diff --git a/src/web/backend/.gitignore b/src/web/backend/.gitignore index 0f7df0fbef7c3ea7cf8299cd2601b54e9de6eb9e..b4d687d11424be9e9002c6c0bbe39e471a6989b2 100644 --- a/src/web/backend/.gitignore +++ b/src/web/backend/.gitignore @@ -10,3 +10,4 @@ Homestead.json Homestead.yaml npm-debug.log yarn-error.log +.php_cs.cache diff --git a/src/web/backend/app/Console/Commands/GatewayCommands/BaseGatewayFileGenerator.php b/src/web/backend/app/Console/Commands/GatewayCommands/BaseGatewayFileGenerator.php index 8677438f1d1afa1cae577e9b64f5a92d519957a9..3447f1ec3aa75ebd33967121405ed239b48e84ef 100644 --- a/src/web/backend/app/Console/Commands/GatewayCommands/BaseGatewayFileGenerator.php +++ b/src/web/backend/app/Console/Commands/GatewayCommands/BaseGatewayFileGenerator.php @@ -3,17 +3,18 @@ namespace App\Console\Commands\GatewayCommands; - use Illuminate\Console\GeneratorCommand; -abstract class BaseGatewayFileGenerator extends GeneratorCommand { +abstract class BaseGatewayFileGenerator extends GeneratorCommand +{ /** * Get the default namespace for the class. * * @param string $rootNamespace * @return string */ - protected function getDefaultNamespace($rootNamespace) { + protected function getDefaultNamespace($rootNamespace) + { $namespace = $rootNamespace . '\\Gateways'; foreach (explode('/', $this->getNameInput()) as $folder) { $namespace .= '\\' . $folder; @@ -27,7 +28,8 @@ abstract class BaseGatewayFileGenerator extends GeneratorCommand { * @param string $name * @return string */ - protected function getNamespace($name) { + protected function getNamespace($name) + { return $this->getDefaultNamespace($this->rootNamespace()); } @@ -38,7 +40,8 @@ abstract class BaseGatewayFileGenerator extends GeneratorCommand { * @param string $name * @return string */ - protected function replaceClass($stub, $name) { + protected function replaceClass($stub, $name) + { $name = last(explode('\\', $name)); return parent::replaceClass($stub, $name); } @@ -48,7 +51,8 @@ abstract class BaseGatewayFileGenerator extends GeneratorCommand { * * @return string */ - public function rootNamespace() { + public function rootNamespace() + { return 'Source'; } } diff --git a/src/web/backend/app/Console/Commands/GatewayCommands/CreateGateway.php b/src/web/backend/app/Console/Commands/GatewayCommands/CreateGateway.php index ee5cb598ad30f0faccaeac597d8add1b6435720c..06d21c7afd04ae7dcb42c94850125b5c339b3809 100644 --- a/src/web/backend/app/Console/Commands/GatewayCommands/CreateGateway.php +++ b/src/web/backend/app/Console/Commands/GatewayCommands/CreateGateway.php @@ -3,10 +3,10 @@ namespace App\Console\Commands\GatewayCommands; - use Illuminate\Console\Command; -class CreateGateway extends Command { +class CreateGateway extends Command +{ /** * The name and signature of the console command. * @@ -24,7 +24,8 @@ class CreateGateway extends Command { /** * Execute the console command. */ - public function handle(): void { + public function handle(): void + { $name = $this->argument('name'); $this->call( 'gateway:create-interface', diff --git a/src/web/backend/app/Console/Commands/GatewayCommands/GenerateBaseGateway.php b/src/web/backend/app/Console/Commands/GatewayCommands/GenerateBaseGateway.php index 59dbb3e875621dd77b70c14e2e80842352fa6764..fc5baa74050d9d824db2672057c58b216e06de42 100644 --- a/src/web/backend/app/Console/Commands/GatewayCommands/GenerateBaseGateway.php +++ b/src/web/backend/app/Console/Commands/GatewayCommands/GenerateBaseGateway.php @@ -3,8 +3,8 @@ namespace App\Console\Commands\GatewayCommands; - -class GenerateBaseGateway extends BaseGatewayFileGenerator { +class GenerateBaseGateway extends BaseGatewayFileGenerator +{ /** * The name and signature of the console command. * @@ -31,7 +31,8 @@ class GenerateBaseGateway extends BaseGatewayFileGenerator { * * @return string */ - protected function getStub() { + protected function getStub() + { return __DIR__ . '/stubs/Repository.stub'; } @@ -41,7 +42,8 @@ class GenerateBaseGateway extends BaseGatewayFileGenerator { * @param string $name * @return string */ - protected function getPath($name) { + protected function getPath($name) + { $baseName = $this->getNameInput(); $className = last(explode('/', $baseName)); diff --git a/src/web/backend/app/Console/Commands/GatewayCommands/GenerateGatewayRepositoryType.php b/src/web/backend/app/Console/Commands/GatewayCommands/GenerateGatewayRepositoryType.php index fc321679bb5fbcf88bc8a6b00fdd22902226257e..18ccf1c2c9930a9334f726b4b43e8da0b834cea2 100644 --- a/src/web/backend/app/Console/Commands/GatewayCommands/GenerateGatewayRepositoryType.php +++ b/src/web/backend/app/Console/Commands/GatewayCommands/GenerateGatewayRepositoryType.php @@ -3,8 +3,8 @@ namespace App\Console\Commands\GatewayCommands; - -class GenerateGatewayRepositoryType extends BaseGatewayFileGenerator { +class GenerateGatewayRepositoryType extends BaseGatewayFileGenerator +{ /** * The name and signature of the console command. * @@ -31,7 +31,8 @@ class GenerateGatewayRepositoryType extends BaseGatewayFileGenerator { * * @return string */ - protected function getStub() { + protected function getStub() + { $type = $this->argument('type'); return __DIR__ . '/stubs/' . ucfirst($type) . '.stub'; } @@ -42,7 +43,8 @@ class GenerateGatewayRepositoryType extends BaseGatewayFileGenerator { * @param string $name * @return string */ - protected function getPath($name) { + protected function getPath($name) + { $name = $this->getNameInput(); $type = $this->argument('type'); return $this->laravel->basePath() . '/src/Gateways/' . $name . '/' . $type . $name . 'Repository.php'; diff --git a/src/web/backend/app/Console/Commands/GatewayCommands/GenerateGatewayServiceProvider.php b/src/web/backend/app/Console/Commands/GatewayCommands/GenerateGatewayServiceProvider.php index 8fd17ca933095bf2d479753470f7a6ef35a42f87..fcc415b393d218ec0a4780230d1557f2cb5c6c2d 100644 --- a/src/web/backend/app/Console/Commands/GatewayCommands/GenerateGatewayServiceProvider.php +++ b/src/web/backend/app/Console/Commands/GatewayCommands/GenerateGatewayServiceProvider.php @@ -3,8 +3,8 @@ namespace App\Console\Commands\GatewayCommands; - -class GenerateGatewayServiceProvider extends BaseGatewayFileGenerator { +class GenerateGatewayServiceProvider extends BaseGatewayFileGenerator +{ /** * The name and signature of the console command. * @@ -31,7 +31,8 @@ class GenerateGatewayServiceProvider extends BaseGatewayFileGenerator { * * @return string */ - protected function getStub() { + protected function getStub() + { return __DIR__ . '/stubs/Provider.stub'; } @@ -41,7 +42,8 @@ class GenerateGatewayServiceProvider extends BaseGatewayFileGenerator { * @param string $name * @return string */ - protected function getPath($name) { + protected function getPath($name) + { $fullName = $this->getNameInput(); $className = last(explode('/', $fullName)); diff --git a/src/web/backend/app/Console/Commands/UseCaseCommands/BaseUseCaseFileGenerator.php b/src/web/backend/app/Console/Commands/UseCaseCommands/BaseUseCaseFileGenerator.php index 45af8ea3faf24341cff84d6ec804abe383a300b0..16bd7b968e9d279fb16d1199121abf29a1183b3b 100644 --- a/src/web/backend/app/Console/Commands/UseCaseCommands/BaseUseCaseFileGenerator.php +++ b/src/web/backend/app/Console/Commands/UseCaseCommands/BaseUseCaseFileGenerator.php @@ -4,14 +4,16 @@ namespace App\Console\Commands\UseCaseCommands; use Illuminate\Console\GeneratorCommand; -abstract class BaseUseCaseFileGenerator extends GeneratorCommand { +abstract class BaseUseCaseFileGenerator extends GeneratorCommand +{ /** * Get the default namespace for the class. * * @param string $rootNamespace * @return string */ - protected function getDefaultNamespace($rootNamespace) { + protected function getDefaultNamespace($rootNamespace) + { $namespace = $rootNamespace . '\\UseCases'; foreach (explode('/', $this->getNameInput()) as $folder) { $namespace .= '\\' . $folder; @@ -25,7 +27,8 @@ abstract class BaseUseCaseFileGenerator extends GeneratorCommand { * @param string $name * @return string */ - protected function getNamespace($name) { + protected function getNamespace($name) + { return $this->getDefaultNamespace($this->rootNamespace()); } @@ -36,7 +39,8 @@ abstract class BaseUseCaseFileGenerator extends GeneratorCommand { * @param string $name * @return string */ - protected function replaceClass($stub, $name) { + protected function replaceClass($stub, $name) + { $name = last(explode('\\', $name)); return parent::replaceClass($stub, $name); } @@ -46,7 +50,8 @@ abstract class BaseUseCaseFileGenerator extends GeneratorCommand { * * @return string */ - public function rootNamespace() { + public function rootNamespace() + { return 'Source'; } } diff --git a/src/web/backend/app/Console/Commands/UseCaseCommands/CreateUseCase.php b/src/web/backend/app/Console/Commands/UseCaseCommands/CreateUseCase.php index 92090294aced820a978557cc04fce54b0872fb1c..43439d8e6cad40c6da295073f10fd776d380f165 100644 --- a/src/web/backend/app/Console/Commands/UseCaseCommands/CreateUseCase.php +++ b/src/web/backend/app/Console/Commands/UseCaseCommands/CreateUseCase.php @@ -4,7 +4,8 @@ namespace App\Console\Commands\UseCaseCommands; use Illuminate\Console\Command; -class CreateUseCase extends Command { +class CreateUseCase extends Command +{ /** * The name and signature of the console command. * @@ -22,7 +23,8 @@ class CreateUseCase extends Command { /** * Execute the console command. */ - public function handle(): void { + public function handle(): void + { $name = $this->argument('name'); $this->call( 'use-case:create-use-case', diff --git a/src/web/backend/app/Console/Commands/UseCaseCommands/GenerateBaseUseCase.php b/src/web/backend/app/Console/Commands/UseCaseCommands/GenerateBaseUseCase.php index 8ce0ca9250eb22a48e64471de2c2fdd29c90e72a..489aa9c1de27494a38de211a2bf286e3309290ec 100644 --- a/src/web/backend/app/Console/Commands/UseCaseCommands/GenerateBaseUseCase.php +++ b/src/web/backend/app/Console/Commands/UseCaseCommands/GenerateBaseUseCase.php @@ -2,7 +2,8 @@ namespace App\Console\Commands\UseCaseCommands; -class GenerateBaseUseCase extends BaseUseCaseFileGenerator { +class GenerateBaseUseCase extends BaseUseCaseFileGenerator +{ /** * The name and signature of the console command. * @@ -29,7 +30,8 @@ class GenerateBaseUseCase extends BaseUseCaseFileGenerator { * * @return string */ - protected function getStub() { + protected function getStub() + { return __DIR__ . '/stubs/BaseUseCase.stub'; } @@ -39,7 +41,8 @@ class GenerateBaseUseCase extends BaseUseCaseFileGenerator { * @param string $name * @return string */ - protected function getPath($name) { + protected function getPath($name) + { $baseName = $this->getNameInput(); $className = last(explode('/', $baseName)); diff --git a/src/web/backend/app/Console/Commands/UseCaseCommands/GenerateUseCase.php b/src/web/backend/app/Console/Commands/UseCaseCommands/GenerateUseCase.php index dcccfb6062d9f7bb3ecf3028c6a3daf5cd71b93b..c8b1f7c3cbb0db83fc930da35feb6083c1a55392 100644 --- a/src/web/backend/app/Console/Commands/UseCaseCommands/GenerateUseCase.php +++ b/src/web/backend/app/Console/Commands/UseCaseCommands/GenerateUseCase.php @@ -2,7 +2,8 @@ namespace App\Console\Commands\UseCaseCommands; -class GenerateUseCase extends BaseUseCaseFileGenerator { +class GenerateUseCase extends BaseUseCaseFileGenerator +{ /** * The name and signature of the console command. * @@ -29,7 +30,8 @@ class GenerateUseCase extends BaseUseCaseFileGenerator { * * @return string */ - protected function getStub() { + protected function getStub() + { return __DIR__ . '/stubs/UseCase.stub'; } @@ -39,7 +41,8 @@ class GenerateUseCase extends BaseUseCaseFileGenerator { * @param string $name * @return string */ - protected function getPath($name) { + protected function getPath($name) + { $name = $this->getNameInput(); $className = last(explode('/', $name)); diff --git a/src/web/backend/app/Console/Commands/UseCaseCommands/GenerateUseCasePresenter.php b/src/web/backend/app/Console/Commands/UseCaseCommands/GenerateUseCasePresenter.php index 6fce050819610da7eb2f575471777ae78204bf58..9437fe98cd6d1841d560028a6aaf20700bafe5a7 100644 --- a/src/web/backend/app/Console/Commands/UseCaseCommands/GenerateUseCasePresenter.php +++ b/src/web/backend/app/Console/Commands/UseCaseCommands/GenerateUseCasePresenter.php @@ -2,7 +2,8 @@ namespace App\Console\Commands\UseCaseCommands; -class GenerateUseCasePresenter extends BaseUseCaseFileGenerator { +class GenerateUseCasePresenter extends BaseUseCaseFileGenerator +{ /** * The name and signature of the console command. * @@ -29,7 +30,8 @@ class GenerateUseCasePresenter extends BaseUseCaseFileGenerator { * * @return string */ - protected function getStub() { + protected function getStub() + { return __DIR__ . '/stubs/presenter.stub'; } @@ -39,7 +41,8 @@ class GenerateUseCasePresenter extends BaseUseCaseFileGenerator { * @param string $name * @return string */ - protected function getPath($name) { + protected function getPath($name) + { $name = $this->getNameInput(); return $this->laravel->basePath() . '/src/UseCases/' . $name . '/Presenter.php'; } diff --git a/src/web/backend/app/Console/Commands/UseCaseCommands/GenerateUseCasePresenterType.php b/src/web/backend/app/Console/Commands/UseCaseCommands/GenerateUseCasePresenterType.php index d06e2fce4b019e2a66cc8502185eef056f75560c..b2ade41c0419347ea87020796d3309510b78030d 100644 --- a/src/web/backend/app/Console/Commands/UseCaseCommands/GenerateUseCasePresenterType.php +++ b/src/web/backend/app/Console/Commands/UseCaseCommands/GenerateUseCasePresenterType.php @@ -2,7 +2,8 @@ namespace App\Console\Commands\UseCaseCommands; -class GenerateUseCasePresenterType extends BaseUseCaseFileGenerator { +class GenerateUseCasePresenterType extends BaseUseCaseFileGenerator +{ /** * The name and signature of the console command. * @@ -29,7 +30,8 @@ class GenerateUseCasePresenterType extends BaseUseCaseFileGenerator { * * @return string */ - protected function getStub() { + protected function getStub() + { return __DIR__ . '/stubs/PresenterType.stub'; } @@ -39,7 +41,8 @@ class GenerateUseCasePresenterType extends BaseUseCaseFileGenerator { * @param string $name * @return string */ - protected function getPath($name) { + protected function getPath($name) + { $name = $this->getNameInput(); $type = $this->argument('type'); return $this->laravel->basePath() . '/src/UseCases/' . $name . '/' . $type . 'Presenter.php'; @@ -52,7 +55,8 @@ class GenerateUseCasePresenterType extends BaseUseCaseFileGenerator { * @param string $name * @return string */ - protected function replaceClass($stub, $name) { + protected function replaceClass($stub, $name) + { $type = $this->argument('type'); $name = $type . 'Presenter'; return parent::replaceClass($stub, $name); diff --git a/src/web/backend/app/Console/Commands/UseCaseCommands/GenerateUseCaseResponseModel.php b/src/web/backend/app/Console/Commands/UseCaseCommands/GenerateUseCaseResponseModel.php index 1efc8f77c7b67a61233371da739f51b3e00508ac..a10c419e590baaabd34abcb961370921a695b946 100644 --- a/src/web/backend/app/Console/Commands/UseCaseCommands/GenerateUseCaseResponseModel.php +++ b/src/web/backend/app/Console/Commands/UseCaseCommands/GenerateUseCaseResponseModel.php @@ -2,7 +2,8 @@ namespace App\Console\Commands\UseCaseCommands; -class GenerateUseCaseResponseModel extends BaseUseCaseFileGenerator { +class GenerateUseCaseResponseModel extends BaseUseCaseFileGenerator +{ /** * The name and signature of the console command. * @@ -29,7 +30,8 @@ class GenerateUseCaseResponseModel extends BaseUseCaseFileGenerator { * * @return string */ - protected function getStub() { + protected function getStub() + { return __DIR__ . '/stubs/ResponseModel.stub'; } @@ -39,7 +41,8 @@ class GenerateUseCaseResponseModel extends BaseUseCaseFileGenerator { * @param string $name * @return string */ - protected function getPath($name) { + protected function getPath($name) + { $name = $this->getNameInput(); return $this->laravel->basePath() . '/src/UseCases/' . $name . '/ResponseModel.php'; } diff --git a/src/web/backend/app/Console/Commands/UseCaseCommands/GenerateUseCaseServiceProvider.php b/src/web/backend/app/Console/Commands/UseCaseCommands/GenerateUseCaseServiceProvider.php index 087f9b4bcbf980ba446fef181e8b2d98d0ab1cfd..91c43066de2186dbb42a84ab9eda29b4ac7dbe68 100644 --- a/src/web/backend/app/Console/Commands/UseCaseCommands/GenerateUseCaseServiceProvider.php +++ b/src/web/backend/app/Console/Commands/UseCaseCommands/GenerateUseCaseServiceProvider.php @@ -3,8 +3,8 @@ namespace App\Console\Commands\UseCaseCommands; - -class GenerateUseCaseServiceProvider extends BaseUseCaseFileGenerator { +class GenerateUseCaseServiceProvider extends BaseUseCaseFileGenerator +{ /** * The name and signature of the console command. * @@ -31,7 +31,8 @@ class GenerateUseCaseServiceProvider extends BaseUseCaseFileGenerator { * * @return string */ - protected function getStub() { + protected function getStub() + { return __DIR__ . '/stubs/Provider.stub'; } @@ -41,7 +42,8 @@ class GenerateUseCaseServiceProvider extends BaseUseCaseFileGenerator { * @param string $name * @return string */ - protected function getPath($name) { + protected function getPath($name) + { $fullName = $this->getNameInput(); $className = last(explode('/', $fullName)); diff --git a/src/web/backend/app/Door.php b/src/web/backend/app/Door.php index ac5b00a6ea6877a6b9d438c7fa1d25b128d9baa1..ee35fac294b4fb58d9ce1077ef0391125ec0c733 100644 --- a/src/web/backend/app/Door.php +++ b/src/web/backend/app/Door.php @@ -4,7 +4,8 @@ namespace App; use Illuminate\Foundation\Auth\User as Authenticatable; -class Door extends Authenticatable { +class Door extends Authenticatable +{ protected $fillable = [ '*' ]; diff --git a/src/web/backend/app/Exceptions/Handler.php b/src/web/backend/app/Exceptions/Handler.php index 80b50c96509374ad8fc458f5825b15c722141a6c..c615fae1524af9028b9f6577fe06596ae7f4fa9d 100644 --- a/src/web/backend/app/Exceptions/Handler.php +++ b/src/web/backend/app/Exceptions/Handler.php @@ -5,16 +5,17 @@ namespace App\Exceptions; use Exception; use Illuminate\Http\Request; use Illuminate\Http\JsonResponse; -use Source\Exceptions\EntityExistsException; use Illuminate\Auth\AuthenticationException; +use Source\Exceptions\EntityExistsException; use Source\Exceptions\AuthorizationException; -use Source\Exceptions\EntityNotFoundException; use Illuminate\Validation\ValidationException; +use Source\Exceptions\EntityNotFoundException; use Symfony\Component\HttpFoundation\Response; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; use Source\Exceptions\AuthenticationException as SourceAuthenticationException; -class Handler extends ExceptionHandler { +class Handler extends ExceptionHandler +{ /** * A list of the exception types that are not reported. * @@ -32,7 +33,8 @@ class Handler extends ExceptionHandler { * @param int $code * @return JsonResponse */ - public function respondWithError(string $message, int $code): JsonResponse { + public function respondWithError(string $message, int $code): JsonResponse + { return new JsonResponse( [ 'status' => 'error', @@ -51,7 +53,8 @@ class Handler extends ExceptionHandler { * @return Response * @throws Exception */ - public function render($request, Exception $exception) { + public function render($request, Exception $exception) + { if ( $exception instanceof EntityNotFoundException || $exception instanceof EntityExistsException @@ -77,7 +80,8 @@ class Handler extends ExceptionHandler { * @param AuthenticationException $exception * @return Response */ - protected function unauthenticated($request, AuthenticationException $exception) { + protected function unauthenticated($request, AuthenticationException $exception) + { return response()->json(['message' => $exception->getMessage()], 401); } @@ -88,7 +92,8 @@ class Handler extends ExceptionHandler { * @param Request $request * @return Response */ - protected function convertValidationExceptionToResponse(ValidationException $e, $request) { + protected function convertValidationExceptionToResponse(ValidationException $e, $request) + { if ($e->response) { return $e->response; } diff --git a/src/web/backend/app/Group.php b/src/web/backend/app/Group.php index 46cef419097d05dc3d3a09bf1b43348aebf5756e..90b9c5a281541d706dad0348d8b64b9245caec01 100644 --- a/src/web/backend/app/Group.php +++ b/src/web/backend/app/Group.php @@ -3,7 +3,6 @@ namespace App; - -class Group { - +class Group +{ } diff --git a/src/web/backend/app/Guards/ApiGuard.php b/src/web/backend/app/Guards/ApiGuard.php index 7eda47773be21ec3a8e3c4f46c79cfd3388fa249..df7205ce0de0e1a2e5fca4e26b34e997d237fcfc 100644 --- a/src/web/backend/app/Guards/ApiGuard.php +++ b/src/web/backend/app/Guards/ApiGuard.php @@ -3,7 +3,6 @@ namespace App\Guards; - use Illuminate\Http\Request; use Illuminate\Auth\GuardHelpers; use Illuminate\Contracts\Auth\Guard; @@ -11,7 +10,8 @@ use Illuminate\Contracts\Auth\Authenticatable; use Source\UseCases\Token\Authenticate\AuthenticateUseCase; use Source\UseCases\Token\Authenticate\TranslationPresenter; -class ApiGuard implements Guard { +class ApiGuard implements Guard +{ use GuardHelpers; /** @@ -43,7 +43,8 @@ class ApiGuard implements Guard { public function __construct( AuthenticateUseCase $authenticator, Request $request, - $inputKey = 'api_token'){ + $inputKey = 'api_token' + ) { $this->request = $request; $this->inputKey = $inputKey; $this->authenticator = $authenticator; @@ -54,7 +55,8 @@ class ApiGuard implements Guard { * * @return Authenticatable|null */ - public function user() { + public function user() + { // If we've already retrieved the user for the current request we can just // return it back immediately. We do not want to fetch the user data on // every call to this method because that would be tremendously slow. @@ -78,7 +80,8 @@ class ApiGuard implements Guard { * * @return string|null */ - public function getTokenForRequest(): ?string { + public function getTokenForRequest(): ?string + { $token = $this->request->query($this->inputKey); if (empty($token)) { @@ -106,7 +109,8 @@ class ApiGuard implements Guard { * @param array $credentials * @return bool */ - public function validate(array $credentials = []) { + public function validate(array $credentials = []) + { if (empty($credentials[$this->inputKey])) { return false; } @@ -124,7 +128,8 @@ class ApiGuard implements Guard { * @param Request $request * @return $this */ - public function setRequest(Request $request): self { + public function setRequest(Request $request): self + { $this->request = $request; return $this; @@ -135,7 +140,8 @@ class ApiGuard implements Guard { * * @return Authenticatable|null */ - public function retrieveByToken(string $token): ?Authenticatable { + public function retrieveByToken(string $token): ?Authenticatable + { $presenter = new TranslationPresenter(); $this->authenticator->check($presenter, $token); diff --git a/src/web/backend/app/Guards/DoorGuard.php b/src/web/backend/app/Guards/DoorGuard.php index 721bc8c443a7f1ceca0906d17d2a15856c538a3b..f0db52697bba1fd2febb86f3a30c29acf5f4fcef 100644 --- a/src/web/backend/app/Guards/DoorGuard.php +++ b/src/web/backend/app/Guards/DoorGuard.php @@ -3,7 +3,6 @@ namespace App\Guards; - use Illuminate\Http\Request; use Illuminate\Auth\GuardHelpers; use Illuminate\Contracts\Auth\Guard; @@ -11,7 +10,8 @@ use Illuminate\Contracts\Auth\Authenticatable; use Source\UseCases\Doors\Authenticate\AuthenticateUseCase; use Source\UseCases\Doors\Authenticate\TranslationPresenter; -class DoorGuard implements Guard { +class DoorGuard implements Guard +{ use GuardHelpers; /** @@ -43,7 +43,8 @@ class DoorGuard implements Guard { public function __construct( AuthenticateUseCase $authenticator, Request $request, - $inputKey = 'api_token') { + $inputKey = 'api_token' + ) { $this->request = $request; $this->inputKey = $inputKey; $this->authenticator = $authenticator; @@ -54,7 +55,8 @@ class DoorGuard implements Guard { * * @return Authenticatable|null */ - public function user() { + public function user() + { // If we've already retrieved the user for the current request we can just // return it back immediately. We do not want to fetch the user data on // every call to this method because that would be tremendously slow. @@ -78,7 +80,8 @@ class DoorGuard implements Guard { * * @return string|null */ - public function getTokenForRequest(): ?string { + public function getTokenForRequest(): ?string + { $token = $this->request->query($this->inputKey); if (empty($token)) { @@ -102,7 +105,8 @@ class DoorGuard implements Guard { * @param array $credentials * @return bool */ - public function validate(array $credentials = []) { + public function validate(array $credentials = []) + { if (empty($credentials[$this->inputKey])) { return false; } @@ -120,7 +124,8 @@ class DoorGuard implements Guard { * @param Request $request * @return $this */ - public function setRequest(Request $request): self { + public function setRequest(Request $request): self + { $this->request = $request; return $this; @@ -131,7 +136,8 @@ class DoorGuard implements Guard { * * @return Authenticatable|null */ - public function retrieveByToken(string $token): ?Authenticatable { + public function retrieveByToken(string $token): ?Authenticatable + { $presenter = new TranslationPresenter(); $this->authenticator->check($presenter, $token); diff --git a/src/web/backend/app/Http/Controllers/ApiController.php b/src/web/backend/app/Http/Controllers/ApiController.php index f513a151b83eab48c70cfbfa9b9950dbe89eee7a..b3dc439bce9f46e467344d495c67df5f87faa63f 100644 --- a/src/web/backend/app/Http/Controllers/ApiController.php +++ b/src/web/backend/app/Http/Controllers/ApiController.php @@ -3,10 +3,10 @@ namespace App\Http\Controllers; - use Illuminate\Http\JsonResponse; -abstract class ApiController extends Controller { +abstract class ApiController extends Controller +{ /** * @var int */ @@ -15,7 +15,8 @@ abstract class ApiController extends Controller { /** * @param int $code */ - public function setStatusCode(int $code): void { + public function setStatusCode(int $code): void + { $this->status = $code; } @@ -23,7 +24,8 @@ abstract class ApiController extends Controller { * @param array $data * @return JsonResponse */ - public function respondWithData(array $data): JsonResponse { + public function respondWithData(array $data): JsonResponse + { return response()->json( array_merge( $data, @@ -36,7 +38,8 @@ abstract class ApiController extends Controller { ); } - public function respondWithMessage(string $message): JsonResponse { + public function respondWithMessage(string $message): JsonResponse + { return response()->json( [ 'message' => $message, @@ -51,7 +54,8 @@ abstract class ApiController extends Controller { * @param string $message * @return JsonResponse */ - public function respondWithError(string $message): JsonResponse { + public function respondWithError(string $message): JsonResponse + { return response()->json( [ 'status' => 'error', diff --git a/src/web/backend/app/Http/Controllers/AuthController.php b/src/web/backend/app/Http/Controllers/AuthController.php index 5cd23ec2565b110675c2beb286426c6ff40d2eb0..83d8e33142048053f05dc792249a8911c2e600c9 100644 --- a/src/web/backend/app/Http/Controllers/AuthController.php +++ b/src/web/backend/app/Http/Controllers/AuthController.php @@ -13,12 +13,14 @@ use Source\UseCases\Users\Authenticate\APIPresenter; use Source\UseCases\Users\Authenticate\AuthenticateUseCase; use Source\UseCases\Users\Authenticate\UserCreationException; -class AuthController extends ApiController { +class AuthController extends ApiController +{ protected Request $request; protected CookieJar $cookieJar; - public function __construct(Request $request, CookieJar $cookieJar) { + public function __construct(Request $request, CookieJar $cookieJar) + { $this->request = $request; $this->cookieJar = $cookieJar; } @@ -29,7 +31,8 @@ class AuthController extends ApiController { * @throws AuthenticationException * @throws EntityNotFoundException */ - public function login(AuthenticateUseCase $authenticateUseCase): JsonResponse { + public function login(AuthenticateUseCase $authenticateUseCase): JsonResponse + { $presenter = new APIPresenter(); $authenticateUseCase->attempt($presenter, $this->request->all()); @@ -43,7 +46,8 @@ class AuthController extends ApiController { ); } - public function samlLogin(AuthenticateUseCase $authenticateUseCase): RedirectResponse { + public function samlLogin(AuthenticateUseCase $authenticateUseCase): RedirectResponse + { return redirect()->to($authenticateUseCase->handToSaml()); } @@ -52,7 +56,8 @@ class AuthController extends ApiController { * @return mixed * @throws EntityNotFoundException */ - public function handle(AuthenticateUseCase $authenticateUseCase) { + public function handle(AuthenticateUseCase $authenticateUseCase) + { $presenter = new APIPresenter(); try { @@ -74,7 +79,8 @@ class AuthController extends ApiController { * @param AuthenticateUseCase $authenticateUseCase * @return RedirectResponse */ - public function samlLogout(AuthenticateUseCase $authenticateUseCase): RedirectResponse { + public function samlLogout(AuthenticateUseCase $authenticateUseCase): RedirectResponse + { Cookie::queue($this->cookieJar->forget('api_token')); return redirect()->to( diff --git a/src/web/backend/app/Http/Controllers/Controller.php b/src/web/backend/app/Http/Controllers/Controller.php index a0a2a8a34a6221e4dceb24a759ed14e911f74c57..03e02a23e29174f0ade820fdb4cdfcec3abf8769 100644 --- a/src/web/backend/app/Http/Controllers/Controller.php +++ b/src/web/backend/app/Http/Controllers/Controller.php @@ -2,10 +2,10 @@ namespace App\Http\Controllers; -use Illuminate\Foundation\Auth\Access\AuthorizesRequests; use Illuminate\Foundation\Bus\DispatchesJobs; -use Illuminate\Foundation\Validation\ValidatesRequests; use Illuminate\Routing\Controller as BaseController; +use Illuminate\Foundation\Validation\ValidatesRequests; +use Illuminate\Foundation\Auth\Access\AuthorizesRequests; class Controller extends BaseController { diff --git a/src/web/backend/app/Http/Controllers/UsersController.php b/src/web/backend/app/Http/Controllers/UsersController.php index 97b74cd9758a636f8e5e3545d89a8d855d8a59aa..2570257eb48e9b5e8171a91e389f9a8e3896cf97 100644 --- a/src/web/backend/app/Http/Controllers/UsersController.php +++ b/src/web/backend/app/Http/Controllers/UsersController.php @@ -3,25 +3,25 @@ namespace App\Http\Controllers; - use Illuminate\Http\Request; use Illuminate\Http\JsonResponse; use Source\Exceptions\EntityExistsException; -use Source\Exceptions\EntityNotFoundException; use Illuminate\Validation\ValidationException; +use Source\Exceptions\EntityNotFoundException; use Source\UseCases\Users\GetUser\GetUserUseCase; -use Source\UseCases\Users\DeleteUser\DeleteFailedException; use Source\UseCases\Users\CreateUser\CreateUserUseCase; use Source\UseCases\Users\DeleteUser\DeleteUserUseCase; use Source\UseCases\Users\UpdateUser\UpdateUserUseCase; use Source\UseCases\Users\GetAllUsers\GetAllUsersUseCase; +use Source\UseCases\Users\DeleteUser\DeleteFailedException; use Source\UseCases\Users\GetUser\APIPresenter as GetUserAPIPresenter; use Source\UseCases\Users\GetAllUsers\APIPresenter as AllUsersAPIPresenter; -use Source\UseCases\Users\UpdateUser\APIPresenter as UpdateUserAPIPresenter; -use Source\UseCases\Users\DeleteUser\APIPresenter as DeleteUserAPIPresenter; use Source\UseCases\Users\CreateUser\APIPresenter as CreateUserAPIPresenter; +use Source\UseCases\Users\DeleteUser\APIPresenter as DeleteUserAPIPresenter; +use Source\UseCases\Users\UpdateUser\APIPresenter as UpdateUserAPIPresenter; -class UsersController extends ApiController { +class UsersController extends ApiController +{ /** * @var Request */ @@ -30,7 +30,8 @@ class UsersController extends ApiController { /** * @param Request $request */ - public function __construct(Request $request) { + public function __construct(Request $request) + { $this->request = $request; } @@ -38,7 +39,8 @@ class UsersController extends ApiController { * @param GetAllUsersUseCase $getAllUsers * @return JsonResponse */ - public function index(GetAllUsersUseCase $getAllUsers): JsonResponse { + public function index(GetAllUsersUseCase $getAllUsers): JsonResponse + { $presenter = new AllUsersAPIPresenter(); $getAllUsers->all($presenter); @@ -52,7 +54,8 @@ class UsersController extends ApiController { * @return JsonResponse * @throws EntityNotFoundException */ - public function get(GetUserUseCase $getUser, string $userId): JsonResponse { + public function get(GetUserUseCase $getUser, string $userId): JsonResponse + { $presenter = new GetUserAPIPresenter(); $getUser->get($userId, $presenter); @@ -66,7 +69,8 @@ class UsersController extends ApiController { * @throws ValidationException * @throws EntityExistsException */ - public function store(CreateUserUseCase $createUser): JsonResponse { + public function store(CreateUserUseCase $createUser): JsonResponse + { $this->validate( $this->request, [ @@ -95,7 +99,8 @@ class UsersController extends ApiController { * @throws ValidationException * @throws EntityNotFoundException */ - public function update(UpdateUserUseCase $updateUser, string $userId): JsonResponse { + public function update(UpdateUserUseCase $updateUser, string $userId): JsonResponse + { $this->validate( $this->request, [ @@ -122,7 +127,8 @@ class UsersController extends ApiController { * @param string $userId * @return JsonResponse */ - public function delete(DeleteUserUseCase $deleteUser, string $userId): JsonResponse { + public function delete(DeleteUserUseCase $deleteUser, string $userId): JsonResponse + { $presenter = new DeleteUserAPIPresenter(); try { diff --git a/src/web/backend/app/Http/Kernel.php b/src/web/backend/app/Http/Kernel.php index ba8ebfe5a7490b8852beea118755250b7cc0e054..dde5b237aedfda47ee0d62c2e2a80d4327440a00 100644 --- a/src/web/backend/app/Http/Kernel.php +++ b/src/web/backend/app/Http/Kernel.php @@ -8,18 +8,18 @@ use App\Http\Middleware\TrustProxies; use App\Http\Middleware\EncryptCookies; use App\Http\Middleware\VerifyCsrfToken; use Illuminate\Auth\Middleware\Authorize; -use Illuminate\Http\Middleware\SetCacheHeaders; use Illuminate\Auth\Middleware\RequirePassword; +use Illuminate\Http\Middleware\SetCacheHeaders; use Illuminate\Session\Middleware\StartSession; -use App\Http\Middleware\RedirectIfAuthenticated; use App\Http\Middleware\CheckForMaintenanceMode; -use Illuminate\Foundation\Http\Kernel as HttpKernel; +use App\Http\Middleware\RedirectIfAuthenticated; use Illuminate\Routing\Middleware\ThrottleRequests; +use Illuminate\Foundation\Http\Kernel as HttpKernel; use Illuminate\Routing\Middleware\ValidateSignature; -use Illuminate\Routing\Middleware\SubstituteBindings; use Illuminate\Auth\Middleware\EnsureEmailIsVerified; -use Illuminate\View\Middleware\ShareErrorsFromSession; +use Illuminate\Routing\Middleware\SubstituteBindings; use Illuminate\Session\Middleware\AuthenticateSession; +use Illuminate\View\Middleware\ShareErrorsFromSession; use Illuminate\Auth\Middleware\AuthenticateWithBasicAuth; use Illuminate\Foundation\Http\Middleware\ValidatePostSize; use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse; diff --git a/src/web/backend/app/Http/Middleware/Authenticate.php b/src/web/backend/app/Http/Middleware/Authenticate.php index d61cf4b03d2759969172f819f1b04fba1a682ee3..53b7da4d66b4a107608c66586b2441edcd04687f 100644 --- a/src/web/backend/app/Http/Middleware/Authenticate.php +++ b/src/web/backend/app/Http/Middleware/Authenticate.php @@ -4,14 +4,16 @@ namespace App\Http\Middleware; use Illuminate\Auth\Middleware\Authenticate as Middleware; -class Authenticate extends Middleware { +class Authenticate extends Middleware +{ /** * Get the path the user should be redirected to when they are not authenticated. * * @param \Illuminate\Http\Request $request * @return string|null */ - protected function redirectTo($request) { + protected function redirectTo($request) + { // Don't return anything, as this application is basically a pure api, so, we don't have a login view route... return null; } diff --git a/src/web/backend/app/Http/Middleware/RedirectIfAuthenticated.php b/src/web/backend/app/Http/Middleware/RedirectIfAuthenticated.php index 2395ddccf9e278a719bac028ce90d5be0c2ebd8e..d38fc2e94ba95d87de407c96c41a098d7d05c427 100644 --- a/src/web/backend/app/Http/Middleware/RedirectIfAuthenticated.php +++ b/src/web/backend/app/Http/Middleware/RedirectIfAuthenticated.php @@ -2,9 +2,9 @@ namespace App\Http\Middleware; -use App\Providers\RouteServiceProvider; use Closure; use Illuminate\Support\Facades\Auth; +use App\Providers\RouteServiceProvider; class RedirectIfAuthenticated { diff --git a/src/web/backend/app/Http/Middleware/TrustProxies.php b/src/web/backend/app/Http/Middleware/TrustProxies.php index ee5b5958ed929c04c17a0df6ea61a56cbf0da5a5..12fdf8b5e9f419335efd67fd1075701b20843f06 100644 --- a/src/web/backend/app/Http/Middleware/TrustProxies.php +++ b/src/web/backend/app/Http/Middleware/TrustProxies.php @@ -2,8 +2,8 @@ namespace App\Http\Middleware; -use Fideloper\Proxy\TrustProxies as Middleware; use Illuminate\Http\Request; +use Fideloper\Proxy\TrustProxies as Middleware; class TrustProxies extends Middleware { diff --git a/src/web/backend/app/Providers/AppServiceProvider.php b/src/web/backend/app/Providers/AppServiceProvider.php index 5619f1da16a0216fde278aeb6b6eb0858b9b5385..6f4ecf024c7cc027b0287fd2a9331929ed020ff6 100644 --- a/src/web/backend/app/Providers/AppServiceProvider.php +++ b/src/web/backend/app/Providers/AppServiceProvider.php @@ -4,8 +4,8 @@ namespace App\Providers; use Illuminate\Support\ServiceProvider; use Source\Gateways\Saml\SamlRepositoryServiceProvider; -use Source\Gateways\Users\UsersRepositoryServiceProvider; use Source\Gateways\Doors\DoorsRepositoryServiceProvider; +use Source\Gateways\Users\UsersRepositoryServiceProvider; use Source\Gateways\Tokens\TokensRepositoryServiceProvider; use Source\UseCases\Users\GetUser\GetUserUseCaseServiceProvider; use Source\UseCases\Users\CreateUser\CreateUserUseCaseServiceProvider; diff --git a/src/web/backend/app/Providers/AuthServiceProvider.php b/src/web/backend/app/Providers/AuthServiceProvider.php index 5b1badab29ec13a1a676e8945c784ba96fbba0b3..54724d8872260d6e171c5977659c7230b8291343 100644 --- a/src/web/backend/app/Providers/AuthServiceProvider.php +++ b/src/web/backend/app/Providers/AuthServiceProvider.php @@ -8,7 +8,8 @@ use Illuminate\Support\Facades\Auth; use Source\UseCases\Token\Authenticate\AuthenticateUseCase; use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; -class AuthServiceProvider extends ServiceProvider { +class AuthServiceProvider extends ServiceProvider +{ /** * The policy mappings for the application. * @@ -23,7 +24,8 @@ class AuthServiceProvider extends ServiceProvider { * * @return void */ - public function boot() { + public function boot() + { $this->registerPolicies(); // Define guard for the api diff --git a/src/web/backend/app/Providers/BroadcastServiceProvider.php b/src/web/backend/app/Providers/BroadcastServiceProvider.php index 395c518bc47b94752d00b8dc7aeb7d241633e7cf..352cce44a3debcbb07fe36af93ec156cd6ed9a94 100644 --- a/src/web/backend/app/Providers/BroadcastServiceProvider.php +++ b/src/web/backend/app/Providers/BroadcastServiceProvider.php @@ -2,8 +2,8 @@ namespace App\Providers; -use Illuminate\Support\Facades\Broadcast; use Illuminate\Support\ServiceProvider; +use Illuminate\Support\Facades\Broadcast; class BroadcastServiceProvider extends ServiceProvider { diff --git a/src/web/backend/app/Providers/EventServiceProvider.php b/src/web/backend/app/Providers/EventServiceProvider.php index 723a290d57d86b15a0da5924b60220a161b2967f..6c64e52bef79c5622d2a2396f801e3d06acac845 100644 --- a/src/web/backend/app/Providers/EventServiceProvider.php +++ b/src/web/backend/app/Providers/EventServiceProvider.php @@ -2,10 +2,10 @@ namespace App\Providers; +use Illuminate\Support\Facades\Event; use Illuminate\Auth\Events\Registered; use Illuminate\Auth\Listeners\SendEmailVerificationNotification; use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; -use Illuminate\Support\Facades\Event; class EventServiceProvider extends ServiceProvider { diff --git a/src/web/backend/app/Providers/RouteServiceProvider.php b/src/web/backend/app/Providers/RouteServiceProvider.php index 55a8a3b88478d4bc7e68eea6077dbbc393a6b4bb..a66a6772039b65ef9da09faeb13b08161c4a400c 100644 --- a/src/web/backend/app/Providers/RouteServiceProvider.php +++ b/src/web/backend/app/Providers/RouteServiceProvider.php @@ -5,7 +5,8 @@ namespace App\Providers; use Illuminate\Support\Facades\Route; use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; -class RouteServiceProvider extends ServiceProvider { +class RouteServiceProvider extends ServiceProvider +{ /** * This namespace is applied to your controller routes. * @@ -27,7 +28,8 @@ class RouteServiceProvider extends ServiceProvider { * * @return void */ - public function boot() { + public function boot() + { parent::boot(); } @@ -36,7 +38,8 @@ class RouteServiceProvider extends ServiceProvider { * * @return void */ - public function map() { + public function map() + { $this->mapDoorRoutes(); $this->mapApiRoutes(); @@ -51,7 +54,8 @@ class RouteServiceProvider extends ServiceProvider { * * @return void */ - protected function mapWebRoutes(): void { + protected function mapWebRoutes(): void + { Route::middleware('web') ->namespace($this->namespace) ->group(base_path('routes/web.php')); @@ -64,7 +68,8 @@ class RouteServiceProvider extends ServiceProvider { * * @return void */ - protected function mapApiRoutes(): void { + protected function mapApiRoutes(): void + { Route::middleware('api') ->namespace($this->namespace) ->group(base_path('routes/api.php')); @@ -75,7 +80,8 @@ class RouteServiceProvider extends ServiceProvider { * * @return void */ - protected function mapDoorRoutes(): void { + protected function mapDoorRoutes(): void + { Route::middleware('door') ->namespace($this->namespace) ->group(base_path('routes/door.php')); diff --git a/src/web/backend/app/Token.php b/src/web/backend/app/Token.php index c57d9a3794a52caf6a5f0133ffd845d0350e8e08..5377ff841fdfbbf9a603cec935ad2a881941ad2b 100644 --- a/src/web/backend/app/Token.php +++ b/src/web/backend/app/Token.php @@ -18,7 +18,8 @@ class Token extends Model /** * @return BelongsTo */ - public function user(): BelongsTo { + public function user(): BelongsTo + { return $this->belongsTo(User::class); } } diff --git a/src/web/backend/app/User.php b/src/web/backend/app/User.php index d64bbf7b0cdaa0f6ac39b35615c35ba67d7f89bd..e3b05952f2ff3d910ab72051d13708f5dbe6d5ef 100644 --- a/src/web/backend/app/User.php +++ b/src/web/backend/app/User.php @@ -6,7 +6,8 @@ use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Foundation\Auth\User as Authenticatable; -class User extends Authenticatable { +class User extends Authenticatable +{ use SoftDeletes; protected $fillable = [ @@ -25,7 +26,8 @@ class User extends Authenticatable { /** * @return HasMany */ - public function tokens(): HasMany { + public function tokens(): HasMany + { return $this->hasMany(Token::class); } } diff --git a/src/web/backend/config/saml.php b/src/web/backend/config/saml.php index 7ee951dc197e617fe78e03db41d087c6d7db9135..3dcddd17f31e0172f54d9bbc0458385d62edd668 100644 --- a/src/web/backend/config/saml.php +++ b/src/web/backend/config/saml.php @@ -55,4 +55,3 @@ return [ 'auth_source' => env('SAML_SIMPLESAMLPHP_AUTH_SOURCE', 'default-sp'), ] ]; - diff --git a/src/web/backend/database/factories/UserFactory.php b/src/web/backend/database/factories/UserFactory.php index 084535f60e68b859d9fc30bd9804dfa16883fa7e..5e516ceea0d16c7493307caca87b6cbae4acc75a 100644 --- a/src/web/backend/database/factories/UserFactory.php +++ b/src/web/backend/database/factories/UserFactory.php @@ -2,8 +2,8 @@ /** @var \Illuminate\Database\Eloquent\Factory $factory */ use App\User; -use Faker\Generator as Faker; use Illuminate\Support\Str; +use Faker\Generator as Faker; /* |-------------------------------------------------------------------------- diff --git a/src/web/backend/database/migrations/2014_10_12_000000_create_users_table.php b/src/web/backend/database/migrations/2014_10_12_000000_create_users_table.php index 2a2476a890f888078d7f20ec757296063a47e95c..f0b8c8d2a082ea788f2bd46a2f583a292fa503e7 100644 --- a/src/web/backend/database/migrations/2014_10_12_000000_create_users_table.php +++ b/src/web/backend/database/migrations/2014_10_12_000000_create_users_table.php @@ -1,8 +1,8 @@ id = $id; $this->location = $location; $this->name = $name; @@ -44,46 +46,53 @@ class Door { /** * @return int */ - public function getId(): int { + public function getId(): int + { return $this->id; } /** * @return string */ - public function getLocation(): string { + public function getLocation(): string + { return $this->location; } /** * @return string */ - public function getName(): string { + public function getName(): string + { return $this->name; } /** * @return string */ - public function getToken(): string { + public function getToken(): string + { return $this->token; } /** * @return Carbon|null */ - public function getCreatedAt(): ?Carbon { + public function getCreatedAt(): ?Carbon + { return $this->createdAt; } /** * @return Carbon|null */ - public function getUpdatedAt(): ?Carbon { + public function getUpdatedAt(): ?Carbon + { return $this->updatedAt; } - public function hasTokenOf(?string $token): bool { + public function hasTokenOf(?string $token): bool + { if (!$token) { return false; } diff --git a/src/web/backend/src/Entities/SamlUser.php b/src/web/backend/src/Entities/SamlUser.php index f92ba18b99a9c0e2eee9f3e6d94a69abbe90d861..72b14db459d42c831b6a1f872580851ce5f1aed2 100644 --- a/src/web/backend/src/Entities/SamlUser.php +++ b/src/web/backend/src/Entities/SamlUser.php @@ -3,8 +3,8 @@ namespace Source\Entities; - -class SamlUser { +class SamlUser +{ /** @var string */ protected $firstName; @@ -23,10 +23,12 @@ class SamlUser { * @param string $emplid * @param string $email */ - public function __construct(string $firstName, - string $lastName, - string $emplid, - string $email) { + public function __construct( + string $firstName, + string $lastName, + string $emplid, + string $email + ) { $this->firstName = ucfirst($firstName); $this->lastName = ucfirst($lastName); $this->email = strtolower($email); @@ -36,35 +38,40 @@ class SamlUser { /** * @return string */ - public function getFirstName(): string { + public function getFirstName(): string + { return $this->firstName; } /** * @return string */ - public function getLastName(): string { + public function getLastName(): string + { return $this->lastName; } /** * @return string */ - public function getEmplid(): string { + public function getEmplid(): string + { return $this->emplid; } /** * @return string */ - public function getEmail(): string { + public function getEmail(): string + { return $this->email; } /** * @return string */ - public function getDisplayName(): string { + public function getDisplayName(): string + { return $this->getFirstName() . ' ' . $this->getLastName(); } } diff --git a/src/web/backend/src/Entities/Token.php b/src/web/backend/src/Entities/Token.php index 466bd3d9d75ec03327134b4a5fa561b237324a7d..599d67926cdf6909013438cbd2d83a5aea22509c 100644 --- a/src/web/backend/src/Entities/Token.php +++ b/src/web/backend/src/Entities/Token.php @@ -3,7 +3,6 @@ namespace Source\Entities; - use Carbon\Carbon; /** @@ -11,7 +10,8 @@ use Carbon\Carbon; * * @package Source\Entities */ -class Token { +class Token +{ /** * @var int */ @@ -56,13 +56,15 @@ class Token { * @param Carbon|null $createdAt * @param Carbon|null $updatedAt */ - public function __construct(int $id, - int $userId, - string $tokenString, - ?string $name = null, - ?Carbon $expiresAt = null, - ?Carbon $createdAt = null, - ?Carbon $updatedAt = null) { + public function __construct( + int $id, + int $userId, + string $tokenString, + ?string $name = null, + ?Carbon $expiresAt = null, + ?Carbon $createdAt = null, + ?Carbon $updatedAt = null + ) { $this->id = $id; $this->userId = $userId; $this->name = $name; @@ -76,63 +78,72 @@ class Token { * @param string|null $token * @return bool */ - public function matches(?string $token): bool { + public function matches(?string $token): bool + { return $this->tokenString === $token; } /** * @return int */ - public function getId(): int { + public function getId(): int + { return $this->id; } /** * @return int */ - public function getUserId(): int { + public function getUserId(): int + { return $this->userId; } /** * @return string */ - public function getTokenString(): string { + public function getTokenString(): string + { return $this->tokenString; } /** * @return string|null */ - public function getName(): ?string { + public function getName(): ?string + { return $this->name; } /** * @return Carbon|null */ - public function getExpiresAt(): ?Carbon { + public function getExpiresAt(): ?Carbon + { return $this->expiresAt; } /** * @return Carbon|null */ - public function getCreatedAt(): ?Carbon { + public function getCreatedAt(): ?Carbon + { return $this->createdAt; } /** * @return Carbon|null */ - public function getUpdatedAt(): ?Carbon { + public function getUpdatedAt(): ?Carbon + { return $this->updatedAt; } /** * @param int $id */ - public function setId(int $id): void { + public function setId(int $id): void + { $this->id = $id; } @@ -140,7 +151,8 @@ class Token { * @param Carbon $date * @return bool */ - public function isValidAtTime(Carbon $date): bool { + public function isValidAtTime(Carbon $date): bool + { return $this->expiresAt === null || $this->expiresAt->isAfter($date); } } diff --git a/src/web/backend/src/Entities/User.php b/src/web/backend/src/Entities/User.php index 4e92244950c0edad81e55fc74471554d82a12d92..4232e911d8f259bcd31124d4f317d7e7070b745f 100644 --- a/src/web/backend/src/Entities/User.php +++ b/src/web/backend/src/Entities/User.php @@ -3,10 +3,10 @@ namespace Source\Entities; - use Carbon\Carbon; -class User { +class User +{ /** * @var int */ @@ -75,17 +75,19 @@ class User { * @param Carbon|null $createdAt * @param Carbon|null $updatedAt */ - public function __construct(int $id, - string $firstName, - string $lastName, - string $displayName, - ?string $emplid, - string $email, - ?string $password, - ?string $doorcode, - ?Carbon $expiresAt = null, - ?Carbon $createdAt = null, - ?Carbon $updatedAt = null) { + public function __construct( + int $id, + string $firstName, + string $lastName, + string $displayName, + ?string $emplid, + string $email, + ?string $password, + ?string $doorcode, + ?Carbon $expiresAt = null, + ?Carbon $createdAt = null, + ?Carbon $updatedAt = null + ) { $this->id = $id; $this->firstName = $firstName; $this->lastName = $lastName; @@ -102,84 +104,96 @@ class User { /** * @return int */ - public function getId(): int { + public function getId(): int + { return $this->id; } /** * @return string */ - public function getFirstName(): string { + public function getFirstName(): string + { return $this->firstName; } /** * @return string */ - public function getLastName(): string { + public function getLastName(): string + { return $this->lastName; } /** * @return string */ - public function getDisplayName(): string { + public function getDisplayName(): string + { return $this->displayName; } /** * @return string|null */ - public function getEmplid(): ?string { + public function getEmplid(): ?string + { return $this->emplid; } /** * @return string */ - public function getEmail(): string { + public function getEmail(): string + { return $this->email; } /** * @return string|null */ - public function getPassword(): ?string { + public function getPassword(): ?string + { return $this->password; } /** * @return string|null */ - public function getDoorcode(): ?string { + public function getDoorcode(): ?string + { return $this->doorcode; } /** * @return Carbon|null */ - public function getExpiresAt(): ?Carbon { + public function getExpiresAt(): ?Carbon + { return $this->expiresAt; } /** * @return Carbon|null */ - public function getCreatedAt(): ?Carbon { + public function getCreatedAt(): ?Carbon + { return $this->createdAt; } /** * @return Carbon|null */ - public function getUpdatedAt(): ?Carbon { + public function getUpdatedAt(): ?Carbon + { return $this->updatedAt; } /** * @param int $id */ - public function setId(int $id): void { + public function setId(int $id): void + { $this->id = $id; } @@ -187,7 +201,8 @@ class User { * @param string $id * @return bool */ - public function hasUserIdOf(?string $id): bool { + public function hasUserIdOf(?string $id): bool + { if ($id === null) { return false; } @@ -195,7 +210,8 @@ class User { return $this->getId() === (int)$id; } - public function matchCredentials(?string $email, ?string $password): bool { + public function matchCredentials(?string $email, ?string $password): bool + { if (!$password || !$email) { return false; } @@ -207,7 +223,8 @@ class User { * @param string $doorcode * @return bool */ - public function hasDoorcodeOf(?string $doorcode): bool { + public function hasDoorcodeOf(?string $doorcode): bool + { if (!$doorcode) { return false; } @@ -215,7 +232,8 @@ class User { return $this->getDoorcode() === $doorcode; } - public function hasEmailOf(?string $email): bool { + public function hasEmailOf(?string $email): bool + { return $this->getEmail() === strtolower($email); } } diff --git a/src/web/backend/src/Exceptions/AuthenticationException.php b/src/web/backend/src/Exceptions/AuthenticationException.php index ebead0445981ce8576be1e0fc5efb07fadf95088..90fee9c01e0972d24d6df4f208004abbbb8b69fe 100644 --- a/src/web/backend/src/Exceptions/AuthenticationException.php +++ b/src/web/backend/src/Exceptions/AuthenticationException.php @@ -3,12 +3,13 @@ namespace Source\Exceptions; - use Exception; use Throwable; -class AuthenticationException extends Exception { - public function __construct($message = 'Unauthenticated', $code = 401, Throwable $previous = null) { +class AuthenticationException extends Exception +{ + public function __construct($message = 'Unauthenticated', $code = 401, Throwable $previous = null) + { parent::__construct($message, $code, $previous); } } diff --git a/src/web/backend/src/Exceptions/AuthorizationException.php b/src/web/backend/src/Exceptions/AuthorizationException.php index 4d2e8f0c1b8842fdab81eca433201a2ee89c84d3..145a7cfd2e8a7ec53eb3f074d7cfeb8a4f978de7 100644 --- a/src/web/backend/src/Exceptions/AuthorizationException.php +++ b/src/web/backend/src/Exceptions/AuthorizationException.php @@ -3,12 +3,13 @@ namespace Source\Exceptions; - use Exception; use Throwable; -class AuthorizationException extends Exception { - public function __construct($message = 'Unauthorized', $code = 403, Throwable $previous = null) { +class AuthorizationException extends Exception +{ + public function __construct($message = 'Unauthorized', $code = 403, Throwable $previous = null) + { parent::__construct($message, $code, $previous); } } diff --git a/src/web/backend/src/Exceptions/EntityExistsException.php b/src/web/backend/src/Exceptions/EntityExistsException.php index 3cf0fbd34e2beb66607d828725dd159104440039..fe9574f196d95a51f34a682ce280d01a0351cab3 100644 --- a/src/web/backend/src/Exceptions/EntityExistsException.php +++ b/src/web/backend/src/Exceptions/EntityExistsException.php @@ -3,13 +3,13 @@ namespace Source\Exceptions; - use Exception; use Throwable; -class EntityExistsException extends Exception { - public function __construct($message = 'Entity already exists.', $code = 400, Throwable $previous = null) { +class EntityExistsException extends Exception +{ + public function __construct($message = 'Entity already exists.', $code = 400, Throwable $previous = null) + { parent::__construct($message, $code, $previous); } - } diff --git a/src/web/backend/src/Exceptions/EntityNotFoundException.php b/src/web/backend/src/Exceptions/EntityNotFoundException.php index bd5e483ca80c4361c4d0b31d912129b8134d38f6..a66b4492cbbfbd839a20d1a61233575df1232649 100644 --- a/src/web/backend/src/Exceptions/EntityNotFoundException.php +++ b/src/web/backend/src/Exceptions/EntityNotFoundException.php @@ -3,12 +3,13 @@ namespace Source\Exceptions; - use Exception; use Throwable; -class EntityNotFoundException extends Exception { - public function __construct($message = 'Entity not found', $code = 404, Throwable $previous = null) { +class EntityNotFoundException extends Exception +{ + public function __construct($message = 'Entity not found', $code = 404, Throwable $previous = null) + { parent::__construct($message, $code, $previous); } } diff --git a/src/web/backend/src/Gateways/Doors/DatabaseDoorsRepository.php b/src/web/backend/src/Gateways/Doors/DatabaseDoorsRepository.php index 115055cad12b11a61c8861a3bd172313c6735a76..8c8ae17102c656ca41cb7e471e3dbee349015dde 100644 --- a/src/web/backend/src/Gateways/Doors/DatabaseDoorsRepository.php +++ b/src/web/backend/src/Gateways/Doors/DatabaseDoorsRepository.php @@ -3,14 +3,15 @@ namespace Source\Gateways\Doors; - use Source\Entities\Door; -class DatabaseDoorsRepository implements DoorsRepository { +class DatabaseDoorsRepository implements DoorsRepository +{ /** * @inheritDoc */ - public function create(Door $door): Door { + public function create(Door $door): Door + { $dbDoor = \App\Door::create( [ 'location' => $door->getLocation(), @@ -32,7 +33,8 @@ class DatabaseDoorsRepository implements DoorsRepository { /** * @inheritDoc */ - public function getByToken(string $token): ?Door { + public function getByToken(string $token): ?Door + { $dbDoor = \App\Door::where('api_token', hash('sha256', $token))->first(); if (!$dbDoor) { diff --git a/src/web/backend/src/Gateways/Doors/DoorsRepository.php b/src/web/backend/src/Gateways/Doors/DoorsRepository.php index 410e1d676c5dfd5a9b8261275b48e36fe4a0aa65..c5353a010e852af9ac37a89a471da9ac4b494d97 100644 --- a/src/web/backend/src/Gateways/Doors/DoorsRepository.php +++ b/src/web/backend/src/Gateways/Doors/DoorsRepository.php @@ -3,10 +3,10 @@ namespace Source\Gateways\Doors; - use Source\Entities\Door; -interface DoorsRepository { +interface DoorsRepository +{ /** * Create a new door * diff --git a/src/web/backend/src/Gateways/Doors/DoorsRepositoryServiceProvider.php b/src/web/backend/src/Gateways/Doors/DoorsRepositoryServiceProvider.php index d58b9573b1da211ab18ccd7fafba1c2b98c6aa1a..8c5d6e433de0135e307884bfcc237874e84943b5 100644 --- a/src/web/backend/src/Gateways/Doors/DoorsRepositoryServiceProvider.php +++ b/src/web/backend/src/Gateways/Doors/DoorsRepositoryServiceProvider.php @@ -3,27 +3,28 @@ namespace Source\Gateways\Doors; - +use Illuminate\Support\ServiceProvider; use Illuminate\Contracts\Foundation\Application; use Illuminate\Contracts\Support\DeferrableProvider; -use Illuminate\Support\ServiceProvider; /** * Service provider must be registered in AppServiceProvider */ -class DoorsRepositoryServiceProvider extends ServiceProvider implements DeferrableProvider { +class DoorsRepositoryServiceProvider extends ServiceProvider implements DeferrableProvider +{ /** * Register any application services. * * @return void */ - public function register() { + public function register() + { $this->app->singleton(DoorsRepository::class, static function (Application $app) { if (env('APP_ENV') === 'memory') { return new LocalDoorsRepository(); } - if(env('APP_ENV') === 'testing') { + if (env('APP_ENV') === 'testing') { return new InMemoryDoorsRepository(); } @@ -36,13 +37,15 @@ class DoorsRepositoryServiceProvider extends ServiceProvider implements Deferrab * * @return void */ - public function boot(): void { + public function boot(): void + { } /** * @return array */ - public function provides() { + public function provides() + { return [DoorsRepository::class]; } } diff --git a/src/web/backend/src/Gateways/Doors/InMemoryDoorsRepository.php b/src/web/backend/src/Gateways/Doors/InMemoryDoorsRepository.php index 13e1e092b8787c70fc48188ac173cada6f1a1da7..42634a6d10ab9bc779ff82e6136b612c5f27e2dd 100644 --- a/src/web/backend/src/Gateways/Doors/InMemoryDoorsRepository.php +++ b/src/web/backend/src/Gateways/Doors/InMemoryDoorsRepository.php @@ -3,17 +3,18 @@ namespace Source\Gateways\Doors; - use Source\Entities\Door; -class InMemoryDoorsRepository implements DoorsRepository { +class InMemoryDoorsRepository implements DoorsRepository +{ /** @var Door[] */ protected array $doors = []; /** * @inheritDoc */ - public function create(Door $door): Door { + public function create(Door $door): Door + { $this->doors[] = $door; return $door; } @@ -21,7 +22,8 @@ class InMemoryDoorsRepository implements DoorsRepository { /** * @inheritDoc */ - public function getByToken(string $token): ?Door { + public function getByToken(string $token): ?Door + { foreach ($this->doors as $door) { if ($door->hasTokenOf($token)) { return $door; diff --git a/src/web/backend/src/Gateways/Doors/LocalDoorsRepository.php b/src/web/backend/src/Gateways/Doors/LocalDoorsRepository.php index ac352a3244c4c47f28eedebbbb1bee21942fe2d0..8224442cae526c505b1069007a4d2af112b66336 100644 --- a/src/web/backend/src/Gateways/Doors/LocalDoorsRepository.php +++ b/src/web/backend/src/Gateways/Doors/LocalDoorsRepository.php @@ -3,11 +3,12 @@ namespace Source\Gateways\Doors; - use Source\Entities\Door; -class LocalDoorsRepository extends InMemoryDoorsRepository { - public function __construct() { +class LocalDoorsRepository extends InMemoryDoorsRepository +{ + public function __construct() + { $this->doors[] = new Door(1, 'The Amazon', 'chicken izta door', 'door_1_api_token'); $this->doors[] = new Door(2, 'Bat Cave', 'Bruce\' lair', 'door_2_api_token'); } diff --git a/src/web/backend/src/Gateways/Saml/InMemorySamlRepository.php b/src/web/backend/src/Gateways/Saml/InMemorySamlRepository.php index 27aae7640cb438ae3ddf84c1fe0dc3d6b14c563e..2acc325fc8983a0feeaa90510cf919f1b5da7a57 100644 --- a/src/web/backend/src/Gateways/Saml/InMemorySamlRepository.php +++ b/src/web/backend/src/Gateways/Saml/InMemorySamlRepository.php @@ -3,11 +3,10 @@ namespace Source\Gateways\Saml; - use Source\Entities\SamlUser; -class InMemorySamlRepository implements SamlRepository { - +class InMemorySamlRepository implements SamlRepository +{ protected ?SamlUser $userToLogInAs; protected ?SamlUser $loggedInUser; @@ -24,14 +23,16 @@ class InMemorySamlRepository implements SamlRepository { $this->logoutUrl = $logoutUrl; } - public function setLoginUser(SamlUser $user): void { + public function setLoginUser(SamlUser $user): void + { $this->userToLogInAs = $user; } /** * @inheritDoc */ - public function login(array $options = []): string { + public function login(array $options = []): string + { $this->loggedInUser = $this->userToLogInAs; return $this->loginUrl; } @@ -39,14 +40,16 @@ class InMemorySamlRepository implements SamlRepository { /** * @inheritDoc */ - public function handleLogin(): ?SamlUser { + public function handleLogin(): ?SamlUser + { return $this->loggedInUser; } /** * @inheritDoc */ - public function logout(): string { + public function logout(): string + { $this->loggedInUser = null; return $this->logoutUrl; } @@ -54,7 +57,8 @@ class InMemorySamlRepository implements SamlRepository { /** * @inheritDoc */ - public function isAuthenticated(): bool { + public function isAuthenticated(): bool + { return $this->loggedInUser !== null; } } diff --git a/src/web/backend/src/Gateways/Saml/SamlRepository.php b/src/web/backend/src/Gateways/Saml/SamlRepository.php index 6fd182466781245a712427c830cd58c0aac7b4c0..d6a32084948fdcf60fed8843519c2de7820b619b 100644 --- a/src/web/backend/src/Gateways/Saml/SamlRepository.php +++ b/src/web/backend/src/Gateways/Saml/SamlRepository.php @@ -3,10 +3,10 @@ namespace Source\Gateways\Saml; - use Source\Entities\SamlUser; -interface SamlRepository { +interface SamlRepository +{ /** * This function returns the url to redirect to to log a user in. * diff --git a/src/web/backend/src/Gateways/Saml/SamlRepositoryServiceProvider.php b/src/web/backend/src/Gateways/Saml/SamlRepositoryServiceProvider.php index 9324e26d17118ec71710a84670a62d2c9c36b6b0..ea03fa8b42883f3c10d3136128b0feaeb4c0ee8f 100644 --- a/src/web/backend/src/Gateways/Saml/SamlRepositoryServiceProvider.php +++ b/src/web/backend/src/Gateways/Saml/SamlRepositoryServiceProvider.php @@ -3,23 +3,24 @@ namespace Source\Gateways\Saml; - +use Illuminate\Support\ServiceProvider; use Illuminate\Contracts\Foundation\Application; use Illuminate\Contracts\Support\DeferrableProvider; -use Illuminate\Support\ServiceProvider; /** * Service provider must be registered in AppServiceProvider */ -class SamlRepositoryServiceProvider extends ServiceProvider implements DeferrableProvider { +class SamlRepositoryServiceProvider extends ServiceProvider implements DeferrableProvider +{ /** * Register any application services. * * @return void */ - public function register() { + public function register() + { $this->app->singleton(SamlRepository::class, static function (Application $app) { - if(env('APP_ENV') === 'testing') { + if (env('APP_ENV') === 'testing') { return new InMemorySamlRepository( config('saml.login_route'), config('saml.logout_route') @@ -40,13 +41,15 @@ class SamlRepositoryServiceProvider extends ServiceProvider implements Deferrabl * * @return void */ - public function boot(): void { + public function boot(): void + { } /** * @return array */ - public function provides() { + public function provides() + { return [SamlRepository::class]; } } diff --git a/src/web/backend/src/Gateways/Saml/SimpleSamlPhpSamlRepository.php b/src/web/backend/src/Gateways/Saml/SimpleSamlPhpSamlRepository.php index 3b6992a8e03f7013ba5067b688ddeba6c8704ec8..ed115a4cabf00e0adb7bc6166d36bb0c44267a4f 100644 --- a/src/web/backend/src/Gateways/Saml/SimpleSamlPhpSamlRepository.php +++ b/src/web/backend/src/Gateways/Saml/SimpleSamlPhpSamlRepository.php @@ -2,14 +2,14 @@ namespace Source\Gateways\Saml; - use Exception; use SimpleSAML_Auth_Simple; use Source\Entities\SamlUser; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Validator; -class SimpleSamlPhpSamlRepository implements SamlRepository { +class SimpleSamlPhpSamlRepository implements SamlRepository +{ /** @var string */ protected string $loginUrl; @@ -43,8 +43,8 @@ class SimpleSamlPhpSamlRepository implements SamlRepository { string $loginUrl, string $logoutUrl, string $samlAutoloadPath, - string $authSource) { - + string $authSource + ) { $this->loginUrl = $loginUrl; $this->logoutUrl = $logoutUrl; @@ -56,7 +56,8 @@ class SimpleSamlPhpSamlRepository implements SamlRepository { /** * @inheritDoc */ - public function login(array $options = []): string { + public function login(array $options = []): string + { return $this->saml->getloginURL($this->loginUrl); } @@ -64,29 +65,34 @@ class SimpleSamlPhpSamlRepository implements SamlRepository { * @inheritDoc * @throws Exception */ - public function handleLogin(): ?SamlUser { + public function handleLogin(): ?SamlUser + { return $this->makeUser(); } /** * @inheritDoc */ - public function logout(): string { + public function logout(): string + { return $this->saml->getLogoutURL($this->logoutUrl); } - public function isAuthenticated(): bool { + public function isAuthenticated(): bool + { return $this->saml->isAuthenticated(); } - public function isGuest(): bool { + public function isGuest(): bool + { return !$this->isAuthenticated(); } /** * Verify required user attributes. */ - protected function makeUser(): ?SamlUser { + protected function makeUser(): ?SamlUser + { if ($this->isGuest()) { return null; } diff --git a/src/web/backend/src/Gateways/Tokens/DatabaseTokensRepository.php b/src/web/backend/src/Gateways/Tokens/DatabaseTokensRepository.php index a0b787f141296a9456dd4cd8adea1490a0b5bae9..23521432ecdd2582bdbb4e4b1bcce75b423e5fe8 100644 --- a/src/web/backend/src/Gateways/Tokens/DatabaseTokensRepository.php +++ b/src/web/backend/src/Gateways/Tokens/DatabaseTokensRepository.php @@ -3,15 +3,16 @@ namespace Source\Gateways\Tokens; - use App\User; use Carbon\Carbon; use Source\Entities\Token; use Illuminate\Database\Eloquent\Builder; use Source\Exceptions\EntityNotFoundException; -class DatabaseTokensRepository implements TokensRepository { - protected function dbTokenToToken(\App\Token $token): Token { +class DatabaseTokensRepository implements TokensRepository +{ + protected function dbTokenToToken(\App\Token $token): Token + { return new Token( $token->id, $token->user_id, @@ -26,7 +27,8 @@ class DatabaseTokensRepository implements TokensRepository { /** * @inheritDoc */ - public function create(Token $token): Token { + public function create(Token $token): Token + { $user = User::find($token->getUserId()); if (!$user) { @@ -46,7 +48,8 @@ class DatabaseTokensRepository implements TokensRepository { /** * @inheritDoc */ - public function findValidToken(string $token): ?Token { + public function findValidToken(string $token): ?Token + { $found = \App\Token::where('api_token', $token)->where('expires_at', '>', Carbon::now())->orWhere( static function (Builder $query) use ($token) { $query->where('api_token', $token)->where('expires_at', null); @@ -64,7 +67,8 @@ class DatabaseTokensRepository implements TokensRepository { /** * @inheritDoc */ - public function invalidateToken(string $token): void { + public function invalidateToken(string $token): void + { $found = \App\Token::where('api_token', $token) ->where('expires_at', '<', Carbon::now()) ->where('expires_at', '!=', null) diff --git a/src/web/backend/src/Gateways/Tokens/InMemoryTokensRepository.php b/src/web/backend/src/Gateways/Tokens/InMemoryTokensRepository.php index 43d4249e0fc2da36ab4a260524655e647a6d22a8..c414544e7ca5131128129172a2f524a9bd62f72e 100644 --- a/src/web/backend/src/Gateways/Tokens/InMemoryTokensRepository.php +++ b/src/web/backend/src/Gateways/Tokens/InMemoryTokensRepository.php @@ -3,11 +3,11 @@ namespace Source\Gateways\Tokens; - use Carbon\Carbon; use Source\Entities\Token; -class InMemoryTokensRepository implements TokensRepository { +class InMemoryTokensRepository implements TokensRepository +{ /** * @var Token[] */ @@ -16,7 +16,8 @@ class InMemoryTokensRepository implements TokensRepository { protected static int $id = 1; /** @inheritDoc */ - public function create(Token $token): Token { + public function create(Token $token): Token + { $token->setId(static::$id++); $this->tokens[] = $token; return $token; @@ -24,11 +25,12 @@ class InMemoryTokensRepository implements TokensRepository { /** @inheritDoc */ - public function findValidToken(string $tokenToMatch): ?Token { + public function findValidToken(string $tokenToMatch): ?Token + { foreach ($this->tokens as $token) { - if ($token->matches($tokenToMatch) && $token->isValidAtTime(Carbon::now())) { - return $token; - } + if ($token->matches($tokenToMatch) && $token->isValidAtTime(Carbon::now())) { + return $token; + } } return null; @@ -37,7 +39,8 @@ class InMemoryTokensRepository implements TokensRepository { /** * @inheritDoc */ - public function invalidateToken(string $token): void { + public function invalidateToken(string $token): void + { $this->tokens = array_filter($this->tokens, static function (Token $t) use ($token) { return !$t->matches($token); }); diff --git a/src/web/backend/src/Gateways/Tokens/LocalTokensRepository.php b/src/web/backend/src/Gateways/Tokens/LocalTokensRepository.php index 62f7658ed13b739d686e4212dc9429bda50eefb9..8cde4405adbf349408e3cae0ff637a66f50888c0 100644 --- a/src/web/backend/src/Gateways/Tokens/LocalTokensRepository.php +++ b/src/web/backend/src/Gateways/Tokens/LocalTokensRepository.php @@ -3,12 +3,13 @@ namespace Source\Gateways\Tokens; - use Carbon\Carbon; use Source\Entities\Token; -class LocalTokensRepository extends InMemoryTokensRepository { - public function __construct() { +class LocalTokensRepository extends InMemoryTokensRepository +{ + public function __construct() + { $this->tokens[] = new Token(1, 1, 'token_string', 'basic token'); $this->tokens[] = new Token(2, 420, 'expired_token', '', Carbon::now()->subDays(3)); } diff --git a/src/web/backend/src/Gateways/Tokens/TokensRepository.php b/src/web/backend/src/Gateways/Tokens/TokensRepository.php index 39766543067a60532ca1cfe026bdb35783eed523..21d6a1575d6732dfaf513b57aa938a8f94d165e8 100644 --- a/src/web/backend/src/Gateways/Tokens/TokensRepository.php +++ b/src/web/backend/src/Gateways/Tokens/TokensRepository.php @@ -3,11 +3,11 @@ namespace Source\Gateways\Tokens; - use Source\Entities\Token; use Source\Exceptions\EntityNotFoundException; -interface TokensRepository { +interface TokensRepository +{ /** * @param Token $token * @return Token diff --git a/src/web/backend/src/Gateways/Tokens/TokensRepositoryServiceProvider.php b/src/web/backend/src/Gateways/Tokens/TokensRepositoryServiceProvider.php index 190832fa7f748886e73134107f0958bb706829bf..86183c655de60352e6e0a17b45cbc43ab465dfc0 100644 --- a/src/web/backend/src/Gateways/Tokens/TokensRepositoryServiceProvider.php +++ b/src/web/backend/src/Gateways/Tokens/TokensRepositoryServiceProvider.php @@ -3,28 +3,28 @@ namespace Source\Gateways\Tokens; - -use Source\Gateways\Users\UsersRepository; +use Illuminate\Support\ServiceProvider; use Illuminate\Contracts\Foundation\Application; use Illuminate\Contracts\Support\DeferrableProvider; -use Illuminate\Support\ServiceProvider; /** * Service provider must be registered in AppServiceProvider */ -class TokensRepositoryServiceProvider extends ServiceProvider implements DeferrableProvider { +class TokensRepositoryServiceProvider extends ServiceProvider implements DeferrableProvider +{ /** * Register any application services. * * @return void */ - public function register() { + public function register() + { $this->app->singleton(TokensRepository::class, static function (Application $app) { if (env('APP_ENV') === 'memory') { return new LocalTokensRepository(); } - if(env('APP_ENV') === 'testing') { + if (env('APP_ENV') === 'testing') { return new InMemoryTokensRepository(); } @@ -37,13 +37,15 @@ class TokensRepositoryServiceProvider extends ServiceProvider implements Deferra * * @return void */ - public function boot(): void { + public function boot(): void + { } /** * @return array */ - public function provides() { + public function provides() + { return [TokensRepository::class]; } } diff --git a/src/web/backend/src/Gateways/Users/DatabaseUsersRepository.php b/src/web/backend/src/Gateways/Users/DatabaseUsersRepository.php index daff9cb5f106fba21d73a743fecb7a828a9313f0..f407cd90503b5e3b83b588b8376774b1dbd015b3 100644 --- a/src/web/backend/src/Gateways/Users/DatabaseUsersRepository.php +++ b/src/web/backend/src/Gateways/Users/DatabaseUsersRepository.php @@ -3,12 +3,12 @@ namespace Source\Gateways\Users; - use Source\Entities\User; -class DatabaseUsersRepository implements UsersRepository { - - protected function fillBasicUserAttrs(User $user, \App\User $dbUser): \App\User { +class DatabaseUsersRepository implements UsersRepository +{ + protected function fillBasicUserAttrs(User $user, \App\User $dbUser): \App\User + { $dbUser->first_name = $user->getFirstName(); $dbUser->last_name = $user->getLastName(); $dbUser->display_name = $user->getDisplayName(); @@ -23,7 +23,8 @@ class DatabaseUsersRepository implements UsersRepository { /** * @inheritDoc */ - public function get(string $userId): ?User { + public function get(string $userId): ?User + { $user = \App\User::find($userId); if (!$user) { @@ -48,7 +49,8 @@ class DatabaseUsersRepository implements UsersRepository { /** * @inheritDoc */ - public function all(): array { + public function all(): array + { $users = \App\User::all()->values()->all(); return array_map( @@ -74,7 +76,8 @@ class DatabaseUsersRepository implements UsersRepository { /** * @inheritDoc */ - public function create(User $user): ?User { + public function create(User $user): ?User + { $newUser = $this->fillBasicUserAttrs($user, new \App\User()); $newUser->save(); @@ -97,7 +100,8 @@ class DatabaseUsersRepository implements UsersRepository { /** * @inheritDoc */ - public function update(string $userId, User $user): ?User { + public function update(string $userId, User $user): ?User + { $dbUser = \App\User::find($userId); if (!$dbUser) { @@ -126,7 +130,8 @@ class DatabaseUsersRepository implements UsersRepository { /** * @inheritDoc */ - public function delete(string $userId): bool { + public function delete(string $userId): bool + { $user = \App\User::find($userId); return $user->delete(); } @@ -134,14 +139,16 @@ class DatabaseUsersRepository implements UsersRepository { /** * @inheritDoc */ - public function exists(string $userId): bool { + public function exists(string $userId): bool + { return \App\User::find($userId) !== null; } /** * @inheritDoc */ - public function findByCredentials(string $email, string $password): ?User { + public function findByCredentials(string $email, string $password): ?User + { $user = \App\User::where('email', $email)->first(); if (!$user) { @@ -170,7 +177,8 @@ class DatabaseUsersRepository implements UsersRepository { /** * @inheritDoc */ - public function findByDoorcode(string $doorcode): ?User { + public function findByDoorcode(string $doorcode): ?User + { $doorcode = hash('sha256', $doorcode); $user = \App\User::where('doorcode', $doorcode)->first(); @@ -198,7 +206,8 @@ class DatabaseUsersRepository implements UsersRepository { /** * @inheritDoc */ - public function findByEmail(string $email): ?User { + public function findByEmail(string $email): ?User + { $user = \App\User::where('email', strtolower($email))->first(); return new User( diff --git a/src/web/backend/src/Gateways/Users/InMemoryUsersRepository.php b/src/web/backend/src/Gateways/Users/InMemoryUsersRepository.php index 306837f6380607071a89d2aa049bf2d1b5fe9a09..842aad627642485eedf9b7f17c1cca7fb818b047 100644 --- a/src/web/backend/src/Gateways/Users/InMemoryUsersRepository.php +++ b/src/web/backend/src/Gateways/Users/InMemoryUsersRepository.php @@ -3,10 +3,10 @@ namespace Source\Gateways\Users; - use Source\Entities\User; -class InMemoryUsersRepository implements UsersRepository { +class InMemoryUsersRepository implements UsersRepository +{ /** * @var User[] */ @@ -20,7 +20,8 @@ class InMemoryUsersRepository implements UsersRepository { /** * @inheritDoc */ - public function get(string $userId): ?User { + public function get(string $userId): ?User + { foreach ($this->users as $user) { if ($user->hasUserIdOf($userId)) { return $user; @@ -33,14 +34,16 @@ class InMemoryUsersRepository implements UsersRepository { /** * @inheritDoc */ - public function all(): array { + public function all(): array + { return $this->users; } /** * @inheritDoc */ - public function create(User $user): ?User { + public function create(User $user): ?User + { if ($user->hasUserIdOf(0)) { $user->setId(static::$idCounter++); } @@ -57,7 +60,8 @@ class InMemoryUsersRepository implements UsersRepository { /** * @inheritDoc */ - public function update(string $userId, User $user): ?User { + public function update(string $userId, User $user): ?User + { foreach ($this->users as &$userBase) { if ($userBase->hasUserIdOf($userId)) { $user->setId($userBase->getId()); @@ -71,7 +75,8 @@ class InMemoryUsersRepository implements UsersRepository { /** * @inheritDoc */ - public function delete(string $userId): bool { + public function delete(string $userId): bool + { $this->users = array_filter($this->users, static function (User $user) use ($userId) { return !$user->hasUserIdOf($userId); }); @@ -82,14 +87,16 @@ class InMemoryUsersRepository implements UsersRepository { /** * @inheritDoc */ - public function exists(string $userId): bool { + public function exists(string $userId): bool + { return $this->get($userId) !== null; } /** * @inheritDoc */ - public function findByCredentials(string $email, string $password): ?User { + public function findByCredentials(string $email, string $password): ?User + { foreach ($this->users as $user) { if ($user->matchCredentials($email, $password)) { return $user; @@ -102,7 +109,8 @@ class InMemoryUsersRepository implements UsersRepository { /** * @inheritDoc */ - public function findByDoorcode(string $doorcode): ?User { + public function findByDoorcode(string $doorcode): ?User + { foreach ($this->users as $user) { if ($user->hasDoorcodeOf($doorcode)) { return $user; @@ -115,14 +123,16 @@ class InMemoryUsersRepository implements UsersRepository { /** * Clears the repository */ - public function clear(): void { + public function clear(): void + { $this->users = []; } /** * @inheritDoc */ - public function findByEmail(string $email): ?User { + public function findByEmail(string $email): ?User + { foreach ($this->users as $user) { if ($user->hasEmailOf($email)) { return $user; diff --git a/src/web/backend/src/Gateways/Users/LocalUsersRepository.php b/src/web/backend/src/Gateways/Users/LocalUsersRepository.php index 6c83fe652828bd840fbdd12c4eac2d1ea51c153d..e7e9f2a4b356263dde619fd978039398bb500e10 100644 --- a/src/web/backend/src/Gateways/Users/LocalUsersRepository.php +++ b/src/web/backend/src/Gateways/Users/LocalUsersRepository.php @@ -3,12 +3,13 @@ namespace Source\Gateways\Users; - use Carbon\Carbon; use Source\Entities\User; -class LocalUsersRepository extends InMemoryUsersRepository { - public function __construct() { +class LocalUsersRepository extends InMemoryUsersRepository +{ + public function __construct() + { $this->create( new User( 1, diff --git a/src/web/backend/src/Gateways/Users/UsersRepository.php b/src/web/backend/src/Gateways/Users/UsersRepository.php index 1addecf1cd23356225bad3ced06b3d0b36c70cc1..e65f625003decbffbf379c7808c865ed8a87c776 100644 --- a/src/web/backend/src/Gateways/Users/UsersRepository.php +++ b/src/web/backend/src/Gateways/Users/UsersRepository.php @@ -3,10 +3,10 @@ namespace Source\Gateways\Users; - use Source\Entities\User; -interface UsersRepository { +interface UsersRepository +{ /** * @param string $userId * @return User|null diff --git a/src/web/backend/src/Gateways/Users/UsersRepositoryServiceProvider.php b/src/web/backend/src/Gateways/Users/UsersRepositoryServiceProvider.php index 78df20ef9a666adc7df822078f3f87c195c640f6..2b9d97d5bb630b956d2e2675ccafa4e81fc62cf3 100644 --- a/src/web/backend/src/Gateways/Users/UsersRepositoryServiceProvider.php +++ b/src/web/backend/src/Gateways/Users/UsersRepositoryServiceProvider.php @@ -3,20 +3,21 @@ namespace Source\Gateways\Users; - use Illuminate\Support\ServiceProvider; use Illuminate\Contracts\Support\DeferrableProvider; /** * Service provider must be registered in AppServiceProvider */ -class UsersRepositoryServiceProvider extends ServiceProvider implements DeferrableProvider { +class UsersRepositoryServiceProvider extends ServiceProvider implements DeferrableProvider +{ /** * Register any application services. * * @return void */ - public function register() { + public function register() + { $this->app->singleton( UsersRepository::class, static function () { @@ -24,7 +25,7 @@ class UsersRepositoryServiceProvider extends ServiceProvider implements Deferrab return new LocalUsersRepository(); } - if(env('APP_ENV') === 'testing') { + if (env('APP_ENV') === 'testing') { return new InMemoryUsersRepository(); } @@ -38,13 +39,15 @@ class UsersRepositoryServiceProvider extends ServiceProvider implements Deferrab * * @return void */ - public function boot(): void { + public function boot(): void + { } /** * @return array */ - public function provides() { + public function provides() + { return [UsersRepository::class]; } } diff --git a/src/web/backend/src/UseCases/BasePresenter.php b/src/web/backend/src/UseCases/BasePresenter.php index c51666d869702c48037f5c88c3e2a59c80890323..41e95fbaecbc5a88bf877604bd524c81ed6ef957 100644 --- a/src/web/backend/src/UseCases/BasePresenter.php +++ b/src/web/backend/src/UseCases/BasePresenter.php @@ -3,18 +3,19 @@ namespace Source\UseCases; - use Carbon\Carbon; use Source\Entities\User; -abstract class BasePresenter { +abstract class BasePresenter +{ /** * @param bool|null $bool * @param string $true * @param string $false * @return string */ - public function formatBool(?bool $bool, string $true = 'Yes', string $false = 'No'): ?string { + public function formatBool(?bool $bool, string $true = 'Yes', string $false = 'No'): ?string + { if ($bool === null) { return null; } @@ -27,7 +28,8 @@ abstract class BasePresenter { * @param string $format * @return string|null */ - public function formatDate(?Carbon $date, string $format = 'M j, Y'): ?string { + public function formatDate(?Carbon $date, string $format = 'M j, Y'): ?string + { if ($date === null) { return null; } @@ -40,7 +42,8 @@ abstract class BasePresenter { * @param string $format * @return string|null */ - public function formatTime(?Carbon $time, string $format = 'g:i A'): ?string { + public function formatTime(?Carbon $time, string $format = 'g:i A'): ?string + { if ($time === null) { return null; } @@ -53,7 +56,8 @@ abstract class BasePresenter { * @param string $format * @return string|null */ - public function formatDateTime(?Carbon $datetime, string $format = 'c'): ?string { + public function formatDateTime(?Carbon $datetime, string $format = 'c'): ?string + { if ($datetime === null) { return null; } @@ -65,7 +69,8 @@ abstract class BasePresenter { * @param User $user * @return array */ - public function formatUser(User $user): array { + public function formatUser(User $user): array + { return [ 'id' => $user->getId(), 'first_name' => $user->getFirstName(), diff --git a/src/web/backend/src/UseCases/Doors/Authenticate/Authenticate.php b/src/web/backend/src/UseCases/Doors/Authenticate/Authenticate.php index bd16962779670e07b73870286abc113e2b4a8f77..207812c76077d73d41b3b69228bbdcc262269919 100644 --- a/src/web/backend/src/UseCases/Doors/Authenticate/Authenticate.php +++ b/src/web/backend/src/UseCases/Doors/Authenticate/Authenticate.php @@ -4,17 +4,20 @@ namespace Source\UseCases\Doors\Authenticate; use Source\Gateways\Doors\DoorsRepository; -class Authenticate implements AuthenticateUseCase { +class Authenticate implements AuthenticateUseCase +{ protected DoorsRepository $doors; - public function __construct(DoorsRepository $doors) { + public function __construct(DoorsRepository $doors) + { $this->doors = $doors; } /** * @inheritDoc */ - public function check(Presenter $presenter, ?string $token): void { + public function check(Presenter $presenter, ?string $token): void + { if (!$token) { return; } diff --git a/src/web/backend/src/UseCases/Doors/Authenticate/AuthenticateUseCase.php b/src/web/backend/src/UseCases/Doors/Authenticate/AuthenticateUseCase.php index be194366a856c08881927b7676a8650d602c3636..cdf1c721b9fa656d209339dc09ee106ad1220b43 100644 --- a/src/web/backend/src/UseCases/Doors/Authenticate/AuthenticateUseCase.php +++ b/src/web/backend/src/UseCases/Doors/Authenticate/AuthenticateUseCase.php @@ -3,8 +3,8 @@ namespace Source\UseCases\Doors\Authenticate; - -interface AuthenticateUseCase { +interface AuthenticateUseCase +{ /** * Authenticates a door token * diff --git a/src/web/backend/src/UseCases/Doors/Authenticate/AuthenticateUseCaseServiceProvider.php b/src/web/backend/src/UseCases/Doors/Authenticate/AuthenticateUseCaseServiceProvider.php index 721980683b904073950b869874bb1364a81539bd..6201ab8d7a715e77117896277820aa4bc9880233 100644 --- a/src/web/backend/src/UseCases/Doors/Authenticate/AuthenticateUseCaseServiceProvider.php +++ b/src/web/backend/src/UseCases/Doors/Authenticate/AuthenticateUseCaseServiceProvider.php @@ -3,22 +3,23 @@ namespace Source\UseCases\Doors\Authenticate; - +use Illuminate\Support\ServiceProvider; use Source\Gateways\Doors\DoorsRepository; use Illuminate\Contracts\Foundation\Application; use Illuminate\Contracts\Support\DeferrableProvider; -use Illuminate\Support\ServiceProvider; /** * Service provider must be registered in AppServiceProvider */ -class AuthenticateUseCaseServiceProvider extends ServiceProvider implements DeferrableProvider { +class AuthenticateUseCaseServiceProvider extends ServiceProvider implements DeferrableProvider +{ /** * Register any application services. * * @return void */ - public function register() { + public function register() + { $this->app->bind(AuthenticateUseCase::class, static function (Application $app) { return new Authenticate($app->make(DoorsRepository::class)); }); @@ -29,13 +30,15 @@ class AuthenticateUseCaseServiceProvider extends ServiceProvider implements Defe * * @return void */ - public function boot(): void { + public function boot(): void + { } /** * @return array */ - public function provides() { + public function provides() + { return [AuthenticateUseCase::class]; } } diff --git a/src/web/backend/src/UseCases/Doors/Authenticate/Presenter.php b/src/web/backend/src/UseCases/Doors/Authenticate/Presenter.php index 133fd1af100bbdbd8b2d4ad0b0c98a9df1eacede..93d9b7b7c450b61d10d63e067f584ff3a6e233ef 100644 --- a/src/web/backend/src/UseCases/Doors/Authenticate/Presenter.php +++ b/src/web/backend/src/UseCases/Doors/Authenticate/Presenter.php @@ -4,7 +4,8 @@ namespace Source\UseCases\Doors\Authenticate; use App\Door; -interface Presenter { +interface Presenter +{ /** * @param ResponseModel $responseModel * @return void diff --git a/src/web/backend/src/UseCases/Doors/Authenticate/ResponseModel.php b/src/web/backend/src/UseCases/Doors/Authenticate/ResponseModel.php index 1b2b05d22a8db4111ad18fe345cf20cc60df45af..e695fca28acf26c8728a5ea47c6e0348a962a5c7 100644 --- a/src/web/backend/src/UseCases/Doors/Authenticate/ResponseModel.php +++ b/src/web/backend/src/UseCases/Doors/Authenticate/ResponseModel.php @@ -4,7 +4,8 @@ namespace Source\UseCases\Doors\Authenticate; use Source\Entities\Door; -class ResponseModel { +class ResponseModel +{ /** * @var Door|null */ @@ -13,14 +14,16 @@ class ResponseModel { /** * @param Door|null $door */ - public function setDoor(?Door $door): void { + public function setDoor(?Door $door): void + { $this->door = $door; } /** * @return Door|null */ - public function getDoor(): ?Door { + public function getDoor(): ?Door + { return $this->door; } } diff --git a/src/web/backend/src/UseCases/Doors/Authenticate/TranslationPresenter.php b/src/web/backend/src/UseCases/Doors/Authenticate/TranslationPresenter.php index f5503052f71bd3c7b57f6f12a7e26924b197d00a..c608624ebe7f097b71d6b9aa08bbaf6a3c771d02 100644 --- a/src/web/backend/src/UseCases/Doors/Authenticate/TranslationPresenter.php +++ b/src/web/backend/src/UseCases/Doors/Authenticate/TranslationPresenter.php @@ -5,11 +5,13 @@ namespace Source\UseCases\Doors\Authenticate; use App\Door; use Source\UseCases\BasePresenter; -class TranslationPresenter extends BasePresenter implements Presenter { +class TranslationPresenter extends BasePresenter implements Presenter +{ protected ?Door $viewModel = null; /** @inheritDoc */ - public function present(ResponseModel $responseModel): void { + public function present(ResponseModel $responseModel): void + { $door = $responseModel->getDoor(); if (!$door) { @@ -25,7 +27,8 @@ class TranslationPresenter extends BasePresenter implements Presenter { } /** @inheritDoc */ - public function getViewModel(): ?Door { + public function getViewModel(): ?Door + { return $this->viewModel; } } diff --git a/src/web/backend/src/UseCases/Token/Authenticate/Authenticate.php b/src/web/backend/src/UseCases/Token/Authenticate/Authenticate.php index fe096cbf1f08f417fff3ac574dcc551060245b2d..23f638d2c34acff8d9e6e54a0d5ce05e8ed99600 100644 --- a/src/web/backend/src/UseCases/Token/Authenticate/Authenticate.php +++ b/src/web/backend/src/UseCases/Token/Authenticate/Authenticate.php @@ -2,11 +2,11 @@ namespace Source\UseCases\Token\Authenticate; -use Source\Entities\User; use Source\Gateways\Users\UsersRepository; use Source\Gateways\Tokens\TokensRepository; -class Authenticate implements AuthenticateUseCase { +class Authenticate implements AuthenticateUseCase +{ protected TokensRepository $tokens; protected UsersRepository $users; @@ -15,7 +15,8 @@ class Authenticate implements AuthenticateUseCase { * @param TokensRepository $tokens * @param UsersRepository $users */ - public function __construct(TokensRepository $tokens, UsersRepository $users) { + public function __construct(TokensRepository $tokens, UsersRepository $users) + { $this->tokens = $tokens; $this->users = $users; } @@ -24,7 +25,8 @@ class Authenticate implements AuthenticateUseCase { /** * @inheritDoc */ - public function check(Presenter $presenter, ?string $token): void { + public function check(Presenter $presenter, ?string $token): void + { if (!$token) { return; } diff --git a/src/web/backend/src/UseCases/Token/Authenticate/AuthenticateUseCase.php b/src/web/backend/src/UseCases/Token/Authenticate/AuthenticateUseCase.php index 7539e7587d93f3d9359726551129a261a10e0eab..dbd410c33c6627d26d877b707c5d2528dc38f7e6 100644 --- a/src/web/backend/src/UseCases/Token/Authenticate/AuthenticateUseCase.php +++ b/src/web/backend/src/UseCases/Token/Authenticate/AuthenticateUseCase.php @@ -3,8 +3,8 @@ namespace Source\UseCases\Token\Authenticate; - -interface AuthenticateUseCase { +interface AuthenticateUseCase +{ /** * Authenticates an API token * diff --git a/src/web/backend/src/UseCases/Token/Authenticate/AuthenticateUseCaseServiceProvider.php b/src/web/backend/src/UseCases/Token/Authenticate/AuthenticateUseCaseServiceProvider.php index a43884c1c56fda959e60c30cf23abe9d3bedc42f..a10f726200a7855d9f3974132ed1cc2e1f64be0a 100644 --- a/src/web/backend/src/UseCases/Token/Authenticate/AuthenticateUseCaseServiceProvider.php +++ b/src/web/backend/src/UseCases/Token/Authenticate/AuthenticateUseCaseServiceProvider.php @@ -3,7 +3,6 @@ namespace Source\UseCases\Token\Authenticate; - use Illuminate\Support\ServiceProvider; use Source\Gateways\Users\UsersRepository; use Source\Gateways\Tokens\TokensRepository; @@ -13,13 +12,15 @@ use Illuminate\Contracts\Support\DeferrableProvider; /** * Service provider must be registered in AppServiceProvider */ -class AuthenticateUseCaseServiceProvider extends ServiceProvider implements DeferrableProvider { +class AuthenticateUseCaseServiceProvider extends ServiceProvider implements DeferrableProvider +{ /** * Register any application services. * * @return void */ - public function register() { + public function register() + { $this->app->bind( AuthenticateUseCase::class, static function (Application $app) { @@ -33,13 +34,15 @@ class AuthenticateUseCaseServiceProvider extends ServiceProvider implements Defe * * @return void */ - public function boot(): void { + public function boot(): void + { } /** * @return array */ - public function provides() { + public function provides() + { return [AuthenticateUseCase::class]; } } diff --git a/src/web/backend/src/UseCases/Token/Authenticate/Presenter.php b/src/web/backend/src/UseCases/Token/Authenticate/Presenter.php index bb2ddb080c976e63cd8b405b68053497cd534afd..7360b18f8963f4427b2ecf6ccfd61113ac11c88a 100644 --- a/src/web/backend/src/UseCases/Token/Authenticate/Presenter.php +++ b/src/web/backend/src/UseCases/Token/Authenticate/Presenter.php @@ -4,7 +4,8 @@ namespace Source\UseCases\Token\Authenticate; use App\User; -interface Presenter { +interface Presenter +{ /** * @param ResponseModel $responseModel * @return void diff --git a/src/web/backend/src/UseCases/Token/Authenticate/ResponseModel.php b/src/web/backend/src/UseCases/Token/Authenticate/ResponseModel.php index 9e0d63eb5e093e28a2e7d049a004831a474b750d..01d4bf20717f5729d1c3b68d84a30b511788ccab 100644 --- a/src/web/backend/src/UseCases/Token/Authenticate/ResponseModel.php +++ b/src/web/backend/src/UseCases/Token/Authenticate/ResponseModel.php @@ -4,7 +4,8 @@ namespace Source\UseCases\Token\Authenticate; use Source\Entities\User; -class ResponseModel { +class ResponseModel +{ /** * @var User|null */ @@ -13,14 +14,16 @@ class ResponseModel { /** * @param User|null $user */ - public function setUser(?User $user): void { + public function setUser(?User $user): void + { $this->user = $user; } /** * @return User|null */ - public function getUser(): ?User { + public function getUser(): ?User + { return $this->user; } } diff --git a/src/web/backend/src/UseCases/Token/Authenticate/TranslationPresenter.php b/src/web/backend/src/UseCases/Token/Authenticate/TranslationPresenter.php index 8268a5c9f671b32ee8ece21e470df579ed92208c..e97114f8c43dd794c9c182aa4482d17d5b737cf6 100644 --- a/src/web/backend/src/UseCases/Token/Authenticate/TranslationPresenter.php +++ b/src/web/backend/src/UseCases/Token/Authenticate/TranslationPresenter.php @@ -5,11 +5,13 @@ namespace Source\UseCases\Token\Authenticate; use App\User; use Source\UseCases\BasePresenter; -class TranslationPresenter extends BasePresenter implements Presenter { +class TranslationPresenter extends BasePresenter implements Presenter +{ protected ?User $viewModel = null; /** @inheritDoc */ - public function present(ResponseModel $responseModel): void { + public function present(ResponseModel $responseModel): void + { $user = $responseModel->getUser(); if (!$user) { @@ -30,7 +32,8 @@ class TranslationPresenter extends BasePresenter implements Presenter { } /** @inheritDoc */ - public function getViewModel(): ?User { + public function getViewModel(): ?User + { return $this->viewModel; } } diff --git a/src/web/backend/src/UseCases/Users/Authenticate/APIPresenter.php b/src/web/backend/src/UseCases/Users/Authenticate/APIPresenter.php index a34ee1ff31eb2d8a9054f14897800c9b56047e73..4fbd447aff9a6ced68903ace5ef262254064e321 100644 --- a/src/web/backend/src/UseCases/Users/Authenticate/APIPresenter.php +++ b/src/web/backend/src/UseCases/Users/Authenticate/APIPresenter.php @@ -5,11 +5,13 @@ namespace Source\UseCases\Users\Authenticate; use Carbon\Carbon; use Source\UseCases\BasePresenter; -class APIPresenter extends BasePresenter implements Presenter { +class APIPresenter extends BasePresenter implements Presenter +{ protected array $viewModel = []; /** @inheritDoc */ - public function present(ResponseModel $responseModel): void { + public function present(ResponseModel $responseModel): void + { $user = $responseModel->getUser(); $token = $responseModel->getToken(); $expires = $token->getExpiresAt(); @@ -30,7 +32,8 @@ class APIPresenter extends BasePresenter implements Presenter { } /** @inheritDoc */ - public function getViewModel(): array { + public function getViewModel(): array + { return $this->viewModel; } } diff --git a/src/web/backend/src/UseCases/Users/Authenticate/Authenticate.php b/src/web/backend/src/UseCases/Users/Authenticate/Authenticate.php index 0b374665188682fc122e3d4b7bedcee582d5178b..e0d721622c9ab88bd076f336871fb3fb3095dd9d 100644 --- a/src/web/backend/src/UseCases/Users/Authenticate/Authenticate.php +++ b/src/web/backend/src/UseCases/Users/Authenticate/Authenticate.php @@ -11,14 +11,16 @@ use Source\Gateways\Users\UsersRepository; use Source\Gateways\Tokens\TokensRepository; use Source\Exceptions\AuthenticationException; -class Authenticate implements AuthenticateUseCase { +class Authenticate implements AuthenticateUseCase +{ protected UsersRepository $users; protected TokensRepository $tokens; protected SamlRepository $saml; - public function __construct(UsersRepository $users, SamlRepository $saml, TokensRepository $tokens) { + public function __construct(UsersRepository $users, SamlRepository $saml, TokensRepository $tokens) + { $this->saml = $saml; $this->users = $users; $this->tokens = $tokens; @@ -27,7 +29,8 @@ class Authenticate implements AuthenticateUseCase { /** * @inheritDoc */ - public function attempt(Presenter $presenter, array $credentials): void { + public function attempt(Presenter $presenter, array $credentials): void + { $email = $credentials['email'] ?? null; $password = $credentials['password'] ?? null; @@ -56,14 +59,16 @@ class Authenticate implements AuthenticateUseCase { $presenter->present($response); } - public function handToSaml(array $options = []): string { + public function handToSaml(array $options = []): string + { return $this->saml->login($options); } /** * @inheritDoc */ - public function handleSamlLogin(Presenter $presenter): void { + public function handleSamlLogin(Presenter $presenter): void + { $user = $this->saml->handleLogin(); if (!$user) { @@ -111,7 +116,8 @@ class Authenticate implements AuthenticateUseCase { /** * @inheritDoc */ - public function samlLogout(?string $token): string { + public function samlLogout(?string $token): string + { $this->tokens->invalidateToken($token); return $this->saml->logout(); diff --git a/src/web/backend/src/UseCases/Users/Authenticate/AuthenticateUseCase.php b/src/web/backend/src/UseCases/Users/Authenticate/AuthenticateUseCase.php index fd1ac1aea1ff285ee079d30e912116ad3f176bcd..6b6e18ad5c50007f51c4231ef37fd121d9fe8694 100644 --- a/src/web/backend/src/UseCases/Users/Authenticate/AuthenticateUseCase.php +++ b/src/web/backend/src/UseCases/Users/Authenticate/AuthenticateUseCase.php @@ -3,11 +3,11 @@ namespace Source\UseCases\Users\Authenticate; - use Source\Exceptions\AuthenticationException; use Source\Exceptions\EntityNotFoundException; -interface AuthenticateUseCase { +interface AuthenticateUseCase +{ /** * Attempt an auth with credentials * diff --git a/src/web/backend/src/UseCases/Users/Authenticate/AuthenticateUseCaseServiceProvider.php b/src/web/backend/src/UseCases/Users/Authenticate/AuthenticateUseCaseServiceProvider.php index f7ff0cfbe3a3b438fd8da25d7004e2392df6fe34..d4154675756841ceacd89517228c09434f25cc7a 100644 --- a/src/web/backend/src/UseCases/Users/Authenticate/AuthenticateUseCaseServiceProvider.php +++ b/src/web/backend/src/UseCases/Users/Authenticate/AuthenticateUseCaseServiceProvider.php @@ -3,24 +3,25 @@ namespace Source\UseCases\Users\Authenticate; - +use Illuminate\Support\ServiceProvider; use Source\Gateways\Saml\SamlRepository; use Source\Gateways\Users\UsersRepository; use Source\Gateways\Tokens\TokensRepository; use Illuminate\Contracts\Foundation\Application; use Illuminate\Contracts\Support\DeferrableProvider; -use Illuminate\Support\ServiceProvider; /** * Service provider must be registered in AppServiceProvider */ -class AuthenticateUseCaseServiceProvider extends ServiceProvider implements DeferrableProvider { +class AuthenticateUseCaseServiceProvider extends ServiceProvider implements DeferrableProvider +{ /** * Register any application services. * * @return void */ - public function register() { + public function register() + { $this->app->bind(AuthenticateUseCase::class, static function (Application $app) { return new Authenticate( $app->make(UsersRepository::class), @@ -35,13 +36,15 @@ class AuthenticateUseCaseServiceProvider extends ServiceProvider implements Defe * * @return void */ - public function boot(): void { + public function boot(): void + { } /** * @return array */ - public function provides() { + public function provides() + { return [AuthenticateUseCase::class]; } } diff --git a/src/web/backend/src/UseCases/Users/Authenticate/Presenter.php b/src/web/backend/src/UseCases/Users/Authenticate/Presenter.php index 68b040e8f2920a75f03454c94e2f2141e4ca511f..51a829df9e3a5421312e876005714ed909f328a0 100644 --- a/src/web/backend/src/UseCases/Users/Authenticate/Presenter.php +++ b/src/web/backend/src/UseCases/Users/Authenticate/Presenter.php @@ -2,7 +2,8 @@ namespace Source\UseCases\Users\Authenticate; -interface Presenter { +interface Presenter +{ /** * @param ResponseModel $responseModel * @return void diff --git a/src/web/backend/src/UseCases/Users/Authenticate/ResponseModel.php b/src/web/backend/src/UseCases/Users/Authenticate/ResponseModel.php index 5251eecbe0d0eb51ad0b8a1ba07a98f8f7fc2441..69a508382cb4baffe4f30a19e9a8df49e03896b7 100644 --- a/src/web/backend/src/UseCases/Users/Authenticate/ResponseModel.php +++ b/src/web/backend/src/UseCases/Users/Authenticate/ResponseModel.php @@ -5,7 +5,8 @@ namespace Source\UseCases\Users\Authenticate; use Source\Entities\User; use Source\Entities\Token; -class ResponseModel { +class ResponseModel +{ /** * @var User */ @@ -20,7 +21,8 @@ class ResponseModel { * @param User $user * @param Token $token */ - public function __construct(User $user, Token $token) { + public function __construct(User $user, Token $token) + { $this->user = $user; $this->token = $token; } @@ -28,14 +30,16 @@ class ResponseModel { /** * @return User */ - public function getUser(): User { + public function getUser(): User + { return $this->user; } /** * @return Token */ - public function getToken(): Token { + public function getToken(): Token + { return $this->token; } } diff --git a/src/web/backend/src/UseCases/Users/Authenticate/UserCreationException.php b/src/web/backend/src/UseCases/Users/Authenticate/UserCreationException.php index d0c01efcb1479bd2fd4e4ef56dae25ae6483572b..c9818ba88eca37b35263543ca373beb7a58cb540 100644 --- a/src/web/backend/src/UseCases/Users/Authenticate/UserCreationException.php +++ b/src/web/backend/src/UseCases/Users/Authenticate/UserCreationException.php @@ -3,12 +3,13 @@ namespace Source\UseCases\Users\Authenticate; - use Exception; use Throwable; -class UserCreationException extends Exception { - public function __construct($message = 'Could not create user.', $code = 0, Throwable $previous = null) { +class UserCreationException extends Exception +{ + public function __construct($message = 'Could not create user.', $code = 0, Throwable $previous = null) + { parent::__construct($message, $code, $previous); } } diff --git a/src/web/backend/src/UseCases/Users/CreateUser/APIPresenter.php b/src/web/backend/src/UseCases/Users/CreateUser/APIPresenter.php index 7df074861880dbc5a6b59f552c9d39b01d169844..ad58d1c781fd2709c59fe3322b4bff22b2c80545 100644 --- a/src/web/backend/src/UseCases/Users/CreateUser/APIPresenter.php +++ b/src/web/backend/src/UseCases/Users/CreateUser/APIPresenter.php @@ -4,16 +4,19 @@ namespace Source\UseCases\Users\CreateUser; use Source\UseCases\BasePresenter; -class APIPresenter extends BasePresenter implements Presenter { +class APIPresenter extends BasePresenter implements Presenter +{ protected array $viewModel = []; /** @inheritDoc */ - public function present(ResponseModel $responseModel): void { + public function present(ResponseModel $responseModel): void + { $this->viewModel['user'] = $this->formatUser($responseModel->getUser()); } /** @inheritDoc */ - public function getViewModel(): array { + public function getViewModel(): array + { return $this->viewModel; } } diff --git a/src/web/backend/src/UseCases/Users/CreateUser/CreateUser.php b/src/web/backend/src/UseCases/Users/CreateUser/CreateUser.php index eb21014c89f3c7a7277bf4bab69f9b8da5a61ad1..178bf3f8eb72912c1c791de39d2444674fda7435 100644 --- a/src/web/backend/src/UseCases/Users/CreateUser/CreateUser.php +++ b/src/web/backend/src/UseCases/Users/CreateUser/CreateUser.php @@ -8,13 +8,15 @@ use Source\Entities\User; use Source\Gateways\Users\UsersRepository; use Source\Exceptions\EntityExistsException; -class CreateUser implements CreateUserUseCase { +class CreateUser implements CreateUserUseCase +{ /** * @var UsersRepository */ protected UsersRepository $usersRepository; - public function __construct(UsersRepository $usersRepository) { + public function __construct(UsersRepository $usersRepository) + { $this->usersRepository = $usersRepository; } @@ -22,7 +24,8 @@ class CreateUser implements CreateUserUseCase { * @inheritDoc * @throws Exception */ - public function create(array $attributes, Presenter $presenter): void { + public function create(array $attributes, Presenter $presenter): void + { $expires = $attributes['expires_at'] ?? null; $expires = $expires ? new Carbon($expires) : null; diff --git a/src/web/backend/src/UseCases/Users/CreateUser/CreateUserUseCase.php b/src/web/backend/src/UseCases/Users/CreateUser/CreateUserUseCase.php index c480b5c88e6d574a4e4752133d204d09ecff6b4e..79536647725480cb19ca6c0272f2efae0cd7e3b1 100644 --- a/src/web/backend/src/UseCases/Users/CreateUser/CreateUserUseCase.php +++ b/src/web/backend/src/UseCases/Users/CreateUser/CreateUserUseCase.php @@ -3,10 +3,10 @@ namespace Source\UseCases\Users\CreateUser; - use Source\Exceptions\EntityExistsException; -interface CreateUserUseCase { +interface CreateUserUseCase +{ /** * Required attributes: * first_name diff --git a/src/web/backend/src/UseCases/Users/CreateUser/CreateUserUseCaseServiceProvider.php b/src/web/backend/src/UseCases/Users/CreateUser/CreateUserUseCaseServiceProvider.php index 9b594a329fa3a17c6e007e5628dd43dc1dd7c152..2d41b8cc03c2b21be44eab3d62055fc2a2cb126b 100644 --- a/src/web/backend/src/UseCases/Users/CreateUser/CreateUserUseCaseServiceProvider.php +++ b/src/web/backend/src/UseCases/Users/CreateUser/CreateUserUseCaseServiceProvider.php @@ -3,7 +3,6 @@ namespace Source\UseCases\Users\CreateUser; - use Illuminate\Support\ServiceProvider; use Source\Gateways\Users\UsersRepository; use Illuminate\Contracts\Foundation\Application; @@ -12,13 +11,15 @@ use Illuminate\Contracts\Support\DeferrableProvider; /** * Service provider must be registered in AppServiceProvider */ -class CreateUserUseCaseServiceProvider extends ServiceProvider implements DeferrableProvider { +class CreateUserUseCaseServiceProvider extends ServiceProvider implements DeferrableProvider +{ /** * Register any application services. * * @return void */ - public function register() { + public function register() + { $this->app->bind( CreateUserUseCase::class, static function (Application $app) { @@ -32,13 +33,15 @@ class CreateUserUseCaseServiceProvider extends ServiceProvider implements Deferr * * @return void */ - public function boot(): void { + public function boot(): void + { } /** * @return array */ - public function provides() { + public function provides() + { return [CreateUserUseCase::class]; } } diff --git a/src/web/backend/src/UseCases/Users/CreateUser/Presenter.php b/src/web/backend/src/UseCases/Users/CreateUser/Presenter.php index 132fad9e83c435e87fe54fc7cfb2a0315b7e9491..e03e6fe0c3cebcf586bd18f65676166f87be7756 100644 --- a/src/web/backend/src/UseCases/Users/CreateUser/Presenter.php +++ b/src/web/backend/src/UseCases/Users/CreateUser/Presenter.php @@ -2,7 +2,8 @@ namespace Source\UseCases\Users\CreateUser; -interface Presenter { +interface Presenter +{ /** * @param ResponseModel $responseModel * @return void diff --git a/src/web/backend/src/UseCases/Users/CreateUser/ResponseModel.php b/src/web/backend/src/UseCases/Users/CreateUser/ResponseModel.php index fe54fbc55913a8de7ce29bbf0172fe15f188843f..90fd784f85aba4cc9b67a6846a53e77568e7ae12 100644 --- a/src/web/backend/src/UseCases/Users/CreateUser/ResponseModel.php +++ b/src/web/backend/src/UseCases/Users/CreateUser/ResponseModel.php @@ -4,7 +4,8 @@ namespace Source\UseCases\Users\CreateUser; use Source\Entities\User; -class ResponseModel { +class ResponseModel +{ /** * @var User */ @@ -13,14 +14,16 @@ class ResponseModel { /** * @param User $user */ - public function __construct(User $user) { + public function __construct(User $user) + { $this->user = $user; } /** * @return User */ - public function getUser(): User { + public function getUser(): User + { return $this->user; } } diff --git a/src/web/backend/src/UseCases/Users/DeleteUser/APIPresenter.php b/src/web/backend/src/UseCases/Users/DeleteUser/APIPresenter.php index e5ef755520ebadb55b20eb8a48393175b2c2db56..06eb288cd4f1defd06b6bb72993c079fd3734dc6 100644 --- a/src/web/backend/src/UseCases/Users/DeleteUser/APIPresenter.php +++ b/src/web/backend/src/UseCases/Users/DeleteUser/APIPresenter.php @@ -4,16 +4,19 @@ namespace Source\UseCases\Users\DeleteUser; use Source\UseCases\BasePresenter; -class APIPresenter extends BasePresenter implements Presenter { +class APIPresenter extends BasePresenter implements Presenter +{ protected array $viewModel = []; /** @inheritDoc */ - public function present(ResponseModel $responseModel): void { + public function present(ResponseModel $responseModel): void + { $this->viewModel['message'] = $responseModel->getMessage(); } /** @inheritDoc */ - public function getViewModel(): array { + public function getViewModel(): array + { return $this->viewModel; } } diff --git a/src/web/backend/src/UseCases/Users/DeleteUser/DeleteFailedException.php b/src/web/backend/src/UseCases/Users/DeleteUser/DeleteFailedException.php index b0dcf46af49cf401ad0e7940cf8c85dd9f4cd77f..28e0cf3de7e1517c04f0a050a9b366ae4ea83cba 100644 --- a/src/web/backend/src/UseCases/Users/DeleteUser/DeleteFailedException.php +++ b/src/web/backend/src/UseCases/Users/DeleteUser/DeleteFailedException.php @@ -3,12 +3,13 @@ namespace Source\UseCases\Users\DeleteUser; - use Exception; use Throwable; -class DeleteFailedException extends Exception { - public function __construct($message = '', $code = 0, Throwable $previous = null) { +class DeleteFailedException extends Exception +{ + public function __construct($message = '', $code = 0, Throwable $previous = null) + { parent::__construct($message, $code, $previous); } } diff --git a/src/web/backend/src/UseCases/Users/DeleteUser/DeleteUser.php b/src/web/backend/src/UseCases/Users/DeleteUser/DeleteUser.php index 1d7006e7cb1d9160267f05bfde1087a2b758a283..c50a6c7ed36beea51de60ea5b278d0672796de5a 100644 --- a/src/web/backend/src/UseCases/Users/DeleteUser/DeleteUser.php +++ b/src/web/backend/src/UseCases/Users/DeleteUser/DeleteUser.php @@ -4,20 +4,23 @@ namespace Source\UseCases\Users\DeleteUser; use Source\Gateways\Users\UsersRepository; -class DeleteUser implements DeleteUserUseCase { +class DeleteUser implements DeleteUserUseCase +{ /** * @var UsersRepository */ protected UsersRepository $usersRepository; - public function __construct(UsersRepository $usersRepository) { + public function __construct(UsersRepository $usersRepository) + { $this->usersRepository = $usersRepository; } /** * @inheritDoc */ - public function delete(string $userId, Presenter $presenter): void { + public function delete(string $userId, Presenter $presenter): void + { if (!$this->usersRepository->delete($userId)) { throw new DeleteFailedException('Unable to delete user.'); } diff --git a/src/web/backend/src/UseCases/Users/DeleteUser/DeleteUserUseCase.php b/src/web/backend/src/UseCases/Users/DeleteUser/DeleteUserUseCase.php index 30d400499755097b6cac4847cf220e73f3d69ba7..402fad7b58c0c0eaba87a85291ad35c831862a19 100644 --- a/src/web/backend/src/UseCases/Users/DeleteUser/DeleteUserUseCase.php +++ b/src/web/backend/src/UseCases/Users/DeleteUser/DeleteUserUseCase.php @@ -3,8 +3,8 @@ namespace Source\UseCases\Users\DeleteUser; - -interface DeleteUserUseCase { +interface DeleteUserUseCase +{ /** * @param string $userId * @param Presenter $presenter diff --git a/src/web/backend/src/UseCases/Users/DeleteUser/DeleteUserUseCaseServiceProvider.php b/src/web/backend/src/UseCases/Users/DeleteUser/DeleteUserUseCaseServiceProvider.php index 516ab30f760e9db81ac11d72adf297b1ee832f79..965ef98c3ae5b5d5124336ff15aa8fb4a22c2425 100644 --- a/src/web/backend/src/UseCases/Users/DeleteUser/DeleteUserUseCaseServiceProvider.php +++ b/src/web/backend/src/UseCases/Users/DeleteUser/DeleteUserUseCaseServiceProvider.php @@ -3,7 +3,6 @@ namespace Source\UseCases\Users\DeleteUser; - use Illuminate\Support\ServiceProvider; use Source\Gateways\Users\UsersRepository; use Illuminate\Contracts\Foundation\Application; @@ -12,13 +11,15 @@ use Illuminate\Contracts\Support\DeferrableProvider; /** * Service provider must be registered in AppServiceProvider */ -class DeleteUserUseCaseServiceProvider extends ServiceProvider implements DeferrableProvider { +class DeleteUserUseCaseServiceProvider extends ServiceProvider implements DeferrableProvider +{ /** * Register any application services. * * @return void */ - public function register() { + public function register() + { $this->app->bind( DeleteUserUseCase::class, static function (Application $app) { @@ -32,13 +33,15 @@ class DeleteUserUseCaseServiceProvider extends ServiceProvider implements Deferr * * @return void */ - public function boot(): void { + public function boot(): void + { } /** * @return array */ - public function provides() { + public function provides() + { return [DeleteUserUseCase::class]; } } diff --git a/src/web/backend/src/UseCases/Users/DeleteUser/Presenter.php b/src/web/backend/src/UseCases/Users/DeleteUser/Presenter.php index 3699ac32c085a29f3d00d36d8e4925b9e9f04ca5..a0e696761186f9551b5dd360c1f6e0ed06277d53 100644 --- a/src/web/backend/src/UseCases/Users/DeleteUser/Presenter.php +++ b/src/web/backend/src/UseCases/Users/DeleteUser/Presenter.php @@ -2,7 +2,8 @@ namespace Source\UseCases\Users\DeleteUser; -interface Presenter { +interface Presenter +{ /** * @param ResponseModel $responseModel * @return void diff --git a/src/web/backend/src/UseCases/Users/DeleteUser/ResponseModel.php b/src/web/backend/src/UseCases/Users/DeleteUser/ResponseModel.php index 569ae63bc2d0a65fdfdf149fc5171dd6f04e10ae..1d371bb96126c10a0e992cd7d842806833f38f39 100644 --- a/src/web/backend/src/UseCases/Users/DeleteUser/ResponseModel.php +++ b/src/web/backend/src/UseCases/Users/DeleteUser/ResponseModel.php @@ -2,7 +2,8 @@ namespace Source\UseCases\Users\DeleteUser; -class ResponseModel { +class ResponseModel +{ /** * @var string */ @@ -11,14 +12,16 @@ class ResponseModel { /** * @param string $message */ - public function __construct(string $message) { + public function __construct(string $message) + { $this->message = $message; } /** * @return string */ - public function getMessage(): string { + public function getMessage(): string + { return $this->message; } } diff --git a/src/web/backend/src/UseCases/Users/GetAllUsers/APIPresenter.php b/src/web/backend/src/UseCases/Users/GetAllUsers/APIPresenter.php index 0d0b942e99c7eeed69bffcfc84edf2b4d6fd2344..76f6f41f80db779c74923890a36e622e817b3447 100644 --- a/src/web/backend/src/UseCases/Users/GetAllUsers/APIPresenter.php +++ b/src/web/backend/src/UseCases/Users/GetAllUsers/APIPresenter.php @@ -5,18 +5,21 @@ namespace Source\UseCases\Users\GetAllUsers; use Source\Entities\User; use Source\UseCases\BasePresenter; -class APIPresenter extends BasePresenter implements Presenter { +class APIPresenter extends BasePresenter implements Presenter +{ protected array $viewModel = []; /** @inheritDoc */ - public function present(ResponseModel $responseModel): void { + public function present(ResponseModel $responseModel): void + { $this->viewModel['users'] = array_map(function (User $user) { return $this->formatUser($user); }, $responseModel->getUsers()); } /** @inheritDoc */ - public function getViewModel(): array { + public function getViewModel(): array + { return $this->viewModel; } } diff --git a/src/web/backend/src/UseCases/Users/GetAllUsers/GetAllUsers.php b/src/web/backend/src/UseCases/Users/GetAllUsers/GetAllUsers.php index 8b754b5490864e46b776599ec6d24fd226bd19a8..8a1d83f1f7d25010b08a0fddb3aae484f579af84 100644 --- a/src/web/backend/src/UseCases/Users/GetAllUsers/GetAllUsers.php +++ b/src/web/backend/src/UseCases/Users/GetAllUsers/GetAllUsers.php @@ -4,17 +4,20 @@ namespace Source\UseCases\Users\GetAllUsers; use Source\Gateways\Users\UsersRepository; -class GetAllUsers implements GetAllUsersUseCase { +class GetAllUsers implements GetAllUsersUseCase +{ /** * @var UsersRepository */ protected UsersRepository $usersRepository; - public function __construct(UsersRepository $usersRepository) { + public function __construct(UsersRepository $usersRepository) + { $this->usersRepository = $usersRepository; } - public function all(Presenter $presenter): void { + public function all(Presenter $presenter): void + { $response = new ResponseModel(); foreach ($this->usersRepository->all() as $user) { diff --git a/src/web/backend/src/UseCases/Users/GetAllUsers/GetAllUsersUseCase.php b/src/web/backend/src/UseCases/Users/GetAllUsers/GetAllUsersUseCase.php index bb26a6f64010793cdffd4f8d75087f0fd4c63d8b..b51646ca23cfe97236986424a7b64b9f119299f1 100644 --- a/src/web/backend/src/UseCases/Users/GetAllUsers/GetAllUsersUseCase.php +++ b/src/web/backend/src/UseCases/Users/GetAllUsers/GetAllUsersUseCase.php @@ -3,8 +3,8 @@ namespace Source\UseCases\Users\GetAllUsers; - -interface GetAllUsersUseCase { +interface GetAllUsersUseCase +{ /** * @param Presenter $presenter */ diff --git a/src/web/backend/src/UseCases/Users/GetAllUsers/GetAllUsersUseCaseServiceProvider.php b/src/web/backend/src/UseCases/Users/GetAllUsers/GetAllUsersUseCaseServiceProvider.php index 34ec575bb9e79fe25a5560f2116cb06594ffccde..e006d0819e087e3bbd42206ebee5d6c7307024b6 100644 --- a/src/web/backend/src/UseCases/Users/GetAllUsers/GetAllUsersUseCaseServiceProvider.php +++ b/src/web/backend/src/UseCases/Users/GetAllUsers/GetAllUsersUseCaseServiceProvider.php @@ -3,7 +3,6 @@ namespace Source\UseCases\Users\GetAllUsers; - use Illuminate\Support\ServiceProvider; use Source\Gateways\Users\UsersRepository; use Illuminate\Contracts\Foundation\Application; @@ -12,13 +11,15 @@ use Illuminate\Contracts\Support\DeferrableProvider; /** * Service provider must be registered in AppServiceProvider */ -class GetAllUsersUseCaseServiceProvider extends ServiceProvider implements DeferrableProvider { +class GetAllUsersUseCaseServiceProvider extends ServiceProvider implements DeferrableProvider +{ /** * Register any application services. * * @return void */ - public function register() { + public function register() + { $this->app->bind( GetAllUsersUseCase::class, static function (Application $app) { @@ -32,13 +33,15 @@ class GetAllUsersUseCaseServiceProvider extends ServiceProvider implements Defer * * @return void */ - public function boot(): void { + public function boot(): void + { } /** * @return array */ - public function provides() { + public function provides() + { return [GetAllUsersUseCase::class]; } } diff --git a/src/web/backend/src/UseCases/Users/GetAllUsers/Presenter.php b/src/web/backend/src/UseCases/Users/GetAllUsers/Presenter.php index 33b0d5d826c73ea78ec51e64c65061c0e6dff8e6..1c3c29b2fe068aa419af6ceabb9bd13f61d8cb39 100644 --- a/src/web/backend/src/UseCases/Users/GetAllUsers/Presenter.php +++ b/src/web/backend/src/UseCases/Users/GetAllUsers/Presenter.php @@ -2,7 +2,8 @@ namespace Source\UseCases\Users\GetAllUsers; -interface Presenter { +interface Presenter +{ /** * @param ResponseModel $responseModel * @return void diff --git a/src/web/backend/src/UseCases/Users/GetAllUsers/ResponseModel.php b/src/web/backend/src/UseCases/Users/GetAllUsers/ResponseModel.php index fe8b45a90e74f87775a6b0f0ef2ba45bf7a72d2f..0338f8fbee5c3c92a9374ca3ef997b6a5a9fe3bd 100644 --- a/src/web/backend/src/UseCases/Users/GetAllUsers/ResponseModel.php +++ b/src/web/backend/src/UseCases/Users/GetAllUsers/ResponseModel.php @@ -4,7 +4,8 @@ namespace Source\UseCases\Users\GetAllUsers; use Source\Entities\User; -class ResponseModel { +class ResponseModel +{ /** * @var User[] */ @@ -13,14 +14,16 @@ class ResponseModel { /** * @param User $user */ - public function addUser(User $user): void { + public function addUser(User $user): void + { $this->users[] = $user; } /** * @return User[] */ - public function getUsers(): array { + public function getUsers(): array + { return $this->users; } } diff --git a/src/web/backend/src/UseCases/Users/GetUser/APIPresenter.php b/src/web/backend/src/UseCases/Users/GetUser/APIPresenter.php index b2eb58b84bebf3991dbc393c0e602fd1c5f7ebc5..35cf7a64ececf76182bce89530cda7d02dc5ec51 100644 --- a/src/web/backend/src/UseCases/Users/GetUser/APIPresenter.php +++ b/src/web/backend/src/UseCases/Users/GetUser/APIPresenter.php @@ -4,16 +4,19 @@ namespace Source\UseCases\Users\GetUser; use Source\UseCases\BasePresenter; -class APIPresenter extends BasePresenter implements Presenter { +class APIPresenter extends BasePresenter implements Presenter +{ protected array $viewModel = []; /** @inheritDoc */ - public function present(ResponseModel $responseModel): void { + public function present(ResponseModel $responseModel): void + { $this->viewModel['user'] = $this->formatUser($responseModel->getUser()); } /** @inheritDoc */ - public function getViewModel(): array { + public function getViewModel(): array + { return $this->viewModel; } } diff --git a/src/web/backend/src/UseCases/Users/GetUser/GetUser.php b/src/web/backend/src/UseCases/Users/GetUser/GetUser.php index 62fe1db5f7f19944c43d9dad4341079bc5c3598e..6de82749fb2835eff2a0354d2ee289a65aea343a 100644 --- a/src/web/backend/src/UseCases/Users/GetUser/GetUser.php +++ b/src/web/backend/src/UseCases/Users/GetUser/GetUser.php @@ -2,23 +2,26 @@ namespace Source\UseCases\Users\GetUser; -use Source\Exceptions\EntityNotFoundException; use Source\Gateways\Users\UsersRepository; +use Source\Exceptions\EntityNotFoundException; -class GetUser implements GetUserUseCase { +class GetUser implements GetUserUseCase +{ /** * @var UsersRepository */ protected UsersRepository $usersRepository; - public function __construct(UsersRepository $usersRepository) { + public function __construct(UsersRepository $usersRepository) + { $this->usersRepository = $usersRepository; } /** * @inheritDoc */ - public function get(string $userId, Presenter $presenter): void { + public function get(string $userId, Presenter $presenter): void + { $user = $this->usersRepository->get($userId); if (!$user) { @@ -29,6 +32,4 @@ class GetUser implements GetUserUseCase { $presenter->present($response); } - - } diff --git a/src/web/backend/src/UseCases/Users/GetUser/GetUserUseCase.php b/src/web/backend/src/UseCases/Users/GetUser/GetUserUseCase.php index d5d6e5ad826fdc61805e7938775377cb9ec610d6..98dcf556c4265ddfd0e92eaebabd190d95b5c38b 100644 --- a/src/web/backend/src/UseCases/Users/GetUser/GetUserUseCase.php +++ b/src/web/backend/src/UseCases/Users/GetUser/GetUserUseCase.php @@ -3,10 +3,10 @@ namespace Source\UseCases\Users\GetUser; - use Source\Exceptions\EntityNotFoundException; -interface GetUserUseCase { +interface GetUserUseCase +{ /** * @param string $userId * @param Presenter $presenter diff --git a/src/web/backend/src/UseCases/Users/GetUser/GetUserUseCaseServiceProvider.php b/src/web/backend/src/UseCases/Users/GetUser/GetUserUseCaseServiceProvider.php index 2c302e8e3767700ee9ecab8c1e3bc0b46e2e070a..f244579cc5a56d8b8e34d77c8ea02525140603dd 100644 --- a/src/web/backend/src/UseCases/Users/GetUser/GetUserUseCaseServiceProvider.php +++ b/src/web/backend/src/UseCases/Users/GetUser/GetUserUseCaseServiceProvider.php @@ -3,7 +3,6 @@ namespace Source\UseCases\Users\GetUser; - use Illuminate\Support\ServiceProvider; use Source\Gateways\Users\UsersRepository; use Illuminate\Contracts\Foundation\Application; @@ -12,13 +11,15 @@ use Illuminate\Contracts\Support\DeferrableProvider; /** * Service provider must be registered in AppServiceProvider */ -class GetUserUseCaseServiceProvider extends ServiceProvider implements DeferrableProvider { +class GetUserUseCaseServiceProvider extends ServiceProvider implements DeferrableProvider +{ /** * Register any application services. * * @return void */ - public function register() { + public function register() + { $this->app->bind( GetUserUseCase::class, static function (Application $app) { @@ -32,13 +33,15 @@ class GetUserUseCaseServiceProvider extends ServiceProvider implements Deferrabl * * @return void */ - public function boot(): void { + public function boot(): void + { } /** * @return array */ - public function provides() { + public function provides() + { return [GetUserUseCase::class]; } } diff --git a/src/web/backend/src/UseCases/Users/GetUser/Presenter.php b/src/web/backend/src/UseCases/Users/GetUser/Presenter.php index d191f348358c11d5e2916922f39bdbd2a5276b67..20ca4b4093d05b4b90639807ed0713c5fb97d816 100644 --- a/src/web/backend/src/UseCases/Users/GetUser/Presenter.php +++ b/src/web/backend/src/UseCases/Users/GetUser/Presenter.php @@ -2,7 +2,8 @@ namespace Source\UseCases\Users\GetUser; -interface Presenter { +interface Presenter +{ /** * @param ResponseModel $responseModel * @return void diff --git a/src/web/backend/src/UseCases/Users/GetUser/ResponseModel.php b/src/web/backend/src/UseCases/Users/GetUser/ResponseModel.php index e76a5eb6b6e26b02994c68487d0aa99bd6f82b91..329d3c94d0d700d9f26aba364e0b8a10cd6cca71 100644 --- a/src/web/backend/src/UseCases/Users/GetUser/ResponseModel.php +++ b/src/web/backend/src/UseCases/Users/GetUser/ResponseModel.php @@ -4,20 +4,23 @@ namespace Source\UseCases\Users\GetUser; use Source\Entities\User; -class ResponseModel { +class ResponseModel +{ /** * @var User */ protected User $user; - public function __construct(User $user) { + public function __construct(User $user) + { $this->user = $user; } /** * @return User */ - public function getUser(): User { + public function getUser(): User + { return $this->user; } } diff --git a/src/web/backend/src/UseCases/Users/UpdateUser/APIPresenter.php b/src/web/backend/src/UseCases/Users/UpdateUser/APIPresenter.php index 55192973baf4ac2b8e6339b645e84372baac7bf9..99f66a7ad3e29a695a1b43f6ba6c9f986b3ed1f0 100644 --- a/src/web/backend/src/UseCases/Users/UpdateUser/APIPresenter.php +++ b/src/web/backend/src/UseCases/Users/UpdateUser/APIPresenter.php @@ -4,11 +4,13 @@ namespace Source\UseCases\Users\UpdateUser; use Source\UseCases\BasePresenter; -class APIPresenter extends BasePresenter implements Presenter { +class APIPresenter extends BasePresenter implements Presenter +{ protected array $viewModel = []; /** @inheritDoc */ - public function present(ResponseModel $responseModel): void { + public function present(ResponseModel $responseModel): void + { $this->viewModel['error'] = $responseModel->hasError(); if ($responseModel->hasError()) { $this->viewModel['message'] = $responseModel->getError(); @@ -18,7 +20,8 @@ class APIPresenter extends BasePresenter implements Presenter { } /** @inheritDoc */ - public function getViewModel(): array { + public function getViewModel(): array + { return $this->viewModel; } } diff --git a/src/web/backend/src/UseCases/Users/UpdateUser/Presenter.php b/src/web/backend/src/UseCases/Users/UpdateUser/Presenter.php index f25f99dc94639efd44fe58d4d9e1d4b42eca1393..f5231fa6412655dc75f5eb03c832b5baa036411b 100644 --- a/src/web/backend/src/UseCases/Users/UpdateUser/Presenter.php +++ b/src/web/backend/src/UseCases/Users/UpdateUser/Presenter.php @@ -2,7 +2,8 @@ namespace Source\UseCases\Users\UpdateUser; -interface Presenter { +interface Presenter +{ /** * @param ResponseModel $responseModel * @return void diff --git a/src/web/backend/src/UseCases/Users/UpdateUser/ResponseModel.php b/src/web/backend/src/UseCases/Users/UpdateUser/ResponseModel.php index 924d495110441802a9eb28d4b992f64e6a653c92..8d09be8884f3ff5d07cdda9f27e4bf66c739549c 100644 --- a/src/web/backend/src/UseCases/Users/UpdateUser/ResponseModel.php +++ b/src/web/backend/src/UseCases/Users/UpdateUser/ResponseModel.php @@ -4,7 +4,8 @@ namespace Source\UseCases\Users\UpdateUser; use Source\Entities\User; -class ResponseModel { +class ResponseModel +{ /** * @var string */ @@ -18,35 +19,40 @@ class ResponseModel { /** * @param string $error */ - public function setError(string $error): void { + public function setError(string $error): void + { $this->error = $error; } /** * @param User $user */ - public function setUser(User $user): void { + public function setUser(User $user): void + { $this->user = $user; } /** * @return bool */ - public function hasError(): bool { + public function hasError(): bool + { return $this->error; } /** * @return string */ - public function getError(): string { + public function getError(): string + { return $this->error; } /** * @return User */ - public function getUser(): User { + public function getUser(): User + { return $this->user; } } diff --git a/src/web/backend/src/UseCases/Users/UpdateUser/UpdateUser.php b/src/web/backend/src/UseCases/Users/UpdateUser/UpdateUser.php index f3afede06c15544ff8dcc83272f64859633c366a..1187184b886325d43f5eb63e58facbaea7ce500e 100644 --- a/src/web/backend/src/UseCases/Users/UpdateUser/UpdateUser.php +++ b/src/web/backend/src/UseCases/Users/UpdateUser/UpdateUser.php @@ -8,7 +8,8 @@ use Source\Entities\User; use Source\Gateways\Users\UsersRepository; use Source\Exceptions\EntityNotFoundException; -class UpdateUser implements UpdateUserUseCase { +class UpdateUser implements UpdateUserUseCase +{ /** * @var UsersRepository */ @@ -17,7 +18,8 @@ class UpdateUser implements UpdateUserUseCase { /** * @param UsersRepository $usersRepository */ - public function __construct(UsersRepository $usersRepository) { + public function __construct(UsersRepository $usersRepository) + { $this->usersRepository = $usersRepository; } @@ -25,14 +27,15 @@ class UpdateUser implements UpdateUserUseCase { * @inheritDoc * @throws Exception */ - public function update(string $userId, array $attributes, Presenter $presenter): void { + public function update(string $userId, array $attributes, Presenter $presenter): void + { $user = $this->usersRepository->get($userId); if (!$user) { throw new EntityNotFoundException(); } - $expires = (array_key_exists('expires_at', $attributes) && $attributes['expires_at']) ? new Carbon - ($attributes['expires_at'] + $expires = (array_key_exists('expires_at', $attributes) && $attributes['expires_at']) ? new Carbon( + $attributes['expires_at'] ) : null; // updatedAt will get overwritten @@ -55,8 +58,7 @@ class UpdateUser implements UpdateUserUseCase { if (!$returnedUser) { $response->setError('Unable to update user.'); - } - else { + } else { $response->setUser($returnedUser); } diff --git a/src/web/backend/src/UseCases/Users/UpdateUser/UpdateUserUseCase.php b/src/web/backend/src/UseCases/Users/UpdateUser/UpdateUserUseCase.php index 88f97b473dd30f32988f6dd90af46a20056dab2f..58238bfd880d601be5e3cb0ab86e7848ab5244ab 100644 --- a/src/web/backend/src/UseCases/Users/UpdateUser/UpdateUserUseCase.php +++ b/src/web/backend/src/UseCases/Users/UpdateUser/UpdateUserUseCase.php @@ -3,10 +3,10 @@ namespace Source\UseCases\Users\UpdateUser; - use Source\Exceptions\EntityNotFoundException; -interface UpdateUserUseCase { +interface UpdateUserUseCase +{ /** * Required attributes: * first_name diff --git a/src/web/backend/src/UseCases/Users/UpdateUser/UpdateUserUseCaseServiceProvider.php b/src/web/backend/src/UseCases/Users/UpdateUser/UpdateUserUseCaseServiceProvider.php index 793b524838f257503f9502062bad550355ed4a7e..15a3201a316db4a3552f1e98a47a40988a06a0a9 100644 --- a/src/web/backend/src/UseCases/Users/UpdateUser/UpdateUserUseCaseServiceProvider.php +++ b/src/web/backend/src/UseCases/Users/UpdateUser/UpdateUserUseCaseServiceProvider.php @@ -3,22 +3,23 @@ namespace Source\UseCases\Users\UpdateUser; - +use Illuminate\Support\ServiceProvider; use Source\Gateways\Users\UsersRepository; use Illuminate\Contracts\Foundation\Application; use Illuminate\Contracts\Support\DeferrableProvider; -use Illuminate\Support\ServiceProvider; /** * Service provider must be registered in AppServiceProvider */ -class UpdateUserUseCaseServiceProvider extends ServiceProvider implements DeferrableProvider { +class UpdateUserUseCaseServiceProvider extends ServiceProvider implements DeferrableProvider +{ /** * Register any application services. * * @return void */ - public function register() { + public function register() + { $this->app->bind(UpdateUserUseCase::class, static function (Application $app) { return new UpdateUser($app->make(UsersRepository::class)); }); @@ -29,13 +30,15 @@ class UpdateUserUseCaseServiceProvider extends ServiceProvider implements Deferr * * @return void */ - public function boot(): void { + public function boot(): void + { } /** * @return array */ - public function provides() { + public function provides() + { return [UpdateUserUseCase::class]; } } diff --git a/src/web/backend/tests/Doubles/InMemoryUsersRepositoryStub.php b/src/web/backend/tests/Doubles/InMemoryUsersRepositoryStub.php index 213af0e8e99c9f9145c09a7d4df8423c2eeb5cc6..1fd2094777c2cb354ac8a541dc0fb87ee2fd5193 100644 --- a/src/web/backend/tests/Doubles/InMemoryUsersRepositoryStub.php +++ b/src/web/backend/tests/Doubles/InMemoryUsersRepositoryStub.php @@ -3,14 +3,15 @@ namespace Tests\Doubles; - use Source\Entities\User; use Source\Gateways\Users\UsersRepository; -class InMemoryUsersRepositoryStub implements UsersRepository { +class InMemoryUsersRepositoryStub implements UsersRepository +{ protected ?User $user; - public function setUserToReturnOnGet(User $user): void { + public function setUserToReturnOnGet(User $user): void + { $this->user = $user; } @@ -18,7 +19,8 @@ class InMemoryUsersRepositoryStub implements UsersRepository { * @param string $userId * @return User|null */ - public function get(string $userId): ?User { + public function get(string $userId): ?User + { if ($this->user) { return $this->user; } @@ -28,7 +30,8 @@ class InMemoryUsersRepositoryStub implements UsersRepository { /** * @return array */ - public function all(): array { + public function all(): array + { return []; } @@ -36,7 +39,8 @@ class InMemoryUsersRepositoryStub implements UsersRepository { * @param User $user * @return User|null */ - public function create(User $user): ?User { + public function create(User $user): ?User + { return null; } @@ -45,7 +49,8 @@ class InMemoryUsersRepositoryStub implements UsersRepository { * @param User $user * @return User|null */ - public function update(string $userId, User $user): ?User { + public function update(string $userId, User $user): ?User + { return null; } @@ -53,7 +58,8 @@ class InMemoryUsersRepositoryStub implements UsersRepository { * @param string $userId * @return bool */ - public function delete(string $userId): bool { + public function delete(string $userId): bool + { return false; } @@ -61,28 +67,32 @@ class InMemoryUsersRepositoryStub implements UsersRepository { * @param string $userId * @return bool */ - public function exists(string $userId): bool { + public function exists(string $userId): bool + { return true; } /** * @inheritDoc */ - public function findByCredentials(string $email, string $password): ?User { + public function findByCredentials(string $email, string $password): ?User + { return null; } /** * @inheritDoc */ - public function findByDoorcode(string $doorcode): ?User { + public function findByDoorcode(string $doorcode): ?User + { return null; } /** * @inheritDoc */ - public function findByEmail(string $email): ?User { + public function findByEmail(string $email): ?User + { return null; } } diff --git a/src/web/backend/tests/Feature/Api/Users/CreateUserApiTest.php b/src/web/backend/tests/Feature/Api/Users/CreateUserApiTest.php index 5ef5b5241303f1370df8c102d923ffceef3d9720..23dc8b748175e06ab062540a4d44082b41eeb0da 100644 --- a/src/web/backend/tests/Feature/Api/Users/CreateUserApiTest.php +++ b/src/web/backend/tests/Feature/Api/Users/CreateUserApiTest.php @@ -3,19 +3,20 @@ namespace Tests\Feature\Api\Users; - use Source\Entities\User; use Source\Exceptions\EntityNotFoundException; use Illuminate\Foundation\Testing\TestResponse; use Tests\Feature\AuthenticatesWithApplicationTestCase; -class CreateUserApiTest extends AuthenticatesWithApplicationTestCase { +class CreateUserApiTest extends AuthenticatesWithApplicationTestCase +{ protected TestResponse $response; /** * @param array $data */ - protected function handleTest(array $data): void { + protected function handleTest(array $data): void + { $this->response = $this->postJson( '/users', array_merge( @@ -28,13 +29,15 @@ class CreateUserApiTest extends AuthenticatesWithApplicationTestCase { /** * @test */ - public function it_denies_unauthorized(): void { + public function it_denies_unauthorized(): void + { $this->handleTest([]); $this->response->assertStatus(401); } - public function invalidUserProvider(): array { + public function invalidUserProvider(): array + { $user = new User(0, 'first', 'last', 'display', null, 't@t.com', '', '43252643', null, null, null); return [ @@ -170,7 +173,8 @@ class CreateUserApiTest extends AuthenticatesWithApplicationTestCase { * @dataProvider invalidUserProvider * @throws EntityNotFoundException */ - public function it_tests_the_validation_rules(array $data, array $message): void { + public function it_tests_the_validation_rules(array $data, array $message): void + { $this->authorize(); $this->handleTest($data); $this->response->assertJsonFragment($message); @@ -180,7 +184,8 @@ class CreateUserApiTest extends AuthenticatesWithApplicationTestCase { * @test * @throws EntityNotFoundException */ - public function it_creates_a_user(): void { + public function it_creates_a_user(): void + { $this->authorize(); $this->handleTest( [ diff --git a/src/web/backend/tests/Feature/Api/Users/DeleteUserApiTest.php b/src/web/backend/tests/Feature/Api/Users/DeleteUserApiTest.php index a169ba360dc20ba05c9c6121622b55e4e9694dfc..9c45e3b035f5a707e9ca0aeffbcf0c350aa9a0f1 100644 --- a/src/web/backend/tests/Feature/Api/Users/DeleteUserApiTest.php +++ b/src/web/backend/tests/Feature/Api/Users/DeleteUserApiTest.php @@ -3,16 +3,17 @@ namespace Tests\Feature\Api\Users; - use Source\Entities\User; use Source\Exceptions\EntityNotFoundException; use Illuminate\Foundation\Testing\TestResponse; use Tests\Feature\AuthenticatesWithApplicationTestCase; -class DeleteUserApiTest extends AuthenticatesWithApplicationTestCase { +class DeleteUserApiTest extends AuthenticatesWithApplicationTestCase +{ protected TestResponse $response; - protected function handleTest(string $userId): void { + protected function handleTest(string $userId): void + { $this->response = $this->deleteJson( '/users/' . $userId, [ @@ -24,7 +25,8 @@ class DeleteUserApiTest extends AuthenticatesWithApplicationTestCase { /** * @test */ - public function it_denies_unauthorized(): void { + public function it_denies_unauthorized(): void + { $this->handleTest('user id'); $this->response->assertStatus(401); @@ -34,7 +36,8 @@ class DeleteUserApiTest extends AuthenticatesWithApplicationTestCase { * @test * @throws EntityNotFoundException */ - public function it_deletes_a_non_existent_user(): void { + public function it_deletes_a_non_existent_user(): void + { $this->authorize(); $this->handleTest('asdfasfd non existent user'); @@ -53,7 +56,8 @@ class DeleteUserApiTest extends AuthenticatesWithApplicationTestCase { * @test * @throws EntityNotFoundException */ - public function it_deletes_a_user(): void { + public function it_deletes_a_user(): void + { $this->authorize(); $user = new User(69, '', '', '', null, '', '', '', null, null, null); @@ -77,7 +81,8 @@ class DeleteUserApiTest extends AuthenticatesWithApplicationTestCase { * @test * @throws EntityNotFoundException */ - public function it_handles_a_failed_delete(): void { + public function it_handles_a_failed_delete(): void + { $this->authorize(); $this->stubUsersRepository(); diff --git a/src/web/backend/tests/Feature/Api/Users/GetAllUsersApiTest.php b/src/web/backend/tests/Feature/Api/Users/GetAllUsersApiTest.php index dde8a1866a472ececb0254c7bfa9ff5175bbd7a2..53bd1a8a30b4efa1d33009943783c992aa9e8a13 100644 --- a/src/web/backend/tests/Feature/Api/Users/GetAllUsersApiTest.php +++ b/src/web/backend/tests/Feature/Api/Users/GetAllUsersApiTest.php @@ -3,23 +3,25 @@ namespace Tests\Feature\Api\Users; - use Source\Entities\User; use Source\Exceptions\EntityNotFoundException; use Illuminate\Foundation\Testing\TestResponse; use Tests\Feature\AuthenticatesWithApplicationTestCase; -class GetAllUsersApiTest extends AuthenticatesWithApplicationTestCase { +class GetAllUsersApiTest extends AuthenticatesWithApplicationTestCase +{ protected TestResponse $response; - protected function handleTest(): void { + protected function handleTest(): void + { $this->response = $this->getJson('/users?api_token=' . $this->authToken); } /** * @test */ - public function it_denies_unauthorized(): void { + public function it_denies_unauthorized(): void + { $this->handleTest(); $this->response->assertStatus(401); @@ -29,7 +31,8 @@ class GetAllUsersApiTest extends AuthenticatesWithApplicationTestCase { * @test * @throws EntityNotFoundException */ - public function it_returns_empty_when_no_users_are_added(): void { + public function it_returns_empty_when_no_users_are_added(): void + { $this->authorize(); $this->handleTest(); @@ -46,7 +49,8 @@ class GetAllUsersApiTest extends AuthenticatesWithApplicationTestCase { * @test * @throws EntityNotFoundException */ - public function it_returns_users_in_the_repository(): void { + public function it_returns_users_in_the_repository(): void + { $this->authorize(); $user = new User(69, '', '', '', null, '', '', '', null, null, null); $this->usersRepository->create($user); diff --git a/src/web/backend/tests/Feature/Api/Users/GetUserApiTest.php b/src/web/backend/tests/Feature/Api/Users/GetUserApiTest.php index a775afed1bb458b35820fc936593ae8520b71068..86709cbeff9c11a81376639b1e2afc2c192d88c5 100644 --- a/src/web/backend/tests/Feature/Api/Users/GetUserApiTest.php +++ b/src/web/backend/tests/Feature/Api/Users/GetUserApiTest.php @@ -3,23 +3,25 @@ namespace Tests\Feature\Api\Users; - use Source\Entities\User; use Source\Exceptions\EntityNotFoundException; use Illuminate\Foundation\Testing\TestResponse; use Tests\Feature\AuthenticatesWithApplicationTestCase; -class GetUserApiTest extends AuthenticatesWithApplicationTestCase { +class GetUserApiTest extends AuthenticatesWithApplicationTestCase +{ protected TestResponse $response; - protected function handleTest(string $userId): void { + protected function handleTest(string $userId): void + { $this->response = $this->getJson('/users/' . $userId . '?api_token=' . $this->authToken); } /** * @test */ - public function it_denies_unauthorized(): void { + public function it_denies_unauthorized(): void + { $this->handleTest('asdf'); $this->response->assertStatus(401); @@ -29,7 +31,8 @@ class GetUserApiTest extends AuthenticatesWithApplicationTestCase { * @test * @throws EntityNotFoundException */ - public function it_returns_404_on_non_existent_user(): void { + public function it_returns_404_on_non_existent_user(): void + { $this->authorize(); $this->handleTest('asdfasdfasdfasd'); @@ -47,7 +50,8 @@ class GetUserApiTest extends AuthenticatesWithApplicationTestCase { * @test * @throws EntityNotFoundException */ - public function it_returns_a_user(): void { + public function it_returns_a_user(): void + { $this->authorize(); $user = new User(69, '', '', '', null, '', '', '', null, null, null); $this->usersRepository->create($user); diff --git a/src/web/backend/tests/Feature/Api/Users/UpdateUserApiTest.php b/src/web/backend/tests/Feature/Api/Users/UpdateUserApiTest.php index e1755513c265c98c17f023d7c8229fbaaaa02c15..c3f4012d7705c8d75e243dd01d1075e036ffb555 100644 --- a/src/web/backend/tests/Feature/Api/Users/UpdateUserApiTest.php +++ b/src/web/backend/tests/Feature/Api/Users/UpdateUserApiTest.php @@ -3,20 +3,21 @@ namespace Tests\Feature\Api\Users; - use Source\Entities\User; use Source\Exceptions\EntityNotFoundException; use Illuminate\Foundation\Testing\TestResponse; use Tests\Feature\AuthenticatesWithApplicationTestCase; -class UpdateUserApiTest extends AuthenticatesWithApplicationTestCase { +class UpdateUserApiTest extends AuthenticatesWithApplicationTestCase +{ protected TestResponse $response; /** * @param string $userId * @param array $data */ - protected function handleTest(string $userId, array $data): void { + protected function handleTest(string $userId, array $data): void + { $this->response = $this->putJson( '/users/' . $userId, array_merge(['api_token' => $this->authToken], $data) @@ -26,13 +27,15 @@ class UpdateUserApiTest extends AuthenticatesWithApplicationTestCase { /** * @test */ - public function it_denies_unauthorized(): void { + public function it_denies_unauthorized(): void + { $this->handleTest('radlfj', []); $this->response->assertStatus(401); } - public function invalidUserProvider(): array { + public function invalidUserProvider(): array + { $user = new User(0, 'first', 'last', 'display', null, 't@t.com', '', '43252643', null, null, null); return [ @@ -154,7 +157,8 @@ class UpdateUserApiTest extends AuthenticatesWithApplicationTestCase { * @dataProvider invalidUserProvider * @throws EntityNotFoundException */ - public function it_tests_the_validation_rules(array $data, array $message): void { + public function it_tests_the_validation_rules(array $data, array $message): void + { $this->authorize(); $this->handleTest('69', $data); $this->response->assertJsonFragment($message); @@ -164,7 +168,8 @@ class UpdateUserApiTest extends AuthenticatesWithApplicationTestCase { * @test * @throws EntityNotFoundException */ - public function it_updates_a_user(): void { + public function it_updates_a_user(): void + { $user = new User(69, '', '', '', null, '', '', '', null, null, null); $this->usersRepository->create($user); @@ -198,7 +203,8 @@ class UpdateUserApiTest extends AuthenticatesWithApplicationTestCase { * @test * @throws EntityNotFoundException */ - public function it_cannot_update_non_existient_user(): void { + public function it_cannot_update_non_existient_user(): void + { $this->authorize(); $this->handleTest( 'asdf', diff --git a/src/web/backend/tests/Feature/AuthenticatesWithApplicationTestCase.php b/src/web/backend/tests/Feature/AuthenticatesWithApplicationTestCase.php index 3ad0bdd68a5e7e18d06d6cbd56c790f461251601..141a67bae9dacb7ee2de4245755a24e9b201e4a9 100644 --- a/src/web/backend/tests/Feature/AuthenticatesWithApplicationTestCase.php +++ b/src/web/backend/tests/Feature/AuthenticatesWithApplicationTestCase.php @@ -3,7 +3,6 @@ namespace Tests\Feature; - use Tests\TestCase; use Source\Entities\User; use Source\Entities\Token; @@ -15,7 +14,8 @@ use Source\Gateways\Users\InMemoryUsersRepository; use Source\Gateways\Tokens\InMemoryTokensRepository; use Illuminate\Contracts\Container\BindingResolutionException; -class AuthenticatesWithApplicationTestCase extends TestCase { +class AuthenticatesWithApplicationTestCase extends TestCase +{ protected InMemoryUsersRepository $usersRepository; protected InMemoryTokensRepository $tokens; @@ -27,7 +27,8 @@ class AuthenticatesWithApplicationTestCase extends TestCase { /** * @throws BindingResolutionException */ - public function setUp(): void { + public function setUp(): void + { parent::setUp(); $this->usersRepository = $this->app->make(UsersRepository::class); $this->tokens = $this->app->make(TokensRepository::class); @@ -36,7 +37,8 @@ class AuthenticatesWithApplicationTestCase extends TestCase { /** * @throws EntityNotFoundException */ - protected function authorize(): void { + protected function authorize(): void + { $this->authUser = new User(1, '', '', '', '', '', '', '', null, null, null); $this->usersRepository->create($this->authUser); @@ -44,7 +46,8 @@ class AuthenticatesWithApplicationTestCase extends TestCase { $this->authToken = 'token'; } - protected function stubUsersRepository(): void { + protected function stubUsersRepository(): void + { $this->app->bind( UsersRepository::class, function ($app) { diff --git a/src/web/backend/tests/Unit/Source/UseCases/Users/CreateUser/PresenterStub.php b/src/web/backend/tests/Unit/Source/UseCases/Users/CreateUser/PresenterStub.php index d2ed2fefc6ff129ecf86e6778cebdaca5de3e99b..c3ac309bfcfa973c06772fefab8077079f4f5a44 100644 --- a/src/web/backend/tests/Unit/Source/UseCases/Users/CreateUser/PresenterStub.php +++ b/src/web/backend/tests/Unit/Source/UseCases/Users/CreateUser/PresenterStub.php @@ -3,26 +3,28 @@ namespace Tests\Unit\Source\UseCases\Users\CreateUser; - use Source\UseCases\Users\CreateUser\Presenter; use Source\UseCases\Users\CreateUser\ResponseModel; -class PresenterStub implements Presenter { - +class PresenterStub implements Presenter +{ public ResponseModel $response; protected bool $presenterCalled = false; - public function present(ResponseModel $responseModel): void { + public function present(ResponseModel $responseModel): void + { $this->presenterCalled = true; $this->response = $responseModel; } - public function wasPresenterCalled(): bool { + public function wasPresenterCalled(): bool + { return $this->presenterCalled; } - public function getViewModel(): array { + public function getViewModel(): array + { return []; } } diff --git a/src/web/backend/tests/Unit/Source/UseCases/Users/CreateUser/PresenterTest.php b/src/web/backend/tests/Unit/Source/UseCases/Users/CreateUser/PresenterTest.php index 7eb4c9ec9750cba0df9492dc1b4f4ef727909313..86f09852ca3f267ff2f914a8ed57645058e733a5 100644 --- a/src/web/backend/tests/Unit/Source/UseCases/Users/CreateUser/PresenterTest.php +++ b/src/web/backend/tests/Unit/Source/UseCases/Users/CreateUser/PresenterTest.php @@ -3,27 +3,29 @@ namespace Unit\Source\UseCases\Users\CreateUser; - use Carbon\Carbon; use Source\Entities\User; use PHPUnit\Framework\TestCase; -use Source\UseCases\Users\CreateUser\ResponseModel; use Source\UseCases\Users\CreateUser\APIPresenter; +use Source\UseCases\Users\CreateUser\ResponseModel; -class PresenterTest extends TestCase { +class PresenterTest extends TestCase +{ protected APIPresenter $presenter; protected ResponseModel $model; protected array $response; - public function setUp(): void { + public function setUp(): void + { parent::setUp(); $this->presenter = new APIPresenter(); } - public function handleTest(User $user): void { + public function handleTest(User $user): void + { $this->model = new ResponseModel($user); $this->presenter->present($this->model); @@ -32,7 +34,8 @@ class PresenterTest extends TestCase { } /** @test */ - public function it_formats_a_user(): void { + public function it_formats_a_user(): void + { $user = new User( 0, 'first', diff --git a/src/web/backend/tests/Unit/Source/UseCases/Users/CreateUser/UseCaseTest.php b/src/web/backend/tests/Unit/Source/UseCases/Users/CreateUser/UseCaseTest.php index 0451519d2a8bba5f82ac99e9da4868b64eee2244..3f44e9e86ce768ca0fe65bf72fbb53ec6b6355ca 100644 --- a/src/web/backend/tests/Unit/Source/UseCases/Users/CreateUser/UseCaseTest.php +++ b/src/web/backend/tests/Unit/Source/UseCases/Users/CreateUser/UseCaseTest.php @@ -3,7 +3,6 @@ namespace Tests\Unit\Source\UseCases\Users\CreateUser; - use Source\Entities\User; use PHPUnit\Framework\TestCase; use Source\Exceptions\EntityExistsException; @@ -11,7 +10,8 @@ use Source\UseCases\Users\CreateUser\CreateUser; use Source\Gateways\Users\InMemoryUsersRepository; use Source\UseCases\Users\CreateUser\ResponseModel; -class UseCaseTest extends TestCase { +class UseCaseTest extends TestCase +{ protected InMemoryUsersRepository $usersRepository; protected CreateUser $useCase; @@ -20,7 +20,8 @@ class UseCaseTest extends TestCase { protected PresenterStub $presenter; - public function setUp(): void { + public function setUp(): void + { parent::setUp(); $this->usersRepository = new InMemoryUsersRepository(); @@ -28,7 +29,8 @@ class UseCaseTest extends TestCase { $this->presenter = new PresenterStub(); } - protected function createUserAttributes(User $user): array { + protected function createUserAttributes(User $user): array + { $expires = $user->getExpiresAt(); if ($expires) { $expires = $expires->toString(); @@ -50,7 +52,8 @@ class UseCaseTest extends TestCase { * @param array $attributes * @throws EntityExistsException */ - public function handleTest(array $attributes): void { + public function handleTest(array $attributes): void + { $this->useCase->create($attributes, $this->presenter); $this->response = $this->presenter->response; @@ -60,7 +63,8 @@ class UseCaseTest extends TestCase { * @test * @throws EntityExistsException */ - public function presenter_was_called(): void { + public function presenter_was_called(): void + { $user = new User(0, 'special name', '', '', null, '', '', '', null, null, null); $this->handleTest($this->createUserAttributes($user)); @@ -72,7 +76,8 @@ class UseCaseTest extends TestCase { * @test * @throws EntityExistsException */ - public function it_creates_a_user(): void { + public function it_creates_a_user(): void + { $user = new User(0, 'special name', '', '', null, '', '', '', null, null, null); $this->handleTest($this->createUserAttributes($user)); diff --git a/src/web/backend/tests/Unit/Source/UseCases/Users/DeleteUser/PresenterStub.php b/src/web/backend/tests/Unit/Source/UseCases/Users/DeleteUser/PresenterStub.php index 7170b16074b783fb3c9ad0288f453e2cb909c59a..9e10d10001f428f10254061245bf71d04a44d7be 100644 --- a/src/web/backend/tests/Unit/Source/UseCases/Users/DeleteUser/PresenterStub.php +++ b/src/web/backend/tests/Unit/Source/UseCases/Users/DeleteUser/PresenterStub.php @@ -3,26 +3,28 @@ namespace Tests\Unit\Source\UseCases\Users\DeleteUser; - use Source\UseCases\Users\DeleteUser\Presenter; use Source\UseCases\Users\DeleteUser\ResponseModel; -class PresenterStub implements Presenter { - +class PresenterStub implements Presenter +{ public ResponseModel $response; protected bool $presenterCalled = false; - public function present(ResponseModel $responseModel): void { + public function present(ResponseModel $responseModel): void + { $this->presenterCalled = true; $this->response = $responseModel; } - public function wasPresenterCalled(): bool { + public function wasPresenterCalled(): bool + { return $this->presenterCalled; } - public function getViewModel(): array { + public function getViewModel(): array + { return []; } } diff --git a/src/web/backend/tests/Unit/Source/UseCases/Users/DeleteUser/PresenterTest.php b/src/web/backend/tests/Unit/Source/UseCases/Users/DeleteUser/PresenterTest.php index 9d9c860fb2a362ac788b91891e53c15bc7f5727f..7af62b821cbf21f93b91110d913dd37e6e354b4b 100644 --- a/src/web/backend/tests/Unit/Source/UseCases/Users/DeleteUser/PresenterTest.php +++ b/src/web/backend/tests/Unit/Source/UseCases/Users/DeleteUser/PresenterTest.php @@ -3,27 +3,27 @@ namespace Unit\Source\UseCases\Users\DeleteUser; - -use Carbon\Carbon; -use Source\Entities\User; use PHPUnit\Framework\TestCase; -use Source\UseCases\Users\DeleteUser\ResponseModel; use Source\UseCases\Users\DeleteUser\APIPresenter; +use Source\UseCases\Users\DeleteUser\ResponseModel; -class PresenterTest extends TestCase { +class PresenterTest extends TestCase +{ protected APIPresenter $presenter; protected ResponseModel $model; protected array $response; - public function setUp(): void { + public function setUp(): void + { parent::setUp(); $this->presenter = new APIPresenter(); } - public function handleTest(string $message): void { + public function handleTest(string $message): void + { $this->model = new ResponseModel($message); $this->presenter->present($this->model); @@ -32,7 +32,8 @@ class PresenterTest extends TestCase { } /** @test */ - public function it_formats_a_message(): void { + public function it_formats_a_message(): void + { $this->handleTest('hello'); $this->assertEquals(['message' => 'hello'], $this->response); diff --git a/src/web/backend/tests/Unit/Source/UseCases/Users/DeleteUser/UseCaseTest.php b/src/web/backend/tests/Unit/Source/UseCases/Users/DeleteUser/UseCaseTest.php index bb258de3a84c279c077ba16e147f6b9d87992302..39dea2e7428e08713584872323fa16f5e6a0e75f 100644 --- a/src/web/backend/tests/Unit/Source/UseCases/Users/DeleteUser/UseCaseTest.php +++ b/src/web/backend/tests/Unit/Source/UseCases/Users/DeleteUser/UseCaseTest.php @@ -3,7 +3,6 @@ namespace Tests\Unit\Source\UseCases\Users\DeleteUser; - use Source\Entities\User; use PHPUnit\Framework\TestCase; use Source\UseCases\Users\DeleteUser\DeleteUser; @@ -11,7 +10,8 @@ use Source\Gateways\Users\InMemoryUsersRepository; use Source\UseCases\Users\DeleteUser\ResponseModel; use Source\UseCases\Users\DeleteUser\DeleteFailedException; -class UseCaseTest extends TestCase { +class UseCaseTest extends TestCase +{ protected InMemoryUsersRepository $usersRepository; protected DeleteUser $useCase; @@ -20,7 +20,8 @@ class UseCaseTest extends TestCase { protected PresenterStub $presenter; - public function setUp(): void { + public function setUp(): void + { parent::setUp(); $this->usersRepository = new InMemoryUsersRepository(); @@ -32,7 +33,8 @@ class UseCaseTest extends TestCase { * @param string $userId * @throws DeleteFailedException */ - public function handleTest(string $userId): void { + public function handleTest(string $userId): void + { $this->useCase->delete($userId, $this->presenter); $this->response = $this->presenter->response; @@ -42,7 +44,8 @@ class UseCaseTest extends TestCase { * @test * @throws DeleteFailedException */ - public function presenter_was_called(): void { + public function presenter_was_called(): void + { $this->handleTest('123'); $this->assertTrue($this->presenter->wasPresenterCalled()); @@ -52,7 +55,8 @@ class UseCaseTest extends TestCase { * @test * @throws DeleteFailedException */ - public function it_deletes_a_user(): void { + public function it_deletes_a_user(): void + { $user1 = new User(420, '', '', '', null, '', '', '', null, null, null); $user2 = new User(69, '', '', '', null, '', '', '', null, null, null); $this->usersRepository->create($user1); diff --git a/src/web/backend/tests/Unit/Source/UseCases/Users/GetAllUsers/PresenterStub.php b/src/web/backend/tests/Unit/Source/UseCases/Users/GetAllUsers/PresenterStub.php index d228cdb8f85941ed88202948f5786cdb09ea1fdf..8e7a933348526552f85980e616aae7a9c8fbe151 100644 --- a/src/web/backend/tests/Unit/Source/UseCases/Users/GetAllUsers/PresenterStub.php +++ b/src/web/backend/tests/Unit/Source/UseCases/Users/GetAllUsers/PresenterStub.php @@ -3,26 +3,28 @@ namespace Tests\Unit\Source\UseCases\Users\GetAllUsers; - use Source\UseCases\Users\GetAllUsers\Presenter; use Source\UseCases\Users\GetAllUsers\ResponseModel; -class PresenterStub implements Presenter { - +class PresenterStub implements Presenter +{ public ResponseModel $response; protected bool $presenterCalled = false; - public function present(ResponseModel $responseModel): void { + public function present(ResponseModel $responseModel): void + { $this->presenterCalled = true; $this->response = $responseModel; } - public function wasPresenterCalled(): bool { + public function wasPresenterCalled(): bool + { return $this->presenterCalled; } - public function getViewModel(): array { + public function getViewModel(): array + { return []; } } diff --git a/src/web/backend/tests/Unit/Source/UseCases/Users/GetAllUsers/PresenterTest.php b/src/web/backend/tests/Unit/Source/UseCases/Users/GetAllUsers/PresenterTest.php index 10c02d193b659d6632140fe721a2f413f27169cb..a70f585955545da47ddad454550707a5e0e6ace7 100644 --- a/src/web/backend/tests/Unit/Source/UseCases/Users/GetAllUsers/PresenterTest.php +++ b/src/web/backend/tests/Unit/Source/UseCases/Users/GetAllUsers/PresenterTest.php @@ -3,36 +3,38 @@ namespace Tests\Unit\Source\UseCases\Users\GetAllUsers; - use Carbon\Carbon; use Source\Entities\User; use PHPUnit\Framework\TestCase; use Source\UseCases\Users\GetAllUsers\APIPresenter; use Source\UseCases\Users\GetAllUsers\ResponseModel; -class PresenterTest extends TestCase { - +class PresenterTest extends TestCase +{ protected APIPresenter $presenter; protected ResponseModel $model; protected array $response; - public function setUp(): void { + public function setUp(): void + { parent::setUp(); $this->model = new ResponseModel(); $this->presenter = new APIPresenter(); } - public function handleTest(): void { + public function handleTest(): void + { $this->presenter->present($this->model); $this->response = $this->presenter->getViewModel(); } /** @test */ - public function it_formats_no_users(): void { + public function it_formats_no_users(): void + { $this->handleTest(); $this->assertEquals( @@ -44,7 +46,8 @@ class PresenterTest extends TestCase { } /** @test */ - public function it_formats_a_user(): void { + public function it_formats_a_user(): void + { $this->model->addUser( new User( 0, diff --git a/src/web/backend/tests/Unit/Source/UseCases/Users/GetAllUsers/UseCaseTest.php b/src/web/backend/tests/Unit/Source/UseCases/Users/GetAllUsers/UseCaseTest.php index c0a2227c337e5a9bed54e7f7327860408096aea5..1f1d7fa95215562e8a2b8898faccc478fb2fba3e 100644 --- a/src/web/backend/tests/Unit/Source/UseCases/Users/GetAllUsers/UseCaseTest.php +++ b/src/web/backend/tests/Unit/Source/UseCases/Users/GetAllUsers/UseCaseTest.php @@ -3,14 +3,14 @@ namespace Tests\Unit\Source\UseCases\Users\GetAllUsers; - use Source\Entities\User; use PHPUnit\Framework\TestCase; -use Source\UseCases\Users\GetAllUsers\GetAllUsers; use Source\Gateways\Users\InMemoryUsersRepository; +use Source\UseCases\Users\GetAllUsers\GetAllUsers; use Source\UseCases\Users\GetAllUsers\ResponseModel; -class UseCaseTest extends TestCase { +class UseCaseTest extends TestCase +{ /** * @var InMemoryUsersRepository */ @@ -28,7 +28,8 @@ class UseCaseTest extends TestCase { protected PresenterStub $presenter; - public function setUp(): void { + public function setUp(): void + { parent::setUp(); $this->usersRepository = new InMemoryUsersRepository(); @@ -36,30 +37,34 @@ class UseCaseTest extends TestCase { $this->presenter = new PresenterStub(); } - public function handleTest(): void { + public function handleTest(): void + { $this->useCase->all($this->presenter); $this->response = $this->presenter->response; } /** @test */ - public function presenter_was_called(): void { + public function presenter_was_called(): void + { $this->handleTest(); $this->assertTrue($this->presenter->wasPresenterCalled()); } /** @test */ - public function it_works_when_no_users_are_added(): void { + public function it_works_when_no_users_are_added(): void + { $this->handleTest(); $this->assertEquals([], $this->response->getUsers()); } /** @test */ - public function it_sees_users(): void { - $this->usersRepository->create(new User(0, '', '', '', '', '','', '', null, null, null)); - $this->usersRepository->create(new User(0, '', '', '', '', '','', '', null, null, null)); + public function it_sees_users(): void + { + $this->usersRepository->create(new User(0, '', '', '', '', '', '', '', null, null, null)); + $this->usersRepository->create(new User(0, '', '', '', '', '', '', '', null, null, null)); $this->handleTest(); diff --git a/src/web/backend/tests/Unit/Source/UseCases/Users/GetUser/PresenterStub.php b/src/web/backend/tests/Unit/Source/UseCases/Users/GetUser/PresenterStub.php index 576a3a1d0eddcb9d1053f25aa78d6b1a4e91c5e2..81f7b4b200f1132ba1ec5b7252e37de9568c72e4 100644 --- a/src/web/backend/tests/Unit/Source/UseCases/Users/GetUser/PresenterStub.php +++ b/src/web/backend/tests/Unit/Source/UseCases/Users/GetUser/PresenterStub.php @@ -3,26 +3,28 @@ namespace Tests\Unit\Source\UseCases\Users\GetUser; - use Source\UseCases\Users\GetUser\Presenter; use Source\UseCases\Users\GetUser\ResponseModel; -class PresenterStub implements Presenter { - +class PresenterStub implements Presenter +{ public ResponseModel $response; protected bool $presenterCalled = false; - public function present(ResponseModel $responseModel): void { + public function present(ResponseModel $responseModel): void + { $this->presenterCalled = true; $this->response = $responseModel; } - public function wasPresenterCalled(): bool { + public function wasPresenterCalled(): bool + { return $this->presenterCalled; } - public function getViewModel(): array { + public function getViewModel(): array + { return []; } } diff --git a/src/web/backend/tests/Unit/Source/UseCases/Users/GetUser/PresenterTest.php b/src/web/backend/tests/Unit/Source/UseCases/Users/GetUser/PresenterTest.php index e7d98b305779f26e6359556e9035a7dfa18f639e..fcfd1e72636ed3c3529f02e55e97adcc9f988ad0 100644 --- a/src/web/backend/tests/Unit/Source/UseCases/Users/GetUser/PresenterTest.php +++ b/src/web/backend/tests/Unit/Source/UseCases/Users/GetUser/PresenterTest.php @@ -3,28 +3,29 @@ namespace Unit\Source\UseCases\Users\GetUser; - use Carbon\Carbon; use Source\Entities\User; use PHPUnit\Framework\TestCase; use Source\UseCases\Users\GetUser\APIPresenter; use Source\UseCases\Users\GetUser\ResponseModel; -class PresenterTest extends TestCase { - +class PresenterTest extends TestCase +{ protected APIPresenter $presenter; protected ResponseModel $model; protected array $response; - public function setUp(): void { + public function setUp(): void + { parent::setUp(); $this->presenter = new APIPresenter(); } - public function handleTest(User $user): void { + public function handleTest(User $user): void + { $this->model = new ResponseModel($user); $this->presenter->present($this->model); @@ -33,7 +34,8 @@ class PresenterTest extends TestCase { } /** @test */ - public function it_formats_a_user(): void { + public function it_formats_a_user(): void + { $user = new User( 0, 'first', diff --git a/src/web/backend/tests/Unit/Source/UseCases/Users/GetUser/UseCaseTest.php b/src/web/backend/tests/Unit/Source/UseCases/Users/GetUser/UseCaseTest.php index 2fa341b8a3c365f808a842ccd24895852e3415dd..56c998e4550944d15f00128b5bdbf38875ba80da 100644 --- a/src/web/backend/tests/Unit/Source/UseCases/Users/GetUser/UseCaseTest.php +++ b/src/web/backend/tests/Unit/Source/UseCases/Users/GetUser/UseCaseTest.php @@ -3,7 +3,6 @@ namespace Tests\Unit\Source\UseCases\Users\GetUser; - use Source\Entities\User; use PHPUnit\Framework\TestCase; use Source\UseCases\Users\GetUser\GetUser; @@ -11,8 +10,8 @@ use Source\Exceptions\EntityNotFoundException; use Source\UseCases\Users\GetUser\ResponseModel; use Source\Gateways\Users\InMemoryUsersRepository; -class UseCaseTest extends TestCase { - +class UseCaseTest extends TestCase +{ protected InMemoryUsersRepository $usersRepository; protected GetUser $useCase; @@ -21,7 +20,8 @@ class UseCaseTest extends TestCase { protected PresenterStub $presenter; - public function setUp(): void { + public function setUp(): void + { parent::setUp(); $this->usersRepository = new InMemoryUsersRepository(); @@ -33,7 +33,8 @@ class UseCaseTest extends TestCase { * @param string $userId * @throws EntityNotFoundException */ - public function handleTest(string $userId): void { + public function handleTest(string $userId): void + { $this->useCase->get($userId, $this->presenter); $this->response = $this->presenter->response; @@ -44,8 +45,9 @@ class UseCaseTest extends TestCase { * @test * @throws EntityNotFoundException */ - public function presenter_was_called(): void { - $this->usersRepository->create(new User(1, '', '', '', '', '','', '', null, null, null)); + public function presenter_was_called(): void + { + $this->usersRepository->create(new User(1, '', '', '', '', '', '', '', null, null, null)); $this->handleTest('1'); @@ -57,8 +59,9 @@ class UseCaseTest extends TestCase { * @test * @throws EntityNotFoundException */ - public function it_throws_an_exception_when_a_user_does_not_exist(): void { - $this->usersRepository->create(new User(0, '', '', '', '', '','', '', null, null, null)); + public function it_throws_an_exception_when_a_user_does_not_exist(): void + { + $this->usersRepository->create(new User(0, '', '', '', '', '', '', '', null, null, null)); $this->expectException(EntityNotFoundException::class); @@ -69,8 +72,9 @@ class UseCaseTest extends TestCase { * @test * @throws EntityNotFoundException */ - public function it_gets_a_user(): void { - $user = new User(15, '', '', '', '', '','', '', null, null, null); + public function it_gets_a_user(): void + { + $user = new User(15, '', '', '', '', '', '', '', null, null, null); $this->usersRepository->create($user); $this->handleTest('15'); diff --git a/src/web/backend/tests/Unit/Source/UseCases/Users/UpdateUser/PresenterStub.php b/src/web/backend/tests/Unit/Source/UseCases/Users/UpdateUser/PresenterStub.php index bf1822a44baab331829ac813c585afc71da21cda..471b48fb00d9d9a9b4b3a85ee472d981068b4ac4 100644 --- a/src/web/backend/tests/Unit/Source/UseCases/Users/UpdateUser/PresenterStub.php +++ b/src/web/backend/tests/Unit/Source/UseCases/Users/UpdateUser/PresenterStub.php @@ -3,26 +3,28 @@ namespace Tests\Unit\Source\UseCases\Users\UpdateUser; - use Source\UseCases\Users\UpdateUser\Presenter; use Source\UseCases\Users\UpdateUser\ResponseModel; -class PresenterStub implements Presenter { - +class PresenterStub implements Presenter +{ public ResponseModel $response; protected bool $presenterCalled = false; - public function present(ResponseModel $responseModel): void { + public function present(ResponseModel $responseModel): void + { $this->presenterCalled = true; $this->response = $responseModel; } - public function wasPresenterCalled(): bool { + public function wasPresenterCalled(): bool + { return $this->presenterCalled; } - public function getViewModel(): array { + public function getViewModel(): array + { return []; } } diff --git a/src/web/backend/tests/Unit/Source/UseCases/Users/UpdateUser/PresenterTest.php b/src/web/backend/tests/Unit/Source/UseCases/Users/UpdateUser/PresenterTest.php index 3fa71655fa6e06033f3171ff2282f967ed06e942..be62043af5b6e972d6e652ed0b499f9563f1e583 100644 --- a/src/web/backend/tests/Unit/Source/UseCases/Users/UpdateUser/PresenterTest.php +++ b/src/web/backend/tests/Unit/Source/UseCases/Users/UpdateUser/PresenterTest.php @@ -3,35 +3,38 @@ namespace Unit\Source\UseCases\Users\UpdateUser; - use Carbon\Carbon; use Source\Entities\User; use PHPUnit\Framework\TestCase; use Source\UseCases\Users\UpdateUser\APIPresenter; use Source\UseCases\Users\UpdateUser\ResponseModel; -class PresenterTest extends TestCase { +class PresenterTest extends TestCase +{ protected APIPresenter $presenter; protected ResponseModel $model; protected array $response; - public function setUp(): void { + public function setUp(): void + { parent::setUp(); $this->presenter = new APIPresenter(); $this->model = new ResponseModel(); } - public function handleTest(): void { + public function handleTest(): void + { $this->presenter->present($this->model); $this->response = $this->presenter->getViewModel(); } /** @test */ - public function it_formats_a_user(): void { + public function it_formats_a_user(): void + { $user = new User( 0, 'first', @@ -70,7 +73,8 @@ class PresenterTest extends TestCase { } /** @test */ - public function it_formats_an_error(): void { + public function it_formats_an_error(): void + { $this->model->setError('error'); $this->handleTest(); diff --git a/src/web/backend/tests/Unit/Source/UseCases/Users/UpdateUser/UseCaseTest.php b/src/web/backend/tests/Unit/Source/UseCases/Users/UpdateUser/UseCaseTest.php index 51663c6c849d277b7a20d80c9b4e816d2426542b..f08e9f6d798ae6fa707182b1256c5e0bfa993d89 100644 --- a/src/web/backend/tests/Unit/Source/UseCases/Users/UpdateUser/UseCaseTest.php +++ b/src/web/backend/tests/Unit/Source/UseCases/Users/UpdateUser/UseCaseTest.php @@ -3,7 +3,6 @@ namespace Tests\Unit\Source\UseCases\Users\UpdateUser; - use Source\Entities\User; use PHPUnit\Framework\TestCase; use Source\Exceptions\EntityNotFoundException; @@ -12,7 +11,8 @@ use Source\UseCases\Users\UpdateUser\UpdateUser; use Source\Gateways\Users\InMemoryUsersRepository; use Source\UseCases\Users\UpdateUser\ResponseModel; -class UseCaseTest extends TestCase { +class UseCaseTest extends TestCase +{ protected InMemoryUsersRepository $usersRepository; protected UpdateUser $useCase; @@ -21,7 +21,8 @@ class UseCaseTest extends TestCase { protected PresenterStub $presenter; - public function setUp(): void { + public function setUp(): void + { parent::setUp(); $this->usersRepository = new InMemoryUsersRepository(); @@ -29,7 +30,8 @@ class UseCaseTest extends TestCase { $this->presenter = new PresenterStub(); } - protected function createUserAttributes(User $user, $password = null, $doorcode = null): array { + protected function createUserAttributes(User $user, $password = null, $doorcode = null): array + { $expires = $user->getExpiresAt(); if ($expires) { $expires = $expires->toString(); @@ -52,7 +54,8 @@ class UseCaseTest extends TestCase { * @param array $attributes * @throws EntityNotFoundException */ - public function handleTest(string $userId, array $attributes): void { + public function handleTest(string $userId, array $attributes): void + { $this->useCase->update($userId, $attributes, $this->presenter); $this->response = $this->presenter->response; @@ -62,7 +65,8 @@ class UseCaseTest extends TestCase { * @test * @throws EntityNotFoundException */ - public function presenter_was_called(): void { + public function presenter_was_called(): void + { $user = new User(69, 'special name', '', '', null, '', '', '', null, null, null); $this->usersRepository->create($user); @@ -75,7 +79,8 @@ class UseCaseTest extends TestCase { * @test * @throws EntityNotFoundException */ - public function it_updates_a_user(): void { + public function it_updates_a_user(): void + { $user = new User(69, 'camdiddle beerbong', '', '', null, '', '', '', null, null, null); $updatedUser = new User(69, 'updated name', '', '', null, '', '', '', null, null, null); $this->usersRepository->create($user); @@ -91,7 +96,8 @@ class UseCaseTest extends TestCase { * @test * @throws EntityNotFoundException */ - public function it_cannot_update_non_existent_user(): void { + public function it_cannot_update_non_existent_user(): void + { $this->expectException(EntityNotFoundException::class); $updatedUser = new User(69, 'updated name', '', '', null, '', '', '', null, null, null); @@ -102,7 +108,8 @@ class UseCaseTest extends TestCase { * @test * @throws EntityNotFoundException */ - public function it_sets_error_on_fail(): void { + public function it_sets_error_on_fail(): void + { $updatedUser = new User(420, 'updated name', '', '', null, '', '', '', null, null, null); $stub = new InMemoryUsersRepositoryStub(); @@ -119,7 +126,8 @@ class UseCaseTest extends TestCase { * @test * @throws EntityNotFoundException */ - public function it_doesnt_need_doorcode_or_password(): void { + public function it_doesnt_need_doorcode_or_password(): void + { $user = new User(69, '', '', '', null, '', 'pass', 'door', null, null, null); $updatedUser = new User(0, '', '', '', null, '', '', '', null, null, null); @@ -135,7 +143,8 @@ class UseCaseTest extends TestCase { * @test * @throws EntityNotFoundException */ - public function it_will_overwrite_pass_and_door_code(): void { + public function it_will_overwrite_pass_and_door_code(): void + { $user = new User(69, '', '', '', null, '', '', '', null, null, null); $updatedUser = new User(0, '', '', '', null, '', '', '', null, null, null);