diff --git a/bin/clear-config-cache.php b/bin/clear-config-cache.php index 29d94851..b1c27cab 100644 --- a/bin/clear-config-cache.php +++ b/bin/clear-config-cache.php @@ -1,11 +1,5 @@ [], 'dot_authorization' => [ diff --git a/config/autoload/dependencies.global.php b/config/autoload/dependencies.global.php index 2777182e..24aec5b6 100644 --- a/config/autoload/dependencies.global.php +++ b/config/autoload/dependencies.global.php @@ -2,11 +2,13 @@ declare(strict_types=1); +use Dot\Authorization\AuthorizationInterface; use Dot\Mail\Factory\MailOptionsAbstractFactory; use Dot\Mail\Factory\MailServiceAbstractFactory; use Dot\Mail\Service\MailService; use Dot\ErrorHandler\ErrorHandlerInterface; use Dot\ErrorHandler\LogErrorHandler; +use Dot\Rbac\Authorization\AuthorizationService; use Frontend\App\Middleware\AuthMiddleware; use Frontend\App\Factory\AuthMiddlewareFactory; @@ -19,7 +21,7 @@ // key is the alias name, the value is the service to which it points. 'aliases' => [ ErrorHandlerInterface::class => LogErrorHandler::class, - \Dot\Authorization\AuthorizationInterface::class => \Dot\Rbac\Authorization\AuthorizationService::class, + AuthorizationInterface::class => AuthorizationService::class, MailService::class => 'dot-mail.service.default', ], // Use 'invokables' for constructor-less services, or services that do diff --git a/config/autoload/doctrine.global.php b/config/autoload/doctrine.global.php index e33a6035..031339e4 100644 --- a/config/autoload/doctrine.global.php +++ b/config/autoload/doctrine.global.php @@ -1,5 +1,8 @@ [ 'orm_default' => [ 'entity_listener_resolver' => EntityListenerResolver::class, - 'query_cache' => \Doctrine\Common\Cache\PhpFileCache::class, - 'metadata_cache' => \Doctrine\Common\Cache\PhpFileCache::class, - 'result_cache' => \Doctrine\Common\Cache\PhpFileCache::class + 'query_cache' => PhpFileCache::class, + 'metadata_cache' => PhpFileCache::class, + 'result_cache' => PhpFileCache::class ] ], 'connection' => [ @@ -52,8 +55,8 @@ UuidBinaryOrderedTimeType::NAME => UuidBinaryOrderedTimeType::class, ], 'cache' => [ - \Doctrine\Common\Cache\PhpFileCache::class => [ - 'class' => \Doctrine\Common\Cache\PhpFileCache::class, + PhpFileCache::class => [ + 'class' => PhpFileCache::class, 'directory' => getcwd() . '/data/cache/doctrine' ] ], diff --git a/config/autoload/error-handling.global.php b/config/autoload/error-handling.global.php index c94b68be..eea16448 100644 --- a/config/autoload/error-handling.global.php +++ b/config/autoload/error-handling.global.php @@ -1,5 +1,7 @@ [ 'options' => [ diff --git a/config/autoload/slug.global.php.dist b/config/autoload/slug.global.php.dist index 4a5ba264..e36afe9b 100644 --- a/config/autoload/slug.global.php.dist +++ b/config/autoload/slug.global.php.dist @@ -1,5 +1,7 @@ [ 'table_name' => 'migrations', diff --git a/config/pipeline.php b/config/pipeline.php index 3318f663..9fc5e302 100644 --- a/config/pipeline.php +++ b/config/pipeline.php @@ -28,7 +28,7 @@ /** * Setup middleware pipeline: */ -return function (Application $app, MiddlewareFactory $factory, ContainerInterface $container) : void { +return function (Application $app, MiddlewareFactory $factory, ContainerInterface $container): void { // The error handler should be the first (most outer) middleware to catch // all Exceptions. $app->pipe(DebugBarMiddleware::class); diff --git a/config/routes.php b/config/routes.php index 88f2508f..406bcdcf 100644 --- a/config/routes.php +++ b/config/routes.php @@ -6,5 +6,5 @@ use Mezzio\MiddlewareFactory; use Psr\Container\ContainerInterface; -return function (Application $app, MiddlewareFactory $factory, ContainerInterface $container) : void { +return function (Application $app, MiddlewareFactory $factory, ContainerInterface $container): void { }; diff --git a/public/debugbar/dotkernel.css b/public/debugbar/dotkernel.css index 25672324..ca79a5b1 100644 --- a/public/debugbar/dotkernel.css +++ b/public/debugbar/dotkernel.css @@ -1,46 +1,50 @@ -.phpdebugbar-header { - background-color: #C60B31 !important; -} - -.phpdebugbar-tab, .phpdebugbar-indicator { - color: #FFFFFF !important; -} - -.phpdebugbar-badge { - vertical-align: baseline !important; -} - -.phpdebugbar-active { - color: #000000 !important; -} - -.phpdebugbar-panel { - background-color: #F8F8F8 !important; -} - -.phpdebugbar-widgets-kvlist { - font-size: .75rem !important; -} - -.phpdebugbar-widgets-key { - text-align: right !important; -} - -.phpdebugbar-widgets-value { - border-left: 1px solid #DDDDDD !important; - background-color: #FFFFFF !important; -} - -.phpdebugbar-widgets-list-item { - background-color: #FFFFFF !important; - padding: .75rem .5rem !important; -} - -.phpdebugbar-widgets-params tr > td:nth-child(1) { - background-color: #F8F8F8 !important; - text-align: right !important; -} - -.phpdebugbar-widgets-params tr > td:nth-child(2) { - background-color: #FFFFFF !important; -} +.phpdebugbar-header { + background-color: #C60B31 !important; +} + +.phpdebugbar-tab, .phpdebugbar-indicator { + color: #FFFFFF !important; +} + +.phpdebugbar-badge { + vertical-align: baseline !important; +} + +.phpdebugbar-active { + color: #000000 !important; +} + +.phpdebugbar-panel { + background-color: #F8F8F8 !important; +} + +.phpdebugbar-widgets-kvlist { + font-size: .75rem !important; +} + +.phpdebugbar-widgets-sql { + font-size: .75rem !important; +} + +.phpdebugbar-widgets-key { + text-align: right !important; +} + +.phpdebugbar-widgets-value { + border-left: 1px solid #DDDDDD !important; + background-color: #FFFFFF !important; +} + +.phpdebugbar-widgets-list-item { + background-color: #FFFFFF !important; + padding: .75rem .5rem !important; +} + +.phpdebugbar-widgets-params tr > td:nth-child(1) { + background-color: #F8F8F8 !important; + text-align: right !important; +} + +.phpdebugbar-widgets-params tr > td:nth-child(2) { + background-color: #FFFFFF !important; +} diff --git a/public/index.php b/public/index.php index f5ec42a1..f80467dd 100644 --- a/public/index.php +++ b/public/index.php @@ -2,6 +2,10 @@ declare(strict_types=1); +use Mezzio\Application; +use Mezzio\MiddlewareFactory; +use Psr\Container\ContainerInterface; + // Delegate static file requests back to the PHP built-in webserver if (PHP_SAPI === 'cli-server' && $_SERVER['SCRIPT_FILENAME'] !== __FILE__) { return false; @@ -14,12 +18,12 @@ * Self-called anonymous function that creates its own scope and keep the global namespace clean. */ (function () { - /** @var \Psr\Container\ContainerInterface $container */ + /** @var ContainerInterface $container */ $container = require 'config/container.php'; - /** @var \Mezzio\Application $app */ - $app = $container->get(\Mezzio\Application::class); - $factory = $container->get(\Mezzio\MiddlewareFactory::class); + /** @var Application $app */ + $app = $container->get(Application::class); + $factory = $container->get(MiddlewareFactory::class); // Execute programmatic/declarative middleware pipeline and routing // configuration statements diff --git a/src/App/src/Common/AbstractEntity.php b/src/App/src/Common/AbstractEntity.php index bfd02885..93b608d1 100644 --- a/src/App/src/Common/AbstractEntity.php +++ b/src/App/src/Common/AbstractEntity.php @@ -8,7 +8,7 @@ /** * Class AbstractEntity - * @package Core\Common + * @package Frontend\App\Common */ abstract class AbstractEntity implements UuidAwareInterface, TimestampAwareInterface { @@ -31,7 +31,7 @@ public function __construct() * @param array $data * @return void */ - public function exchangeArray(array $data) + public function exchangeArray(array $data): void { foreach ($data as $property => $values) { if (is_array($values)) { diff --git a/src/App/src/Common/Pagination.php b/src/App/src/Common/Pagination.php index 7b2843f2..b002f2fa 100644 --- a/src/App/src/Common/Pagination.php +++ b/src/App/src/Common/Pagination.php @@ -4,8 +4,6 @@ namespace Frontend\App\Common; -use function array_key_exists; - /** * Class Pagination * @package Frontend\App\Common @@ -18,7 +16,7 @@ class Pagination * @param array $filters * @return array */ - public static function getOffsetAndLimit(array $filters = []) + public static function getOffsetAndLimit(array $filters = []): array { $page = (int)($filters['page'] ?? 1); diff --git a/src/App/src/Common/TimestampAwareTrait.php b/src/App/src/Common/TimestampAwareTrait.php index 867ce9da..3aa9eedd 100644 --- a/src/App/src/Common/TimestampAwareTrait.php +++ b/src/App/src/Common/TimestampAwareTrait.php @@ -14,22 +14,17 @@ */ trait TimestampAwareTrait { - /** - * @var string $dateFormat - */ - private $dateFormat = 'Y-m-d H:i:s'; + private string $dateFormat = 'Y-m-d H:i:s'; /** * @ORM\Column(name="created", type="datetime_immutable") - * @var DateTimeImmutable */ - protected $created; + protected DateTimeImmutable $created; /** * @ORM\Column(name="updated", type="datetime_immutable", nullable=true) - * @var DateTimeImmutable */ - protected $updated; + protected ?DateTimeImmutable $updated = null; /** * @ORM\PrePersist() @@ -42,9 +37,9 @@ public function updateTimestamps(): void } /** - * @return DateTimeImmutable|null + * @return DateTimeImmutable */ - public function getCreated(): ?DateTimeImmutable + public function getCreated(): DateTimeImmutable { return $this->created; } @@ -54,11 +49,7 @@ public function getCreated(): ?DateTimeImmutable */ public function getCreatedFormatted(): ?string { - if ($this->created instanceof DateTimeImmutable) { - return $this->created->format($this->dateFormat); - } - - return null; + return $this->created->format($this->dateFormat); } /** @@ -74,11 +65,7 @@ public function getUpdated(): ?DateTimeImmutable */ public function getUpdatedFormatted(): ?string { - if ($this->updated instanceof DateTimeImmutable) { - return $this->updated->format($this->dateFormat); - } - - return null; + return $this->updated?->format($this->dateFormat); } /** @@ -95,10 +82,6 @@ public function setDateFormat(string $dateFormat): void public function touch(): void { try { - if (!($this->created instanceof DateTimeImmutable)) { - $this->created = new DateTimeImmutable(); - } - $this->updated = new DateTimeImmutable(); } catch (Exception $exception) { #TODO save the error message diff --git a/src/App/src/Common/UuidAwareInterface.php b/src/App/src/Common/UuidAwareInterface.php index c432230a..498fe6e7 100644 --- a/src/App/src/Common/UuidAwareInterface.php +++ b/src/App/src/Common/UuidAwareInterface.php @@ -13,7 +13,7 @@ interface UuidAwareInterface { /** - * @return UuidInterface + * @return UuidInterface|null */ - public function getUuid(): UuidInterface; + public function getUuid(): ?UuidInterface; } diff --git a/src/App/src/Common/UuidAwareTrait.php b/src/App/src/Common/UuidAwareTrait.php index f3fdff53..bbb78fd9 100644 --- a/src/App/src/Common/UuidAwareTrait.php +++ b/src/App/src/Common/UuidAwareTrait.php @@ -4,9 +4,9 @@ namespace Frontend\App\Common; -use Exception; use Doctrine\ORM\Mapping as ORM; use Ramsey\Uuid\UuidInterface; +use Throwable; /** * Trait UuidAwareTrait @@ -19,19 +19,18 @@ trait UuidAwareTrait * @ORM\Column(name="uuid", type="uuid_binary_ordered_time", unique=true) * @ORM\GeneratedValue(strategy="CUSTOM") * @ORM\CustomIdGenerator(class="Ramsey\Uuid\Doctrine\UuidOrderedTimeGenerator") - * @var UuidInterface */ - protected $uuid; + protected ?UuidInterface $uuid = null; /** - * @return UuidInterface + * @return UuidInterface|null */ - public function getUuid(): UuidInterface + public function getUuid(): ?UuidInterface { if (!$this->uuid) { try { $this->uuid = UuidOrderedTimeGenerator::generateUuid(); - } catch (Exception $exception) { + } catch (Throwable $exception) { #TODO save the error message } } diff --git a/src/App/src/Common/UuidOrderedTimeGenerator.php b/src/App/src/Common/UuidOrderedTimeGenerator.php index 780f6fa5..30873b6d 100644 --- a/src/App/src/Common/UuidOrderedTimeGenerator.php +++ b/src/App/src/Common/UuidOrderedTimeGenerator.php @@ -5,10 +5,9 @@ namespace Frontend\App\Common; use Ramsey\Uuid\Codec\OrderedTimeCodec; -use Ramsey\Uuid\UuidFactory; +use Ramsey\Uuid\Uuid; use Ramsey\Uuid\UuidFactoryInterface; use Ramsey\Uuid\UuidInterface; -use Ramsey\Uuid\Uuid; /** * Class UuidOrderedTimeGenerator diff --git a/src/App/src/ConfigProvider.php b/src/App/src/ConfigProvider.php index b3d72c0f..02224d88 100644 --- a/src/App/src/ConfigProvider.php +++ b/src/App/src/ConfigProvider.php @@ -36,8 +36,8 @@ public function __invoke(): array { return [ 'dependencies' => $this->getDependencies(), - 'doctrine' => $this->getDoctrineConfig(), - 'templates' => $this->getTemplates(), + 'doctrine' => $this->getDoctrineConfig(), + 'templates' => $this->getTemplates(), ]; } @@ -54,7 +54,7 @@ public function getDependencies(): array \Frontend\User\RoutesDelegator::class ] ], - 'factories' => [ + 'factories' => [ 'doctrine.entity_manager.orm_default' => EntityManagerFactory::class, EntityListenerResolver::class => EntityListenerResolverFactory::class, TranslateService::class => AnnotatedServiceFactory::class, @@ -92,8 +92,8 @@ public function getTemplates(): array { return [ 'paths' => [ - 'app' => [__DIR__ . '/../templates/app'], - 'error' => [__DIR__ . '/../templates/error'], + 'app' => [__DIR__ . '/../templates/app'], + 'error' => [__DIR__ . '/../templates/error'], 'layout' => [__DIR__ . '/../templates/layout'], 'partial' => [__DIR__ . '/../templates/partial'], 'language' => [__DIR__ . '/../templates/language'], diff --git a/src/App/src/Controller/LanguageController.php b/src/App/src/Controller/LanguageController.php index 283a283e..c452b187 100644 --- a/src/App/src/Controller/LanguageController.php +++ b/src/App/src/Controller/LanguageController.php @@ -1,9 +1,10 @@ translatorConfig['default']; $this->translateService->addTranslatorCookie($languageKey); - return new HtmlResponse('', 200); + return new HtmlResponse(''); } /** - * @return JsonResponse + * @return ResponseInterface */ - public function translateTextAction() + public function translateTextAction(): ResponseInterface { $translation = ''; $request = $this->getRequest(); @@ -94,6 +94,6 @@ public function translateTextAction() return new JsonResponse([ 'translation' => $translation - ], 200); + ]); } } \ No newline at end of file diff --git a/src/App/src/Factory/AuthMiddlewareFactory.php b/src/App/src/Factory/AuthMiddlewareFactory.php index 45373b51..7ed28415 100644 --- a/src/App/src/Factory/AuthMiddlewareFactory.php +++ b/src/App/src/Factory/AuthMiddlewareFactory.php @@ -1,11 +1,6 @@ get(RbacGuardOptions::class); - /** @var Factory $guardsProviderFactory */ $guardsProviderFactory = new Factory($container, $container->get(GuardsProviderPluginManager::class)); $guardsProvider = $guardsProviderFactory->create($options->getGuardsProvider()); - /** @var AuthMiddlewareFactory $middleware */ - $middleware = new $requestedName( + return new $requestedName( $container->get(RouterInterface::class), $container->get(FlashMessenger::class), $guardsProvider, $options ); - - return $middleware; } } diff --git a/src/App/src/Factory/EntityListenerResolverFactory.php b/src/App/src/Factory/EntityListenerResolverFactory.php index 25740b62..c14bf92e 100644 --- a/src/App/src/Factory/EntityListenerResolverFactory.php +++ b/src/App/src/Factory/EntityListenerResolverFactory.php @@ -9,7 +9,7 @@ /** * Class EntityListenerResolverFactory - * @package Frontend\App\Doctrine\Factory + * @package Frontend\App\Factory */ class EntityListenerResolverFactory { @@ -17,7 +17,7 @@ class EntityListenerResolverFactory * @param ContainerInterface $container * @return EntityListenerResolver */ - public function __invoke(ContainerInterface $container) + public function __invoke(ContainerInterface $container): EntityListenerResolver { return new EntityListenerResolver($container); } diff --git a/src/App/src/Middleware/AuthMiddleware.php b/src/App/src/Middleware/AuthMiddleware.php index b92e619f..d692514a 100644 --- a/src/App/src/Middleware/AuthMiddleware.php +++ b/src/App/src/Middleware/AuthMiddleware.php @@ -4,11 +4,11 @@ namespace Frontend\App\Middleware; +use Dot\FlashMessenger\FlashMessenger; use Dot\Rbac\Guard\Exception\RuntimeException; use Dot\Rbac\Guard\Guard\GuardInterface; use Dot\Rbac\Guard\Options\RbacGuardOptions; use Dot\Rbac\Guard\Provider\GuardsProviderInterface; -use Dot\FlashMessenger\FlashMessenger; use Laminas\Diactoros\Response\RedirectResponse; use Mezzio\Router\RouterInterface; use Psr\Http\Message\ResponseInterface; @@ -17,27 +17,18 @@ use Psr\Http\Server\RequestHandlerInterface; /** - * Class AuthTeamMiddleware - * @package App\User\Middleware - * + * Class AuthMiddleware + * @package Frontend\App\Middleware */ class AuthMiddleware implements MiddlewareInterface { - - /** @var RouterInterface $router */ - protected $router; - - /** @var FlashMessenger $messenger */ - protected $messenger; - - /** @var GuardsProviderInterface $guardProvider */ - protected $guardProvider; - - /** @var RbacGuardOptions */ - protected $options; + protected RouterInterface $router; + protected FlashMessenger $messenger; + protected GuardsProviderInterface $guardProvider; + protected RbacGuardOptions $options; /** - * IdentityMiddleware constructor. + * AuthMiddleware constructor. * @param RouterInterface $router * @param FlashMessenger $messenger * @param GuardsProviderInterface $guardProvider diff --git a/src/App/src/Middleware/RememberMeMiddleware.php b/src/App/src/Middleware/RememberMeMiddleware.php index 0b82d4af..6de72a46 100644 --- a/src/App/src/Middleware/RememberMeMiddleware.php +++ b/src/App/src/Middleware/RememberMeMiddleware.php @@ -27,25 +27,22 @@ */ class RememberMeMiddleware implements MiddlewareInterface { - /** @var UserServiceInterface */ - protected $userService; - - /** @var AuthenticationServiceInterface $authenticationService */ + protected UserServiceInterface $userService; protected AuthenticationServiceInterface $authenticationService; - - /** @var UserRepository $repository */ - protected $repository; - - /** @var array */ - protected $rememberConfig; + protected UserRepository $repository; + protected array $rememberConfig = []; /** - * TranslatorMiddleware constructor. + * RememberMeMiddleware constructor. * @param UserServiceInterface $userService * @param AuthenticationService $authenticationService * @param array $rememberConfig * - * @Inject({UserServiceInterface::class, AuthenticationService::class, "config.rememberMe"}) + * @Inject({ + * UserServiceInterface::class, + * AuthenticationService::class, + * "config.rememberMe" + * }) */ public function __construct( UserServiceInterface $userService, diff --git a/src/App/src/Resolver/EntityListenerResolver.php b/src/App/src/Resolver/EntityListenerResolver.php index c45413ea..4133dbd4 100644 --- a/src/App/src/Resolver/EntityListenerResolver.php +++ b/src/App/src/Resolver/EntityListenerResolver.php @@ -11,11 +11,10 @@ /** * Class EntityListenerResolver - * @package Frontend\App\Doctrine\Resolver + * @package Frontend\App\Resolver */ class EntityListenerResolver extends DefaultEntityListenerResolver { - /** @var ContainerInterface $container */ protected ContainerInterface $container; /** diff --git a/src/App/src/RoutesDelegator.php b/src/App/src/RoutesDelegator.php index 7003e256..d3249476 100644 --- a/src/App/src/RoutesDelegator.php +++ b/src/App/src/RoutesDelegator.php @@ -1,5 +1,7 @@ $options['expires'] ?? $this->getCookieLifetime(), - 'domain' => $options['domain'] ?? $this->sessionConfig->getCookieDomain(), + 'expires' => $options['expires'] ?? $this->getCookieLifetime(), + 'domain' => $options['domain'] ?? $this->sessionConfig->getCookieDomain(), 'httponly' => $options['httponly'] ?? $this->sessionConfig->getCookieHttpOnly(), - 'path' => $options['path'] ?? $this->sessionConfig->getCookiePath(), + 'path' => $options['path'] ?? $this->sessionConfig->getCookiePath(), 'samesite' => $options['samesite'] ?? $this->sessionConfig->getCookieSameSite(), - 'secure' => $options['secure'] ?? $this->sessionConfig->getCookieSecure(), + 'secure' => $options['secure'] ?? $this->sessionConfig->getCookieSecure(), ]; } diff --git a/src/App/src/Service/CookieServiceInterface.php b/src/App/src/Service/CookieServiceInterface.php index 2df692ce..b67d9396 100644 --- a/src/App/src/Service/CookieServiceInterface.php +++ b/src/App/src/Service/CookieServiceInterface.php @@ -1,7 +1,13 @@ $this->config['scoreThreshold']; } + /** + * @param array $config + * @return void + */ private function validateConfig(array $config): void { $keysToValidate = ['siteKey', 'secretKey', 'verifyUrl', 'scoreThreshold']; diff --git a/src/App/src/Service/TranslateService.php b/src/App/src/Service/TranslateService.php index d2f79f0a..a0062de2 100644 --- a/src/App/src/Service/TranslateService.php +++ b/src/App/src/Service/TranslateService.php @@ -35,8 +35,9 @@ public function __construct( /** * @param string $languageKey + * @return void */ - public function addTranslatorCookie(string $languageKey) + public function addTranslatorCookie(string $languageKey): void { $expires = time() + ($this->config['translator']['cookie']['lifetime'] ?? $this->config['session_config']['cookie_lifetime']); diff --git a/src/App/src/Service/TranslateServiceInterface.php b/src/App/src/Service/TranslateServiceInterface.php index 60cab7fe..414e3b1f 100644 --- a/src/App/src/Service/TranslateServiceInterface.php +++ b/src/App/src/Service/TranslateServiceInterface.php @@ -1,9 +1,11 @@ $this->getDependencies(), - 'templates' => $this->getTemplates(), + 'templates' => $this->getTemplates(), 'dot_form' => $this->getForms(), 'doctrine' => $this->getDoctrineConfig() ]; @@ -43,7 +43,7 @@ public function getDependencies(): array RoutesDelegator::class, ], ], - 'factories' => [ + 'factories' => [ ContactController::class => AnnotatedServiceFactory::class, MessageService::class => AnnotatedServiceFactory::class, ], diff --git a/src/Contact/src/Controller/ContactController.php b/src/Contact/src/Controller/ContactController.php index 4f8b09cf..ac97d8b2 100644 --- a/src/Contact/src/Controller/ContactController.php +++ b/src/Contact/src/Controller/ContactController.php @@ -1,10 +1,10 @@ inputFilter->init(); } - public function init() + /** + * @return void + */ + public function init(): void { parent::init(); diff --git a/src/Contact/src/InputFilter/ContactInputFilter.php b/src/Contact/src/InputFilter/ContactInputFilter.php index 8c9cbbcb..ff11e6e8 100644 --- a/src/Contact/src/InputFilter/ContactInputFilter.php +++ b/src/Contact/src/InputFilter/ContactInputFilter.php @@ -1,11 +1,5 @@ getEntityManager()->persist($message); $this->getEntityManager()->flush(); diff --git a/src/Contact/src/Repository/MessageRepositoryInterface.php b/src/Contact/src/Repository/MessageRepositoryInterface.php index fa81202c..d07bb8a6 100644 --- a/src/Contact/src/Repository/MessageRepositoryInterface.php +++ b/src/Contact/src/Repository/MessageRepositoryInterface.php @@ -5,18 +5,16 @@ namespace Frontend\Contact\Repository; use Frontend\Contact\Entity\Message; -use Doctrine\ORM; /** - * Class MessageRepositoryInterface + * Interface MessageRepositoryInterface * @package Frontend\Contact\Repository */ interface MessageRepositoryInterface { /** * @param Message $message - * @throws ORM\ORMException - * @throws ORM\OptimisticLockException + * @return void */ - public function saveMessage(Message $message); + public function saveMessage(Message $message): void; } diff --git a/src/Contact/src/RoutesDelegator.php b/src/Contact/src/RoutesDelegator.php index c5209288..922c924d 100644 --- a/src/Contact/src/RoutesDelegator.php +++ b/src/Contact/src/RoutesDelegator.php @@ -1,5 +1,7 @@ mailService->setBody( $this->templateRenderer->render('contact::email', [ @@ -112,7 +107,7 @@ public function sendContactMail(Message $message) * @param $response * @return bool */ - public function recaptchaIsValid($response) + public function recaptchaIsValid($response): bool { $requestJson = [ 'response' => $response, diff --git a/src/Contact/src/Service/MessageServiceInterface.php b/src/Contact/src/Service/MessageServiceInterface.php index 81aff142..64ecf8bc 100644 --- a/src/Contact/src/Service/MessageServiceInterface.php +++ b/src/Contact/src/Service/MessageServiceInterface.php @@ -1,13 +1,14 @@ $this->getDependencies(), - 'templates' => $this->getTemplates(), + 'templates' => $this->getTemplates(), ]; } @@ -30,7 +30,7 @@ public function __invoke(): array public function getDependencies(): array { return [ - 'factories' => [ + 'factories' => [ PageController::class => AnnotatedServiceFactory::class, ], ]; diff --git a/src/Page/src/Controller/PageController.php b/src/Page/src/Controller/PageController.php index 63c25072..0fb6ae03 100644 --- a/src/Page/src/Controller/PageController.php +++ b/src/Page/src/Controller/PageController.php @@ -1,25 +1,25 @@ template->render('page::home', [ - - ]) + $this->template->render('page::home') ); } @@ -55,9 +57,7 @@ public function indexAction(): ResponseInterface public function homeAction(): ResponseInterface { return new HtmlResponse( - $this->template->render('page::home', [ - - ]) + $this->template->render('page::home') ); } @@ -67,9 +67,7 @@ public function homeAction(): ResponseInterface public function aboutUsAction(): ResponseInterface { return new HtmlResponse( - $this->template->render('page::about', [ - - ]) + $this->template->render('page::about') ); } @@ -79,9 +77,7 @@ public function aboutUsAction(): ResponseInterface public function premiumContentAction(): ResponseInterface { return new HtmlResponse( - $this->template->render('page::premium-content', [ - - ]) + $this->template->render('page::premium-content') ); } @@ -91,9 +87,7 @@ public function premiumContentAction(): ResponseInterface public function whoWeAreAction(): ResponseInterface { return new HtmlResponse( - $this->template->render('page::who-we-are', [ - - ]) + $this->template->render('page::who-we-are') ); } } diff --git a/src/Page/src/RoutesDelegator.php b/src/Page/src/RoutesDelegator.php index cc48af46..5c8df622 100644 --- a/src/Page/src/RoutesDelegator.php +++ b/src/Page/src/RoutesDelegator.php @@ -1,5 +1,7 @@ get('FormElementManager'), diff --git a/src/Plugin/src/Factory/PluginManagerAwareInitializer.php b/src/Plugin/src/Factory/PluginManagerAwareInitializer.php index 87961ab0..7ba2cb8c 100644 --- a/src/Plugin/src/Factory/PluginManagerAwareInitializer.php +++ b/src/Plugin/src/Factory/PluginManagerAwareInitializer.php @@ -1,18 +1,14 @@ get(PluginManager::class); diff --git a/src/Plugin/src/Factory/PluginManagerFactory.php b/src/Plugin/src/Factory/PluginManagerFactory.php index fbe408e2..5e317bca 100644 --- a/src/Plugin/src/Factory/PluginManagerFactory.php +++ b/src/Plugin/src/Factory/PluginManagerFactory.php @@ -1,11 +1,5 @@ get('config')['dot_controller']['plugin_manager']); diff --git a/src/Plugin/src/FormsPlugin.php b/src/Plugin/src/FormsPlugin.php index f279d716..4646b548 100644 --- a/src/Plugin/src/FormsPlugin.php +++ b/src/Plugin/src/FormsPlugin.php @@ -1,38 +1,27 @@ [ - SlugCollector::class => SlugCollectorFactory::class, - SlugMiddleware::class => AnnotatedServiceFactory::class, - SlugService::class => AnnotatedServiceFactory::class, - RouteExtension::class => RouteExtensionFactory::class, + SlugCollector::class => SlugCollectorFactory::class, + SlugMiddleware::class => AnnotatedServiceFactory::class, + SlugService::class => AnnotatedServiceFactory::class, + RouteExtension::class => RouteExtensionFactory::class, ], 'aliases' => [ - SlugInterface::class => SlugCollector::class, + SlugInterface::class => SlugCollector::class, SlugServiceInterface::class => SlugService::class ], ]; diff --git a/src/Slug/src/DuplicateSlugDetector.php b/src/Slug/src/DuplicateSlugDetector.php index 63a4509d..4f4c9e7a 100644 --- a/src/Slug/src/DuplicateSlugDetector.php +++ b/src/Slug/src/DuplicateSlugDetector.php @@ -6,8 +6,6 @@ use Frontend\Slug\Exception\DuplicateSlugException; -use function sprintf; - /** * Class DuplicateSlugDetector * @package Frontend\Slug diff --git a/src/Slug/src/Exception/DuplicateSlugException.php b/src/Slug/src/Exception/DuplicateSlugException.php index f1dead00..cf35b955 100644 --- a/src/Slug/src/Exception/DuplicateSlugException.php +++ b/src/Slug/src/Exception/DuplicateSlugException.php @@ -11,7 +11,6 @@ * Class DuplicateSlugException * @package Frontend\Slug\Exception */ -class DuplicateSlugException extends Exception implements - ExceptionInterface +class DuplicateSlugException extends Exception implements ExceptionInterface { } diff --git a/src/Slug/src/Exception/MissingConfigurationException.php b/src/Slug/src/Exception/MissingConfigurationException.php index 2b6ce1ce..41be47e3 100644 --- a/src/Slug/src/Exception/MissingConfigurationException.php +++ b/src/Slug/src/Exception/MissingConfigurationException.php @@ -11,7 +11,6 @@ * Class MissingConfigurationException * @package Frontend\Slug\Exception */ -class MissingConfigurationException extends Exception implements - ExceptionInterface +class MissingConfigurationException extends Exception implements ExceptionInterface { } diff --git a/src/Slug/src/Factory/RouteExtensionFactory.php b/src/Slug/src/Factory/RouteExtensionFactory.php index 4b68a2b7..7e38d0ce 100644 --- a/src/Slug/src/Factory/RouteExtensionFactory.php +++ b/src/Slug/src/Factory/RouteExtensionFactory.php @@ -8,7 +8,9 @@ use Frontend\Slug\TwigExtension\RouteExtension; use Mezzio\Helper\ServerUrlHelper; use Mezzio\Helper\UrlHelper; +use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; +use Psr\Container\NotFoundExceptionInterface; /** * Class SlugExtensionFactory @@ -16,22 +18,19 @@ */ class RouteExtensionFactory { - /** * @param ContainerInterface $container * @param $requestedName * @return RouteExtension + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ public function __invoke(ContainerInterface $container, $requestedName): RouteExtension { - $url = $container->get(UrlHelper::class); - $slugAdapter = $container->get(SlugInterface::class); - $serverUrl = $container->get(ServerUrlHelper::class); - return new $requestedName( - $url, - $slugAdapter, - $serverUrl + $container->get(UrlHelper::class), + $container->get(SlugInterface::class), + $container->get(ServerUrlHelper::class) ); } } diff --git a/src/Slug/src/Factory/SlugCollectorFactory.php b/src/Slug/src/Factory/SlugCollectorFactory.php index ea4f3dcf..0d8569be 100644 --- a/src/Slug/src/Factory/SlugCollectorFactory.php +++ b/src/Slug/src/Factory/SlugCollectorFactory.php @@ -7,8 +7,10 @@ use Frontend\Slug\Service\SlugServiceInterface; use Mezzio\Helper\UrlHelper; use Mezzio\Router\RouterInterface; +use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; use Frontend\Slug\SlugCollector; +use Psr\Container\NotFoundExceptionInterface; /** * Class SlugCollectorFactory @@ -16,30 +18,23 @@ */ class SlugCollectorFactory { - /** * @param ContainerInterface $container * @param $requestedName * @return SlugCollector + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ public function __invoke(ContainerInterface $container, $requestedName): SlugCollector { - $config = $container->get('config')['slug_configuration'] ?? []; - $router = $container->get(RouterInterface::class); - $url = $container->get(UrlHelper::class); - $slugService = $container->get(SlugServiceInterface::class); - - $detectDuplicates = true; - if (isset($config['detect_duplicates'])) { - $detectDuplicates = $config['detect_duplicates']; - } + $config = $container->get('config')['slug_configuration'] ?? []; return new $requestedName( - $router, - $url, - $slugService, + $container->get(RouterInterface::class), + $container->get(UrlHelper::class), + $container->get(SlugServiceInterface::class), $config, - $detectDuplicates + $config['detect_duplicates'] ?? true ); } } diff --git a/src/Slug/src/Middleware/SlugMiddleware.php b/src/Slug/src/Middleware/SlugMiddleware.php index c686d461..cd67564d 100644 --- a/src/Slug/src/Middleware/SlugMiddleware.php +++ b/src/Slug/src/Middleware/SlugMiddleware.php @@ -4,35 +4,42 @@ namespace Frontend\Slug\Middleware; +use Doctrine\DBAL\Driver\Exception; +use Dot\AnnotatedServices\Annotation\Inject; +use Frontend\Slug\Exception\MissingConfigurationException; use Frontend\Slug\SlugInterface; use Laminas\Diactoros\Uri; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; -use Dot\AnnotatedServices\Annotation\Inject; +/** + * Class SlugMiddleware + * @package Frontend\Slug\Middleware + */ class SlugMiddleware implements MiddlewareInterface { - - /** @var SlugInterface $slugAdapter */ private SlugInterface $slugAdapter; /** * SlugMiddleware constructor. * @param SlugInterface $slugAdapter - * @Inject({SlugInterface::class}) + * @Inject({ + * SlugInterface::class + * }) */ - public function __construct( - SlugInterface $slugAdapter - ) { - $this->slugAdapter = $slugAdapter; + public function __construct(SlugInterface $slugAdapter) + { + $this->slugAdapter = $slugAdapter; } /** * @param ServerRequestInterface $request * @param RequestHandlerInterface $handler * @return ResponseInterface + * @throws Exception + * @throws MissingConfigurationException */ public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { diff --git a/src/Slug/src/Service/SlugService.php b/src/Slug/src/Service/SlugService.php index 2b564686..1af7f7de 100644 --- a/src/Slug/src/Service/SlugService.php +++ b/src/Slug/src/Service/SlugService.php @@ -15,10 +15,8 @@ use Ramsey\Uuid\Uuid; use Ramsey\Uuid\UuidFactory; - /** * Class SlugService - * * @package Frontend\Slug\Service */ class SlugService implements SlugServiceInterface @@ -29,13 +27,13 @@ class SlugService implements SlugServiceInterface 'exchangeColumn', 'slugColumn' ]; - - /** @var EntityManager $em */ protected EntityManager $em; /** * SlugService constructor. - * @Inject({EntityManager::class}) + * @Inject({ + * EntityManager::class + * }) * @param EntityManager $em */ public function __construct(EntityManager $em) @@ -48,11 +46,10 @@ public function __construct(EntityManager $em) * @param string $value * @param Slug $slug * @return bool|string - * @throws \Doctrine\DBAL\Driver\Exception|MissingConfigurationException + * @throws MissingConfigurationException */ - public function slugManipulation(Slug $slug, string $attribute, string $value) + public function slugManipulation(Slug $slug, string $attribute, string $value): bool|string { - $exchange = $slug->getExchange(); $exchange = array_reduce( $exchange, @@ -83,7 +80,6 @@ function ($matched, $exchange) use ($attribute) { } else { return $value; } - } } return false; @@ -93,7 +89,6 @@ function ($matched, $exchange) use ($attribute) { * @param array $param * @param array $exchange * @return string - * @throws \Doctrine\DBAL\Driver\Exception */ protected function generateSlug(array $param, array $exchange): string { @@ -156,7 +151,6 @@ public function clean($input): string * @param string $slug * @param array $exchange * @return int - * @throws \Doctrine\DBAL\Driver\Exception */ protected function checkDuplicateSlug(string $slug, array $exchange): int { @@ -173,13 +167,12 @@ protected function checkDuplicateSlug(string $slug, array $exchange): int } /** + * @param Slug $slug * @param string $param * @param array $db - * @param Slug $slug - * @return false|array - * @throws \Doctrine\DBAL\Driver\Exception + * @return bool|array */ - protected function proceedSlug(Slug $slug, string $param, array $db) + protected function proceedSlug(Slug $slug, string $param, array $db): bool|array { $searchParam = $db['identifier']; if ($slug->getType() === Slug::REQUEST_TYPE) { @@ -209,7 +202,7 @@ protected function proceedSlug(Slug $slug, string $param, array $db) * @param $input * @return string|string[] */ - public function escapeCharacter($input) + public function escapeCharacter($input): array|string { return str_replace( ['\\', "\0", "\n", "\r", "'", '"', "\x1a"], diff --git a/src/Slug/src/Service/SlugServiceInterface.php b/src/Slug/src/Service/SlugServiceInterface.php index ca476d90..2472635b 100644 --- a/src/Slug/src/Service/SlugServiceInterface.php +++ b/src/Slug/src/Service/SlugServiceInterface.php @@ -1,13 +1,15 @@ alias = $alias; - $this->routeName = $routeName; - $this->params = $params; - $this->exchange = $exchange; - $this->type = self::URL_TYPE; + public function __construct(string $alias, string $routeName, array $params = [], array $exchange = []) + { + $this->alias = $alias; + $this->routeName = $routeName; + $this->params = $params; + $this->exchange = $exchange; + $this->type = self::URL_TYPE; } /** diff --git a/src/Slug/src/SlugCollector.php b/src/Slug/src/SlugCollector.php index 4d2ec300..f694abe3 100644 --- a/src/Slug/src/SlugCollector.php +++ b/src/Slug/src/SlugCollector.php @@ -6,17 +6,17 @@ use Doctrine\DBAL\Driver\Exception; use FastRoute\RouteParser\Std; +use Frontend\Slug\Exception\DuplicateSlugException; +use Frontend\Slug\Exception\RuntimeException; +use Frontend\Slug\Exception\MissingConfigurationException; use Frontend\Slug\Service\SlugService; +use InvalidArgumentException; use Laminas\Diactoros\ServerRequest; use Laminas\Diactoros\Uri; -use Mezzio\Helper\UrlHelper; use Mezzio\Router\RouteResult; use Mezzio\Router\RouterInterface; +use Mezzio\Helper\UrlHelper; use Psr\Http\Message\ServerRequestInterface; -use InvalidArgumentException; -use Frontend\Slug\Exception\DuplicateSlugException; -use Frontend\Slug\Exception\RuntimeException; -use Frontend\Slug\Exception\MissingConfigurationException; /** * Class SlugCollector @@ -38,23 +38,12 @@ class SlugCollector implements SlugInterface */ private array $slugs = []; - /** @var RouterInterface $router */ private RouterInterface $router; - - /** @var null|DuplicateSlugDetector $duplicateSlugDetector */ private ?DuplicateSlugDetector $duplicateSlugDetector; - - /** @var UrlHelper $url */ private UrlHelper $url; - - /** @var SlugService $slugService */ private SlugService $slugService; - - /** @var bool $detectDuplicates */ - protected bool $detectDuplicates = true; - - /** @var array $config */ - private array $config; + private bool $detectDuplicates = true; + private array $config = []; /** * SlugCollector constructor. @@ -69,14 +58,14 @@ public function __construct( RouterInterface $router, UrlHelper $url, SlugService $slugService, - $config = [], + array $config = [], bool $detectDuplicates = true ) { - $this->router = $router; - $this->url = $url; - $this->slugService = $slugService; - $this->config = $config; - $this->detectDuplicates = $detectDuplicates; + $this->router = $router; + $this->url = $url; + $this->slugService = $slugService; + $this->config = $config; + $this->detectDuplicates = $detectDuplicates; $this->duplicateSlugDetector = new DuplicateSlugDetector(); @@ -123,7 +112,7 @@ public function slug( array $params, array $exchange ): Slug { - $slug = new Slug($alias, $routeName, $params, $exchange); + $slug = new Slug($alias, $routeName, $params, $exchange); if ($this->detectDuplicates) { $this->detectDuplicate($slug); } @@ -170,21 +159,20 @@ public function match( }, false); - if (!((object)$slug instanceof Slug)) { + if (!($slug instanceof Slug)) { return SlugResult::fromSlugFailure(); } $routerOptions = $options['router'] ?? []; - $path = $this->router->generateUri($routeName, $routeParams, $routerOptions); + $path = $this->router->generateUri($routeName, $routeParams, $routerOptions); $request = new ServerRequest(); - /** @var ServerRequest $request */ $request = $request->withUri(new Uri($path)); $match = $this->router->match($request); $slug->setType(Slug::URL_TYPE); if ($match->isSuccess()) { - $path = $this->generateUri($slug, $match); + $path = $this->generateUri($slug, $match); $path = $this->appendQueryStringArguments($path, $queryParams); $path = $this->appendFragment($path, $fragmentIdentifier); } else { @@ -202,7 +190,7 @@ public function match( */ public function matchRequest(ServerRequestInterface $request): SlugResult { - $path = rawurldecode($request->getUri()->getPath()); + $path = rawurldecode($request->getUri()->getPath()); $fragments = explode('/', $path); $path = '/' . $fragments[1]; @@ -214,14 +202,13 @@ public function matchRequest(ServerRequestInterface $request): SlugResult return $slug; }, false); - if (!((object)$slug instanceof Slug)) { + if (!($slug instanceof Slug)) { return SlugResult::fromSlugFailure(); } - $path = $this->router->generateUri($slug->getRouteName(), $slug->getParams(), $fragments); + $path = $this->router->generateUri($slug->getRouteName(), $slug->getParams(), $fragments); $serverRequest = new ServerRequest(); - /** @var ServerRequest $serverRequest */ $serverRequest = $serverRequest->withUri(new Uri($path)); $match = $this->router->match($serverRequest); @@ -231,14 +218,14 @@ public function matchRequest(ServerRequestInterface $request): SlugResult $slug->setType(Slug::REQUEST_TYPE); if ($match->isSuccess()) { - $path = $this->generateUri($slug, $match, $matchParams); + $path = $this->generateUri($slug, $match, $matchParams); } else { return SlugResult::fromSlugFailure(); } + return SlugResult::fromSlug($slug, $path, $matchParams); } - /** * @param Slug $slug * @param RouteResult $routeResult @@ -249,7 +236,6 @@ public function matchRequest(ServerRequestInterface $request): SlugResult */ public function generateUri(Slug $slug, RouteResult $routeResult, $matchParams = []): string { - $route = $routeResult->getMatchedRoute(); $substitutions = $routeResult->getMatchedParams(); @@ -257,8 +243,8 @@ public function generateUri(Slug $slug, RouteResult $routeResult, $matchParams = $substitutions = array_merge($routeResult->getMatchedParams(), $matchParams); } - $routeParser = new Std(); - $routes = array_reverse($routeParser->parse($route->getPath())); + $routeParser = new Std(); + $routes = array_reverse($routeParser->parse($route->getPath())); $missingParameters = []; foreach ($routes as $parts) { // Check if all parameters can be substituted @@ -422,8 +408,8 @@ private function appendFragment(string $uriString, ?string $fragmentIdentifier): public function matchParams(ServerRequestInterface $request, RouteResult $routeResult): array { $route = $routeResult->getMatchedRoute(); - $routeParser = new Std(); - $routes = array_reverse($routeParser->parse($route->getPath())); + $routeParser = new Std(); + $routes = array_reverse($routeParser->parse($route->getPath())); $fragments = explode('/', $request->getUri()->getPath()); @@ -453,9 +439,6 @@ public function matchParams(ServerRequestInterface $request, RouteResult $routeR */ private function detectDuplicate(Slug $slug): void { - if ($this->duplicateSlugDetector) { - $this->duplicateSlugDetector->detectDuplicate($slug); - return; - } + $this->duplicateSlugDetector?->detectDuplicate($slug); } } diff --git a/src/Slug/src/SlugInterface.php b/src/Slug/src/SlugInterface.php index 7ddb2b97..2c39691c 100644 --- a/src/Slug/src/SlugInterface.php +++ b/src/Slug/src/SlugInterface.php @@ -4,6 +4,9 @@ namespace Frontend\Slug; +use Doctrine\DBAL\Driver\Exception; +use Frontend\Slug\Exception\MissingConfigurationException; +use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface as Request; /** @@ -13,9 +16,10 @@ interface SlugInterface { /** - * - * @param Request $request + * @param ServerRequestInterface $request * @return SlugResult + * @throws Exception + * @throws MissingConfigurationException */ public function matchRequest(Request $request): SlugResult; @@ -26,6 +30,8 @@ public function matchRequest(Request $request): SlugResult; * @param $fragmentIdentifier * @param $options * @return SlugResult + * @throws Exception + * @throws MissingConfigurationException */ public function match( $routeName, @@ -36,7 +42,7 @@ public function match( ): SlugResult; /** - * @return array + * @return Slug[] */ public function getSlugs(): array; } diff --git a/src/Slug/src/SlugResult.php b/src/Slug/src/SlugResult.php index e37b1d3e..c46e8e42 100644 --- a/src/Slug/src/SlugResult.php +++ b/src/Slug/src/SlugResult.php @@ -10,22 +10,12 @@ */ class SlugResult { - /** - * @var ?Slug $slug - */ - private Slug $slug; - - /** @var string $url*/ + private ?Slug $slug = null; private string $url; - - /** @var array $matchedParams */ private array $matchedParams; - - /** @var bool $success Success state of slug. */ private bool $success; /** - * * Create an instance representing a slug success from the matching slug. * * @param $slug @@ -33,13 +23,13 @@ class SlugResult * @param array $matchedParams * @return SlugResult */ - public static function fromSlug($slug, $url, $matchedParams = []): self + public static function fromSlug($slug, $url, array $matchedParams = []): self { - $result = new self(); - $result->success = true; - $result->slug = $slug; - $result->url = $url; - $result->matchedParams = $matchedParams; + $result = new self(); + $result->success = true; + $result->slug = $slug; + $result->url = $url; + $result->matchedParams = $matchedParams; return $result; } @@ -51,8 +41,8 @@ public static function fromSlug($slug, $url, $matchedParams = []): self */ public static function fromSlugFailure(): self { - $result = new self(); - $result->success = false; + $result = new self(); + $result->success = false; return $result; } @@ -68,9 +58,9 @@ public function isSuccess(): bool /** * Retrieve the slug that resulted in the slug match. * - * @return false|null|Slug + * @return bool|Slug|null */ - public function getMatchedSlug() + public function getMatchedSlug(): bool|Slug|null { return $this->isFailure() ? false : $this->slug; } diff --git a/src/Slug/src/TwigExtension/RouteExtension.php b/src/Slug/src/TwigExtension/RouteExtension.php index a106c364..6cb6b249 100644 --- a/src/Slug/src/TwigExtension/RouteExtension.php +++ b/src/Slug/src/TwigExtension/RouteExtension.php @@ -4,6 +4,8 @@ namespace Frontend\Slug\TwigExtension; +use Doctrine\DBAL\Driver\Exception; +use Frontend\Slug\Exception\MissingConfigurationException; use Frontend\Slug\SlugInterface; use Mezzio\Helper\ServerUrlHelper; use Mezzio\Helper\UrlHelper; @@ -12,17 +14,12 @@ /** * Class RouteExtension - * @package Frontend\App\Twig + * @package Frontend\Slug\TwigExtension */ class RouteExtension extends AbstractExtension { - /** @var UrlHelper $urlHelper */ private UrlHelper $urlHelper; - - /** @var SlugInterface $slugAdapter */ private SlugInterface $slugAdapter; - - /** @var ServerUrlHelper $serverUrlHelper*/ private ServerUrlHelper $serverUrlHelper; /** @@ -59,6 +56,8 @@ public function getFunctions(): array * @param string|null $fragmentIdentifier * @param array $options * @return string + * @throws Exception + * @throws MissingConfigurationException */ public function renderUri( ?string $route = null, @@ -67,7 +66,6 @@ public function renderUri( ?string $fragmentIdentifier = null, array $options = [] ): string { - $response = $this->slugAdapter->match($route, $routeParams, $queryParams, $fragmentIdentifier, $options); if ($response->isSuccess()) { @@ -84,6 +82,8 @@ public function renderUri( * @param string|null $fragmentIdentifier * @param array $options * @return string + * @throws Exception + * @throws MissingConfigurationException */ public function renderUrl( ?string $route = null, @@ -92,7 +92,6 @@ public function renderUrl( ?string $fragmentIdentifier = null, array $options = [] ): string { - return $this->serverUrlHelper->generate( $this->renderUri($route, $routeParams, $queryParams, $fragmentIdentifier, $options) ); diff --git a/src/User/src/Authentication/AuthenticationAdapter.php b/src/User/src/Adapter/AuthenticationAdapter.php similarity index 62% rename from src/User/src/Authentication/AuthenticationAdapter.php rename to src/User/src/Adapter/AuthenticationAdapter.php index 73353f31..0a430e19 100644 --- a/src/User/src/Authentication/AuthenticationAdapter.php +++ b/src/User/src/Adapter/AuthenticationAdapter.php @@ -1,41 +1,38 @@ entityManager = $entityManager; + $this->entityRepository = $entityRepository; $this->config = $config; } @@ -48,25 +45,21 @@ public function authenticate(): Result /** Check for the authentication configuration */ $this->validateConfig(); - /** Get the identity class object */ - $repository = $this->entityManager->getRepository($this->config['orm_default']['identity_class']); - /** @var User $identityClass */ - $identityClass = $repository->findOneBy([ - $this->config['orm_default']['identity_property'] => $this->getIdentity() - ]); - + $identityClass = $this->entityRepository->findOneBy([ + $this->config['identity_property'] => $this->getIdentity() + ]); if (null === $identityClass) { return new Result( Result::FAILURE_IDENTITY_NOT_FOUND, null, - [$this->config['orm_default']['messages']['not_found']] + [$this->config['messages']['not_found']] ); } - $getCredential = "get" . ucfirst($this->config['orm_default']['credential_property']); + $getCredential = 'get' . ucfirst($this->config['credential_property']); - /** Check if get credential method exist in the provided identity class */ + /** Check if $getCredential method exist in the provided identity class */ $this->checkMethod($identityClass, $getCredential); /** If passwords don't match, return failure response */ @@ -74,16 +67,16 @@ public function authenticate(): Result return new Result( Result::FAILURE_CREDENTIAL_INVALID, null, - [$this->config['orm_default']['messages']['invalid_credential']] + [$this->config['messages']['invalid_credential']] ); } /** Check for extra validation options */ - if (! empty($this->config['orm_default']['options'])) { - foreach ($this->config['orm_default']['options'] as $property => $option) { - $methodName = "get" . ucfirst($property); + if (! empty($this->config['options'])) { + foreach ($this->config['options'] as $property => $option) { + $methodName = 'get' . ucfirst($property); - /** Check if the method exists in the provided identity class */ + /** Check if $methodName exists in the provided identity class */ $this->checkMethod($identityClass, $methodName); /** Check if value for the current option is provided */ @@ -96,7 +89,7 @@ public function authenticate(): Result } /** Check if message for the current option is provided */ - if (! array_key_exists('message', $option)) { + if (!array_key_exists('message', $option)) { throw new Exception(sprintf( self::OPTION_VALUE_NOT_PROVIDED, 'message', @@ -124,7 +117,7 @@ public function authenticate(): Result })->toArray(), $identityClass->getDetail()->getArrayCopy(), ), - [$this->config['orm_default']['messages']['success']] + [$this->config['messages']['success']] ); } @@ -133,19 +126,16 @@ public function authenticate(): Result */ private function validateConfig() { - if ( - ! isset($this->config['orm_default']['identity_class']) || - ! class_exists($this->config['orm_default']['identity_class']) - ) { - throw new Exception("No or invalid param 'identity_class' provided."); + if (!isset($this->config['identity_class']) || !class_exists($this->config['identity_class'])) { + throw new Exception("Missing or invalid param 'identity_class' provided."); } - if (! isset($this->config['orm_default']['identity_property'])) { - throw new Exception("No or invalid param 'identity_class' provided."); + if (!isset($this->config['identity_property'])) { + throw new Exception("Missing or invalid param 'identity_class' provided."); } - if (! isset($this->config['orm_default']['credential_property'])) { - throw new Exception("No or invalid param 'credential_property' provided."); + if (!isset($this->config['credential_property'])) { + throw new Exception("Missing or invalid param 'credential_property' provided."); } if (empty($this->identity) || empty($this->credential)) { @@ -160,7 +150,7 @@ private function validateConfig() */ private function checkMethod($identityClass, string $methodName): void { - if (! method_exists($identityClass, $methodName)) { + if (!method_exists($identityClass, $methodName)) { throw new Exception(sprintf( self::METHOD_NOT_EXISTS, $methodName, diff --git a/src/User/src/Authentication/AuthenticationAdapterFactory.php b/src/User/src/Authentication/AuthenticationAdapterFactory.php deleted file mode 100644 index ae2f5be3..00000000 --- a/src/User/src/Authentication/AuthenticationAdapterFactory.php +++ /dev/null @@ -1,33 +0,0 @@ -has(EntityManager::class)) { - throw new Exception('EntityManager not found.'); - } - - /** @var array $config */ - $config = $container->get('config'); - if (! isset($config['doctrine']['authentication'])) { - throw new Exception('Authentication config not found.'); - } - return new AuthenticationAdapter( - $container->get(EntityManager::class), - $config['doctrine']['authentication'] - ); - } -} diff --git a/src/User/src/ConfigProvider.php b/src/User/src/ConfigProvider.php index 4b35095f..5a89ef54 100644 --- a/src/User/src/ConfigProvider.php +++ b/src/User/src/ConfigProvider.php @@ -6,15 +6,14 @@ use Doctrine\ORM\Mapping\Driver\AnnotationDriver; use Dot\AnnotatedServices\Factory\AnnotatedServiceFactory; -use Frontend\User\Authentication\AuthenticationAdapter; -use Frontend\User\Authentication\AuthenticationAdapterFactory; -use Frontend\User\Authentication\AuthenticationServiceFactory; -use Frontend\User\Authentication\AuthenticationServiceInterface; +use Frontend\User\Adapter\AuthenticationAdapter; +use Frontend\User\Controller\AccountController; +use Frontend\User\Controller\UserController; use Frontend\User\Entity\User; use Frontend\User\Entity\UserInterface; +use Frontend\User\Factory\AuthenticationAdapterFactory; +use Frontend\User\Factory\AuthenticationServiceFactory; use Frontend\User\Form\LoginForm; -use Frontend\User\Controller\AccountController; -use Frontend\User\Controller\UserController; use Frontend\User\Service\UserRoleService; use Frontend\User\Service\UserRoleServiceInterface; use Frontend\User\Service\UserService; @@ -35,7 +34,7 @@ public function __invoke(): array { return [ 'dependencies' => $this->getDependencies(), - 'templates' => $this->getTemplates(), + 'templates' => $this->getTemplates(), 'dot_form' => $this->getForms(), 'doctrine' => $this->getDoctrineConfig(), ]; @@ -47,7 +46,7 @@ public function __invoke(): array public function getDependencies(): array { return [ - 'factories' => [ + 'factories' => [ UserController::class => AnnotatedServiceFactory::class, AccountController::class => AnnotatedServiceFactory::class, UserService::class => AnnotatedServiceFactory::class, diff --git a/src/User/src/Controller/AccountController.php b/src/User/src/Controller/AccountController.php index 2cbe2294..da304882 100644 --- a/src/User/src/Controller/AccountController.php +++ b/src/User/src/Controller/AccountController.php @@ -32,27 +32,18 @@ use Psr\Http\Message\ResponseInterface; use Exception; +/** + * Class AccountController + * @package Frontend\User\Controller + */ class AccountController extends AbstractActionController { - /** @var RouterInterface $router */ protected RouterInterface $router; - - /** @var TemplateRendererInterface $template */ protected TemplateRendererInterface $template; - - /** @var UserService $userService */ protected UserService $userService; - - /** @var AuthenticationServiceInterface $authenticationService */ protected AuthenticationServiceInterface $authenticationService; - - /** @var FlashMessenger $messenger */ protected FlashMessenger $messenger; - - /** @var FormsPlugin $forms */ protected FormsPlugin $forms; - - /** @var DebugBar $debugBar */ protected DebugBar $debugBar; /** @@ -64,6 +55,7 @@ class AccountController extends AbstractActionController * @param FlashMessenger $messenger * @param FormsPlugin $forms * @param DebugBar $debugBar + * * @Inject({ * UserService::class, * RouterInterface::class, @@ -72,7 +64,7 @@ class AccountController extends AbstractActionController * FlashMessenger::class, * FormsPlugin::class, * DebugBar::class - * }) + * }) */ public function __construct( UserService $userService, @@ -103,7 +95,6 @@ public function activateAction(): ResponseInterface return new RedirectResponse($this->router->generateUri("user", ['action' => 'login'])); } - /** @var User $user */ $user = $this->userService->findOneBy(['hash' => $hash]); if (!($user instanceof User)) { $this->messenger->addError(Message::INVALID_ACTIVATION_CODE, 'user-login'); @@ -292,7 +283,6 @@ public function avatarAction(): ResponseInterface /** @var UserIdentity $identity */ $identity = $this->authenticationService->getIdentity(); - /** @var User $user */ $user = $this->userService->findByUuid($identity->getUuid()); $form = new UploadAvatarForm(); if (RequestMethodInterface::METHOD_POST === $this->request->getMethod()) { @@ -342,7 +332,6 @@ public function detailsAction(): ResponseInterface /** @var UserIdentity $identity */ $identity = $this->authenticationService->getIdentity(); - /** @var User $user */ $user = $this->userService->findByUuid($identity->getUuid()); $form = new ProfileDetailsForm(); @@ -410,7 +399,6 @@ public function changePasswordAction(): ResponseInterface /** @var UserIdentity $identity */ $identity = $this->authenticationService->getIdentity(); - /** @var User $user */ $user = $this->userService->findByUuid($identity->getUuid()); $form = new ProfilePasswordForm(); @@ -468,7 +456,6 @@ public function deleteAccountAction(): ResponseInterface /** @var UserIdentity $identity */ $identity = $this->authenticationService->getIdentity(); - /** @var User $user */ $user = $this->userService->findByUuid($identity->getUuid()); $form = new ProfileDeleteForm(); diff --git a/src/User/src/Controller/UserController.php b/src/User/src/Controller/UserController.php index ac0377b3..67f1eb6f 100644 --- a/src/User/src/Controller/UserController.php +++ b/src/User/src/Controller/UserController.php @@ -5,15 +5,13 @@ namespace Frontend\User\Controller; use Doctrine\ORM\NonUniqueResultException; -use Doctrine\ORM\OptimisticLockException; -use Doctrine\ORM\ORMException; use Dot\Controller\AbstractActionController; use Dot\DebugBar\DebugBar; use Dot\FlashMessenger\FlashMessenger; use Fig\Http\Message\RequestMethodInterface; use Frontend\App\Service\CookieService; use Frontend\Plugin\FormsPlugin; -use Frontend\User\Authentication\AuthenticationAdapter; +use Frontend\User\Adapter\AuthenticationAdapter; use Frontend\User\Entity\User; use Frontend\User\Form\LoginForm; use Frontend\User\Form\RegisterForm; @@ -27,6 +25,10 @@ use Psr\Http\Message\ResponseInterface; use Exception; +/** + * Class UserController + * @package Frontend\User\Controller + */ class UserController extends AbstractActionController { protected CookieService $cookieService; @@ -88,8 +90,7 @@ public function __construct( /** * @return ResponseInterface * @throws NonUniqueResultException - * @throws ORMException - * @throws OptimisticLockException + * @throws Exception */ public function loginAction(): ResponseInterface { diff --git a/src/User/src/Entity/User.php b/src/User/src/Entity/User.php index fd2092b9..0a8cb767 100644 --- a/src/User/src/Entity/User.php +++ b/src/User/src/Entity/User.php @@ -6,14 +6,11 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; +use Doctrine\ORM\Mapping as ORM; use Dot\Authorization\Role\RoleInterface; +use Exception; use Frontend\App\Common\AbstractEntity; use Frontend\App\Common\UuidOrderedTimeGenerator; -use Doctrine\ORM\Mapping as ORM; -use Exception; - -use function bin2hex; -use function random_bytes; /** * Class User @@ -416,8 +413,8 @@ public function getArrayCopy(): array { return [ 'uuid' => $this->getUuid()->toString(), - 'detail' => ($this->getDetail() instanceof UserDetail) ? $this->getDetail()->getArrayCopy() : null, - 'avatar' => ($this->getAvatar() instanceof UserAvatar) ? $this->getAvatar()->getArrayCopy() : null, + 'detail' => $this->getDetail()?->getArrayCopy(), + 'avatar' => $this->getAvatar()?->getArrayCopy(), 'identity' => $this->getIdentity(), 'status' => $this->getStatus(), 'roles' => $this->getRoles()->map(function (UserRole $userRole) { diff --git a/src/User/src/Entity/UserAvatar.php b/src/User/src/Entity/UserAvatar.php index eeb5ffbe..fc5f1038 100644 --- a/src/User/src/Entity/UserAvatar.php +++ b/src/User/src/Entity/UserAvatar.php @@ -28,9 +28,6 @@ class UserAvatar extends AbstractEntity */ protected string $name; - /** - * @var string $url - */ protected string $url; /** diff --git a/src/User/src/Entity/UserIdentity.php b/src/User/src/Entity/UserIdentity.php index c0e14ac0..bee891ec 100644 --- a/src/User/src/Entity/UserIdentity.php +++ b/src/User/src/Entity/UserIdentity.php @@ -12,16 +12,9 @@ */ class UserIdentity implements UserInterface { - /** @var string $identity */ protected string $identity; - - /** @var array $roles */ protected array $roles; - - /** @var array $details */ protected array $details; - - /** @var string $uuid */ protected string $uuid; /** @@ -59,7 +52,6 @@ public function getIdentity(): string return $this->identity; } - /** * @return iterable * @psalm-suppress LessSpecificImplementedReturnType @@ -74,7 +66,7 @@ public function getRoles(): iterable * @param null|mixed $default * @return mixed */ - public function getDetail(string $name, $default = null) + public function getDetail(string $name, $default = null): mixed { return $this->details[$name] ?? $default; } diff --git a/src/User/src/Entity/UserInterface.php b/src/User/src/Entity/UserInterface.php index 873f64d3..b28c21b0 100644 --- a/src/User/src/Entity/UserInterface.php +++ b/src/User/src/Entity/UserInterface.php @@ -13,9 +13,9 @@ interface UserInterface { /** - * @return UuidInterface + * @return UuidInterface|null */ - public function getUuid(): UuidInterface; + public function getUuid(): ?UuidInterface; /** * @return UserDetail|null diff --git a/src/User/src/Entity/UserRememberMe.php b/src/User/src/Entity/UserRememberMe.php index 788d70f4..ff1ca7db 100644 --- a/src/User/src/Entity/UserRememberMe.php +++ b/src/User/src/Entity/UserRememberMe.php @@ -20,28 +20,27 @@ class UserRememberMe extends AbstractEntity /** * @ORM\ManyToOne(targetEntity="Frontend\User\Entity\User") * @ORM\JoinColumn(name="userUuid", referencedColumnName="uuid", nullable=false) - * @var User $user */ - protected $user; + protected User $user; /** * @ORM\Column(name="rememberMeToken", type="string", length=100, nullable=false, unique=true) - * @var string $rememberMeToken */ - protected $rememberMeToken; + protected string $rememberMeToken = ''; /** * @ORM\Column(name="userAgent", type="text") - * @var string|null $userAgent */ - protected $userAgent; + protected ?string $userAgent = null; /** * @ORM\Column(name="expireDate", type="datetime_immutable") - * @var DateTimeImmutable $expireDate */ - protected $expireDate; + protected DateTimeImmutable $expireDate; + /** + * UserRememberMe constructor. + */ public function __construct() { parent::__construct(); diff --git a/src/User/src/Entity/UserResetPassword.php b/src/User/src/Entity/UserResetPassword.php index 654a0c9b..e4004ad8 100644 --- a/src/User/src/Entity/UserResetPassword.php +++ b/src/User/src/Entity/UserResetPassword.php @@ -55,9 +55,9 @@ public function __construct() { parent::__construct(); - $tomorrow = new DateTime(); - $tomorrow->add(new DateInterval('P1D')); - $this->expires = DateTimeImmutable::createFromMutable($tomorrow); + $this->expires = DateTimeImmutable::createFromMutable( + (new DateTime())->add(new DateInterval('P1D')) + ); } /** diff --git a/src/User/src/EventListener/UserAvatarEventListener.php b/src/User/src/EventListener/UserAvatarEventListener.php index 01e20e09..904bf189 100644 --- a/src/User/src/EventListener/UserAvatarEventListener.php +++ b/src/User/src/EventListener/UserAvatarEventListener.php @@ -22,7 +22,9 @@ class UserAvatarEventListener * UserAvatarEventListener constructor. * @param array $config * - * @Inject({"config"}) + * @Inject({ + * "config" + * }) */ public function __construct(array $config = []) { @@ -31,32 +33,36 @@ public function __construct(array $config = []) /** * @param UserAvatar $avatar + * @return void */ - public function postLoad(UserAvatar $avatar) + public function postLoad(UserAvatar $avatar): void { $this->setAvatarUrl($avatar); } /** * @param UserAvatar $avatar + * @return void */ - public function postPersist(UserAvatar $avatar) + public function postPersist(UserAvatar $avatar): void { $this->setAvatarUrl($avatar); } /** * @param UserAvatar $avatar + * @return void */ - public function postUpdate(UserAvatar $avatar) + public function postUpdate(UserAvatar $avatar): void { $this->setAvatarUrl($avatar); } /** * @param UserAvatar $avatar + * @return void */ - private function setAvatarUrl(UserAvatar $avatar) + private function setAvatarUrl(UserAvatar $avatar): void { $avatar->setUrl( sprintf( diff --git a/src/User/src/Factory/AuthenticationAdapterFactory.php b/src/User/src/Factory/AuthenticationAdapterFactory.php new file mode 100644 index 00000000..ea5d7471 --- /dev/null +++ b/src/User/src/Factory/AuthenticationAdapterFactory.php @@ -0,0 +1,58 @@ +has(EntityManager::class)) { + throw new Exception('EntityManager not found.'); + } + + $config = $container->get('config'); + if (!isset($config['doctrine']['authentication']['orm_default'])) { + throw new Exception('Authentication config not found.'); + } + + /** @var EntityManager $entityManager */ + $entityManager = $container->get(EntityManager::class); + $repository = $entityManager->getRepository( + $config['doctrine']['authentication']['orm_default']['identity_class'] + ); + if (!($repository instanceof EntityRepository)) { + throw new Exception( + sprintf( + 'Could not find repository for identity class: %s', + $config['doctrine']['authentication']['orm_default']['identity_class'] + ) + ); + } + + return new AuthenticationAdapter( + $repository, + $config['doctrine']['authentication']['orm_default'] + ); + } +} diff --git a/src/User/src/Authentication/AuthenticationServiceFactory.php b/src/User/src/Factory/AuthenticationServiceFactory.php similarity index 62% rename from src/User/src/Authentication/AuthenticationServiceFactory.php rename to src/User/src/Factory/AuthenticationServiceFactory.php index 98955d2c..14281a4f 100644 --- a/src/User/src/Authentication/AuthenticationServiceFactory.php +++ b/src/User/src/Factory/AuthenticationServiceFactory.php @@ -1,12 +1,19 @@ get(AuthenticationAdapter::class); - return new AuthenticationService(null, $authAdapter); + return new AuthenticationService( + null, + $container->get(AuthenticationAdapter::class) + ); } } diff --git a/src/User/src/Factory/UserIdentityFactory.php b/src/User/src/Factory/UserIdentityFactory.php deleted file mode 100644 index 90571bbf..00000000 --- a/src/User/src/Factory/UserIdentityFactory.php +++ /dev/null @@ -1,33 +0,0 @@ -getEntityManager()->persist($user); $this->getEntityManager()->flush(); + + return $user; } /** * @param string $email * @param string|null $uuid - * @return mixed|null + * @return User|null */ - public function exists(string $email = '', ?string $uuid = '') + public function exists(string $email = '', ?string $uuid = ''): ?User { $qb = $this->getEntityManager()->createQueryBuilder(); @@ -113,11 +113,8 @@ public function findByResetPasswordHash(string $hash): ?User */ public function saveUserRememberMe(UserRememberMe $userRememberMe): void { - $userRememberMe->touch(); - - $em = $this->getEntityManager(); - $em->persist($userRememberMe); - $em->flush(); + $this->getEntityManager()->persist($userRememberMe); + $this->getEntityManager()->flush(); } /** @@ -139,10 +136,10 @@ public function getRememberUser($token): ?UserRememberMe /** * @param User $user * @param string $userAgent - * @return mixed + * @return UserRememberMe|null * @throws NonUniqueResultException */ - public function findRememberMeUser(User $user, string $userAgent) + public function findRememberMeUser(User $user, string $userAgent): ?UserRememberMe { $qb = $this->getEntityManager()->createQueryBuilder(); $qb->select('user_remember_me') @@ -160,7 +157,7 @@ public function findRememberMeUser(User $user, string $userAgent) * @param DateTimeImmutable $currentDate * @return mixed */ - public function deleteExpiredCookies(DateTimeImmutable $currentDate) + public function deleteExpiredCookies(DateTimeImmutable $currentDate): mixed { $qb = $this->getEntityManager()->createQueryBuilder(); $qb->delete(UserRememberMe::class, 'user_remember_me') diff --git a/src/User/src/Repository/UserRoleRepository.php b/src/User/src/Repository/UserRoleRepository.php index b235d019..1dabcdab 100644 --- a/src/User/src/Repository/UserRoleRepository.php +++ b/src/User/src/Repository/UserRoleRepository.php @@ -22,7 +22,6 @@ class UserRoleRepository extends EntityRepository public function findByName(string $name): ?UserRole { $qb = $this->getEntityManager()->createQueryBuilder(); - $qb ->select('role') ->from(UserRole::class, 'role') diff --git a/src/User/src/RoutesDelegator.php b/src/User/src/RoutesDelegator.php index d33f3aa2..af222427 100644 --- a/src/User/src/RoutesDelegator.php +++ b/src/User/src/RoutesDelegator.php @@ -1,5 +1,7 @@ roleRepository->findOneBy($params); - - return $role; + return $this->roleRepository->findOneBy($params); } } diff --git a/src/User/src/Service/UserRoleServiceInterface.php b/src/User/src/Service/UserRoleServiceInterface.php index 6eda0bec..2c4c4657 100644 --- a/src/User/src/Service/UserRoleServiceInterface.php +++ b/src/User/src/Service/UserRoleServiceInterface.php @@ -1,11 +1,13 @@ userRepository->findByUuid($uuid); } @@ -110,12 +108,11 @@ public function findByIdentity(string $identity): UserInterface * @param array $data * @return UserInterface * @throws Exception - * @throws ORMException */ public function createUser(array $data): UserInterface { if ($this->exists($data['email'])) { - throw new ORMException(Message::DUPLICATE_EMAIL); + throw new Exception(Message::DUPLICATE_EMAIL); } $user = new User(); @@ -159,13 +156,13 @@ public function createUser(array $data): UserInterface * @param User $user * @param array $data * @return UserInterface - * @throws ORMException + * @throws Exception */ public function updateUser(User $user, array $data = []): UserInterface { if (isset($data['email']) && !is_null($data['email'])) { if ($this->exists($data['email'], $user->getUuid()->toString())) { - throw new ORMException(Message::DUPLICATE_EMAIL); + throw new Exception(Message::DUPLICATE_EMAIL); } $user->setIdentity($data['email']); } @@ -235,8 +232,7 @@ public function updateUser(User $user, array $data = []): UserInterface */ protected function createAvatar(User $user, UploadedFile $uploadedFile): UserAvatar { - $path = $this->config['uploads']['user']['path'] . DIRECTORY_SEPARATOR; - $path .= $user->getUuid()->toString() . DIRECTORY_SEPARATOR; + $path = sprintf('%s/%s/', $this->config['uploads']['user']['path'], $user->getUuid()->toString()); if (!file_exists($path)) { mkdir($path, 0755); } @@ -336,23 +332,16 @@ public function findOneBy(array $params = []): ?User return null; } - /** @var User $user */ - $user = $this->userRepository->findOneBy($params); - - return $user; + return $this->userRepository->findOneBy($params); } /** * @param User $user * @return User - * @throws ORMException - * @throws OptimisticLockException */ public function activateUser(User $user): User { - $this->userRepository->saveUser($user->activate()); - - return $user; + return $this->userRepository->saveUser($user->activate()); } /** @@ -379,8 +368,6 @@ public function sendResetPasswordRequestedMail(User $user): bool /** * @param string|null $hash * @return User|null - * @throws \Doctrine\ORM\NoResultException - * @throws NonUniqueResultException */ public function findByResetPasswordHash(?string $hash): ?User { @@ -396,7 +383,7 @@ public function findByResetPasswordHash(?string $hash): ?User * @return bool * @throws MailException */ - public function sendResetPasswordCompletedMail(User $user) + public function sendResetPasswordCompletedMail(User $user): bool { $this->mailService->setBody( $this->templateRenderer->render('user::reset-password-completed', [ diff --git a/src/User/src/Service/UserServiceInterface.php b/src/User/src/Service/UserServiceInterface.php index bee16c2d..19f4c2dd 100644 --- a/src/User/src/Service/UserServiceInterface.php +++ b/src/User/src/Service/UserServiceInterface.php @@ -1,10 +1,10 @@