Skip to content
This repository has been archived by the owner on Apr 28, 2020. It is now read-only.

Commit

Permalink
Merge pull request #6 from codedge/analysis-qJdVkE
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
codedge authored Apr 3, 2019
2 parents d682696 + f69857d commit 0898eab
Show file tree
Hide file tree
Showing 15 changed files with 193 additions and 171 deletions.
23 changes: 12 additions & 11 deletions phinx.php
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
<?php declare(strict_types=1);
<?php

require_once __DIR__ . '/vendor/autoload.php';
declare(strict_types=1);

require_once __DIR__.'/vendor/autoload.php';

$dotenv = Dotenv\Dotenv::create(__DIR__);
$dotenv->load();

$settings = require __DIR__ . '/src/settings.php';
$settings = require __DIR__.'/src/settings.php';
$app = new \Slim\App($settings);
// Set up dependencies
require __DIR__ . '/src/dependencies.php';
require __DIR__.'/src/dependencies.php';

$db = $container['settings']['database'];

return [
'paths' => [
'migrations' => 'src/Migrations',
'seeds' => 'src/Seeds',
'seeds' => 'src/Seeds',
],
'environments' => [
'default' => [
'adapter' => $db['driver'],
'host' => $db['host'],
'name' => $db['database'],
'user' => $db['username'],
'pass' => $db['password'],
'host' => $db['host'],
'name' => $db['database'],
'user' => $db['username'],
'pass' => $db['password'],
],
'default_migration_table' => 'migrations',
],
'migration_base_class' => "App\Migrations\Migration",
'templates' => [
'templates' => [
'file' => 'src/Migrations/Migration.template.php.dist',
],
];

23 changes: 12 additions & 11 deletions src/Http/Controller/AuthController.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?php declare(strict_types = 1);
<?php

declare(strict_types=1);

namespace App\Http\Controller;

use App\Http\Validators\Validator as ValidatorRule;
use App\Repository\AuthRepository;
use Awurth\SlimValidation\Validator;
use App\Http\Validators\Validator as ValidatorRule;
use Slim\Http\Request;
use Slim\Http\Response;

Expand All @@ -23,7 +25,7 @@ final class AuthController
/**
* HomeController constructor.
*
* @param Validator $validator
* @param Validator $validator
* @param AuthRepository $repository
*/
public function __construct(Validator $validator, AuthRepository $repository)
Expand All @@ -35,7 +37,7 @@ public function __construct(Validator $validator, AuthRepository $repository)
/**
* Get access token.
*
* @param Request $request
* @param Request $request
* @param Response $response
*
* @return Response
Expand All @@ -45,35 +47,34 @@ public function token(Request $request, Response $response)
$validator = $this->validator->validate(
$request,
[
'email' => ValidatorRule::notEmpty(),
'email' => ValidatorRule::notEmpty(),
'password' => ValidatorRule::notEmpty(),
]
);

if($validator->isValid()) {
if ($validator->isValid()) {
$token = $this->repository->login(
$request->getParsedBodyParam('email'),
$request->getParsedBodyParam('password')
);

if(!empty($token)) {
if (!empty($token)) {
return $response->withStatus(200)->withJson([
'status' => 'Success',
'token' => $token,
'token' => $token,
]);
}

return $response->withStatus(401)->withJson([
'status' => 'Authentication error',
'status' => 'Authentication error',
'message' => 'User not found',
]);

}

return $response->withStatus(400)->withJson(
[
'status' => 'Validation Error',
'data' => $validator->getErrors()
'data' => $validator->getErrors(),
]
);
}
Expand Down
5 changes: 3 additions & 2 deletions src/Http/Validators/Validator.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php declare(strict_types = 1);
<?php

declare(strict_types=1);

namespace App\Http\Validators;

use Respect\Validation\Validator as Respect;

class Validator extends Respect
{

}
4 changes: 3 additions & 1 deletion src/Migrations/20190402135252_create_user_table.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

use App\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
Expand Down
6 changes: 5 additions & 1 deletion src/Migrations/Migration.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace App\Migrations;

Expand All @@ -10,13 +12,15 @@ class Migration extends AbstractMigration
{
/** @var Schema */
private $schema;

/**
* Create a schema builder instance.
*/
public function init()
{
$this->schema = (new Capsule())->schema();
}

/**
* Get the schema builder instance.
*
Expand Down
18 changes: 10 additions & 8 deletions src/Models/Translation.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace App\Models;

Expand Down Expand Up @@ -46,7 +48,7 @@ final class Translation implements \JsonSerializable
*
* @return $this
*/
public function setSourceText(string $text): Translation
public function setSourceText(string $text): self
{
$this->sourceText = $text;

Expand All @@ -70,7 +72,7 @@ public function getSourceText(): string
*
* @return Translation
*/
public function setTargetText(string $text): Translation
public function setTargetText(string $text): self
{
$this->targetText = $text;

Expand All @@ -94,7 +96,7 @@ public function getTargetText(): string
*
* @return Translation
*/
public function setSourceLanguage(string $language): Translation
public function setSourceLanguage(string $language): self
{
$this->sourceLanguage = strtolower($language);

Expand All @@ -118,7 +120,7 @@ public function getSourceLanguage(): string
*
* @return Translation
*/
public function setTargetLanguage(string $language): Translation
public function setTargetLanguage(string $language): self
{
$this->targetLanguage = strtolower($language);

Expand All @@ -142,7 +144,7 @@ public function getTargetLanguage(): string
*
* @return Translation
*/
public function setLoadedFromCache(bool $flag): Translation
public function setLoadedFromCache(bool $flag): self
{
$this->loadedFromCache = $flag;

Expand All @@ -168,9 +170,9 @@ public function jsonSerialize(): array
{
return
[
'source_text' => $this->getSourceText(),
'source_text' => $this->getSourceText(),
'source_language' => $this->getSourceLanguage(),
'target_text' => $this->getTargetText(),
'target_text' => $this->getTargetText(),
'target_language' => $this->getTargetLanguage(),
];
}
Expand Down
14 changes: 8 additions & 6 deletions src/Repository/AuthRepository.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace App\Repository;

use Psr\Container\ContainerInterface;
use Firebase\JWT\JWT;
use Illuminate\Database\Query\Builder;
use Psr\Container\ContainerInterface;

final class AuthRepository
{
Expand Down Expand Up @@ -43,12 +45,12 @@ public function login(string $email, string $password): string

$users = $this->userTable->where('email', '=', $email);

if($users->exists()) {
if ($users->exists()) {
$user = $users->get()->first();
if($user && password_verify($password, $user->password)) {

if ($user && password_verify($password, $user->password)) {
$token = JWT::encode([
'id' => $user->id,
'id' => $user->id,
'email' => $user->email,
], $this->settings['secret']);
}
Expand Down
Loading

0 comments on commit 0898eab

Please sign in to comment.