diff --git a/.gitignore b/.gitignore index 3207f032..26d99a43 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ clover.xml coveralls-upload.json phpunit.xml .phpcs-cache +.phpunit.result.cache # Created by .ignore support plugin (hsz.mobi) ### JetBrains template diff --git a/composer.json b/composer.json index a3c268fa..d2581462 100644 --- a/composer.json +++ b/composer.json @@ -91,11 +91,6 @@ "Frontend\\User\\": "src/User/src/" } }, - "autoload-dev": { - "psr-4": { - "AppTest\\": "test/AppTest/" - } - }, "scripts": { "post-create-project-cmd": [ "@development-enable" diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 5914fe36..fd16dfd8 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -3,8 +3,4 @@ xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true"> - - - - diff --git a/src/App/src/Common/TimestampAwareTrait.php b/src/App/src/Common/TimestampAwareTrait.php index ac50d3da..ed5ed911 100644 --- a/src/App/src/Common/TimestampAwareTrait.php +++ b/src/App/src/Common/TimestampAwareTrait.php @@ -86,8 +86,8 @@ public function touch(): void { try { $this->updated = new DateTimeImmutable(); - } catch (Exception) { - #TODO save the error message + } catch (Exception $exception) { + error_log($exception->getMessage()); } } } diff --git a/src/App/src/Factory/AuthMiddlewareFactory.php b/src/App/src/Factory/AuthMiddlewareFactory.php index 7ed28415..0993c532 100644 --- a/src/App/src/Factory/AuthMiddlewareFactory.php +++ b/src/App/src/Factory/AuthMiddlewareFactory.php @@ -24,13 +24,10 @@ class AuthMiddlewareFactory use AttachAuthorizationEventListenersTrait; /** - * @param ContainerInterface $container - * @param $requestedName - * @return AuthMiddleware * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ - public function __invoke(ContainerInterface $container, $requestedName): AuthMiddleware + public function __invoke(ContainerInterface $container, string $requestedName): AuthMiddleware { /** @var RbacGuardOptions $options */ $options = $container->get(RbacGuardOptions::class); diff --git a/src/App/src/RoutesDelegator.php b/src/App/src/RoutesDelegator.php index d3249476..5d6690c7 100644 --- a/src/App/src/RoutesDelegator.php +++ b/src/App/src/RoutesDelegator.php @@ -9,19 +9,9 @@ use Mezzio\Application; use Psr\Container\ContainerInterface; -/** - * Class RoutesDelegator - * @package Frontend\App - */ class RoutesDelegator { - /** - * @param ContainerInterface $container - * @param $serviceName - * @param callable $callback - * @return Application - */ - public function __invoke(ContainerInterface $container, $serviceName, callable $callback): Application + public function __invoke(ContainerInterface $container, string $serviceName, callable $callback): Application { /** @var Application $app */ $app = $callback(); diff --git a/src/App/src/Service/CookieService.php b/src/App/src/Service/CookieService.php index c8b3d43a..f5336a5b 100644 --- a/src/App/src/Service/CookieService.php +++ b/src/App/src/Service/CookieService.php @@ -20,8 +20,6 @@ class CookieService implements CookieServiceInterface private ConfigInterface $sessionConfig; /** - * @param SessionManager $sessionManager - * * @Inject({ * SessionManager::class * }) @@ -31,13 +29,7 @@ public function __construct(SessionManager $sessionManager) $this->sessionConfig = $sessionManager->getConfig(); } - /** - * @param string $name - * @param $value - * @param array|null $options - * @return bool - */ - public function setCookie(string $name, $value, ?array $options = []): bool + public function setCookie(string $name, mixed $value, ?array $options = []): bool { if (!$this->sessionConfig->getUseCookies()) { return false; @@ -46,10 +38,6 @@ public function setCookie(string $name, $value, ?array $options = []): bool return setcookie($name, $value, $this->getMergedOptions($options)); } - /** - * @param string $name - * @return bool - */ public function expireCookie(string $name): bool { return setcookie($name, '', $this->getMergedOptions([ @@ -58,8 +46,6 @@ public function expireCookie(string $name): bool } /** - * @param array|null $options - * @return array * @psalm-suppress UndefinedInterfaceMethod */ private function getMergedOptions(?array $options = []): array @@ -74,9 +60,6 @@ private function getMergedOptions(?array $options = []): array ]; } - /** - * @return int - */ private function getCookieLifetime(): int { return time() + $this->sessionConfig->getCookieLifetime(); diff --git a/src/App/src/Service/CookieServiceInterface.php b/src/App/src/Service/CookieServiceInterface.php index d83660d6..b7bfd1e1 100644 --- a/src/App/src/Service/CookieServiceInterface.php +++ b/src/App/src/Service/CookieServiceInterface.php @@ -10,17 +10,7 @@ */ interface CookieServiceInterface { - /** - * @param string $name - * @param $value - * @param array|null $options - * @return bool - */ - public function setCookie(string $name, $value, ?array $options = []): bool; + public function setCookie(string $name, mixed $value, ?array $options = []): bool; - /** - * @param string $name - * @return bool - */ public function expireCookie(string $name): bool; } diff --git a/src/App/src/Service/TranslateServiceInterface.php b/src/App/src/Service/TranslateServiceInterface.php index 414e3b1f..2929b240 100644 --- a/src/App/src/Service/TranslateServiceInterface.php +++ b/src/App/src/Service/TranslateServiceInterface.php @@ -13,5 +13,5 @@ interface TranslateServiceInterface /** * @param string $languageKey */ - public function addTranslatorCookie(string $languageKey); + public function addTranslatorCookie(string $languageKey): void; } diff --git a/src/Contact/src/RoutesDelegator.php b/src/Contact/src/RoutesDelegator.php index 922c924d..99433bbc 100644 --- a/src/Contact/src/RoutesDelegator.php +++ b/src/Contact/src/RoutesDelegator.php @@ -9,19 +9,9 @@ use Mezzio\Application; use Psr\Container\ContainerInterface; -/** - * Class RoutesDelegator - * @package Frontend\Contact - */ class RoutesDelegator { - /** - * @param ContainerInterface $container - * @param $serviceName - * @param callable $callback - * @return Application - */ - public function __invoke(ContainerInterface $container, $serviceName, callable $callback): Application + public function __invoke(ContainerInterface $container, string $serviceName, callable $callback): Application { /** @var Application $app */ $app = $callback(); diff --git a/src/Contact/src/Service/MessageService.php b/src/Contact/src/Service/MessageService.php index 10181586..f1a9c684 100644 --- a/src/Contact/src/Service/MessageService.php +++ b/src/Contact/src/Service/MessageService.php @@ -49,10 +49,7 @@ public function __construct( $this->config = $config; } - /** - * @return MessageRepository - */ - public function getRepository(): MessageRepository + public function getRepository(): MessageRepository|EntityRepository { return $this->repository; } @@ -100,30 +97,4 @@ public function sendContactMail(Message $message): bool return $this->mailService->send()->isValid(); } - - /** - * @param $response - * @return bool - */ - public function recaptchaIsValid($response): bool - { - $requestJson = [ - 'response' => $response, - 'secret' => $this->config['recaptcha']['secretKey'] - ]; - $url = 'https://www.google.com/recaptcha/api/siteverify'; - - $curl = curl_init(); - curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST"); - curl_setopt($curl, CURLOPT_POSTFIELDS, $requestJson); - curl_setopt($curl, CURLOPT_URL, $url); - curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); - - $checkRecaptchaResponse = curl_exec($curl); - $checkRecaptchaResponse = json_decode($checkRecaptchaResponse, true); - if ($checkRecaptchaResponse['success']) { - return true; - } - return false; - } } diff --git a/src/Contact/src/Service/MessageServiceInterface.php b/src/Contact/src/Service/MessageServiceInterface.php index b161a836..6f9ba79d 100644 --- a/src/Contact/src/Service/MessageServiceInterface.php +++ b/src/Contact/src/Service/MessageServiceInterface.php @@ -4,6 +4,7 @@ namespace Frontend\Contact\Service; +use Doctrine\ORM\EntityRepository; use Dot\Mail\Exception\MailException; use Frontend\Contact\Entity\Message; use Frontend\Contact\Repository\MessageRepository; @@ -14,10 +15,7 @@ */ interface MessageServiceInterface { - /** - * @return MessageRepository - */ - public function getRepository(): MessageRepository; + public function getRepository(): MessageRepository|EntityRepository; /** * @param array $data @@ -31,10 +29,4 @@ public function processMessage(array $data): bool; * @throws MailException */ public function sendContactMail(Message $message): bool; - - /** - * @param $response - * @return bool - */ - public function recaptchaIsValid($response): bool; } diff --git a/src/Page/src/RoutesDelegator.php b/src/Page/src/RoutesDelegator.php index 5c8df622..6dd970d9 100644 --- a/src/Page/src/RoutesDelegator.php +++ b/src/Page/src/RoutesDelegator.php @@ -9,19 +9,9 @@ use Mezzio\Application; use Psr\Container\ContainerInterface; -/** - * Class RoutesDelegator - * @package Frontend\Page - */ class RoutesDelegator { - /** - * @param ContainerInterface $container - * @param $serviceName - * @param callable $callback - * @return Application - */ - public function __invoke(ContainerInterface $container, $serviceName, callable $callback): Application + public function __invoke(ContainerInterface $container, string $serviceName, callable $callback): Application { /** @var Application $app */ $app = $callback(); diff --git a/src/Plugin/src/Factory/PluginManagerAwareInitializer.php b/src/Plugin/src/Factory/PluginManagerAwareInitializer.php index 7ba2cb8c..cbe9fcba 100644 --- a/src/Plugin/src/Factory/PluginManagerAwareInitializer.php +++ b/src/Plugin/src/Factory/PluginManagerAwareInitializer.php @@ -10,24 +10,18 @@ use Psr\Container\ContainerInterface; use Psr\Container\NotFoundExceptionInterface; -/** - * Class PluginManagerAwareInitializer - * @package Frontend\Plugin\Factory - */ class PluginManagerAwareInitializer { /** - * @param ContainerInterface $container - * @param $instance - * @return void * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ - public function __invoke(ContainerInterface $container, $instance): void + public function __invoke(ContainerInterface $container, ?object $instance): void { if ($instance instanceof PluginManagerAwareInterface) { - $pluginManager = $container->get(PluginManager::class); - $instance->setPluginManager($pluginManager); + $instance->setPluginManager( + $container->get(PluginManager::class) + ); } } } diff --git a/src/Plugin/src/TemplatePlugin.php b/src/Plugin/src/TemplatePlugin.php index 2acd6bf5..a9acaea6 100644 --- a/src/Plugin/src/TemplatePlugin.php +++ b/src/Plugin/src/TemplatePlugin.php @@ -53,7 +53,7 @@ public function render(string $templateName, array $params = []): string * @param string $param * @param mixed $value */ - public function addDefaultParam(string $templateName, string $param, mixed $value) + public function addDefaultParam(string $templateName, string $param, mixed $value): void { $this->template->addDefaultParam($templateName, $param, $value); } diff --git a/src/User/src/Adapter/AuthenticationAdapter.php b/src/User/src/Adapter/AuthenticationAdapter.php index b6ba7923..5d03616c 100644 --- a/src/User/src/Adapter/AuthenticationAdapter.php +++ b/src/User/src/Adapter/AuthenticationAdapter.php @@ -8,6 +8,7 @@ use Exception; use Frontend\User\Entity\User; use Frontend\User\Entity\UserIdentity; +use Frontend\User\Entity\UserInterface; use Frontend\User\Entity\UserRole; use Laminas\Authentication\Adapter\AbstractAdapter; use Laminas\Authentication\Adapter\AdapterInterface; @@ -124,7 +125,7 @@ public function authenticate(): Result /** * @throws Exception */ - private function validateConfig() + private function validateConfig(): void { if (!isset($this->config['identity_class']) || !class_exists($this->config['identity_class'])) { throw new Exception("Missing or invalid param 'identity_class' provided."); @@ -144,11 +145,9 @@ private function validateConfig() } /** - * @param $identityClass - * @param string $methodName * @throws Exception */ - private function checkMethod($identityClass, string $methodName): void + private function checkMethod(UserInterface $identityClass, string $methodName): void { if (!method_exists($identityClass, $methodName)) { throw new Exception(sprintf( diff --git a/src/User/src/Entity/UserAvatar.php b/src/User/src/Entity/UserAvatar.php index 6854b65a..51a4745c 100644 --- a/src/User/src/Entity/UserAvatar.php +++ b/src/User/src/Entity/UserAvatar.php @@ -67,10 +67,10 @@ public function getName(): string } /** - * @param $name + * @param string $name * @return self */ - public function setName($name): self + public function setName(string $name): self { $this->name = $name; diff --git a/src/User/src/Entity/UserDetail.php b/src/User/src/Entity/UserDetail.php index a40b94f0..69c4f980 100644 --- a/src/User/src/Entity/UserDetail.php +++ b/src/User/src/Entity/UserDetail.php @@ -68,10 +68,10 @@ public function getFirstName(): ?string } /** - * @param $firstName + * @param string $firstName * @return self */ - public function setFirstName($firstName): self + public function setFirstName(string $firstName): self { $this->firstName = $firstName; @@ -87,10 +87,10 @@ public function getLastName(): ?string } /** - * @param $lastName + * @param string $lastName * @return self */ - public function setLastName($lastName): self + public function setLastName(string $lastName): self { $this->lastName = $lastName; diff --git a/src/User/src/Entity/UserResetPassword.php b/src/User/src/Entity/UserResetPassword.php index 9fb5c15f..b5d48b55 100644 --- a/src/User/src/Entity/UserResetPassword.php +++ b/src/User/src/Entity/UserResetPassword.php @@ -107,10 +107,10 @@ public function getHash(): string } /** - * @param $hash + * @param string $hash * @return self */ - public function setHash($hash): self + public function setHash(string $hash): self { $this->hash = $hash; diff --git a/src/User/src/Repository/UserRepository.php b/src/User/src/Repository/UserRepository.php index 8e3d65ea..a91426f2 100644 --- a/src/User/src/Repository/UserRepository.php +++ b/src/User/src/Repository/UserRepository.php @@ -119,11 +119,11 @@ public function saveUserRememberMe(UserRememberMe $userRememberMe): void } /** - * @param $token + * @param string $token * @return UserRememberMe|null * @throws NonUniqueResultException */ - public function getRememberUser($token): ?UserRememberMe + public function getRememberUser(string $token): ?UserRememberMe { $qb = $this->getEntityManager()->createQueryBuilder(); $qb->select('user_remember_me') diff --git a/src/User/src/RoutesDelegator.php b/src/User/src/RoutesDelegator.php index af222427..65b875c2 100644 --- a/src/User/src/RoutesDelegator.php +++ b/src/User/src/RoutesDelegator.php @@ -10,19 +10,9 @@ use Mezzio\Application; use Psr\Container\ContainerInterface; -/** - * Class RoutesDelegator - * @package Frontend\User - */ class RoutesDelegator { - /** - * @param ContainerInterface $container - * @param $serviceName - * @param callable $callback - * @return Application - */ - public function __invoke(ContainerInterface $container, $serviceName, callable $callback): Application + public function __invoke(ContainerInterface $container, string $serviceName, callable $callback): Application { /** @var Application $app */ $app = $callback(); diff --git a/src/User/src/Service/UserService.php b/src/User/src/Service/UserService.php index 03317e84..4e20739a 100644 --- a/src/User/src/Service/UserService.php +++ b/src/User/src/Service/UserService.php @@ -391,10 +391,7 @@ public function sendResetPasswordCompletedMail(User $user): bool return $this->mailService->send()->isValid(); } - /** - * @return UserRepository - */ - public function getRepository(): UserRepository + public function getRepository(): UserRepository|EntityRepository { return $this->userRepository; } diff --git a/src/User/src/Service/UserServiceInterface.php b/src/User/src/Service/UserServiceInterface.php index 5c90c99b..93d478e7 100644 --- a/src/User/src/Service/UserServiceInterface.php +++ b/src/User/src/Service/UserServiceInterface.php @@ -4,6 +4,7 @@ namespace Frontend\User\Service; +use Doctrine\ORM\EntityRepository; use Doctrine\ORM\NonUniqueResultException; use Dot\Mail\Exception\MailException; use Exception; @@ -17,7 +18,6 @@ */ interface UserServiceInterface { - // TODO refactor this interface, it should only have CRUD methods. /** * @param array $data * @return UserInterface @@ -51,10 +51,7 @@ public function activateUser(User $user): User; */ public function findByUuid(string $uuid): ?User; - /** - * @return UserRepository - */ - public function getRepository(): UserRepository; + public function getRepository(): UserRepository|EntityRepository; /** * @param UserInterface|User $user diff --git a/test/AppTest/Handler/HomePageHandlerFactoryTest.php b/test/AppTest/Handler/HomePageHandlerFactoryTest.php deleted file mode 100644 index 8ea7badc..00000000 --- a/test/AppTest/Handler/HomePageHandlerFactoryTest.php +++ /dev/null @@ -1,54 +0,0 @@ -container = $this->prophesize(ContainerInterface::class); - $router = $this->prophesize(RouterInterface::class); - - $this->container->get(RouterInterface::class)->willReturn($router); - } - - public function testFactoryWithoutTemplate() - { - $factory = new HomePageHandlerFactory(); - $this->container->has(TemplateRendererInterface::class)->willReturn(false); - $this->container->has(\Mezzio\Template\TemplateRendererInterface::class)->willReturn(false); - - $this->assertInstanceOf(HomePageHandlerFactory::class, $factory); - - $homePage = $factory($this->container->reveal()); - - $this->assertInstanceOf(HomePageHandler::class, $homePage); - } - - public function testFactoryWithTemplate() - { - $this->container->has(TemplateRendererInterface::class)->willReturn(true); - $this->container - ->get(TemplateRendererInterface::class) - ->willReturn($this->prophesize(TemplateRendererInterface::class)); - - $factory = new HomePageHandlerFactory(); - - $homePage = $factory($this->container->reveal()); - - $this->assertInstanceOf(HomePageHandler::class, $homePage); - } -} diff --git a/test/AppTest/Handler/HomePageHandlerTest.php b/test/AppTest/Handler/HomePageHandlerTest.php deleted file mode 100644 index 27b0a2c6..00000000 --- a/test/AppTest/Handler/HomePageHandlerTest.php +++ /dev/null @@ -1,65 +0,0 @@ -container = $this->prophesize(ContainerInterface::class); - $this->router = $this->prophesize(RouterInterface::class); - } - - public function testReturnsJsonResponseWhenNoTemplateRendererProvided() - { - $homePage = new HomePageHandler( - get_class($this->container->reveal()), - $this->router->reveal(), - null - ); - $response = $homePage->handle( - $this->prophesize(ServerRequestInterface::class)->reveal() - ); - - $this->assertInstanceOf(JsonResponse::class, $response); - } - - public function testReturnsHtmlResponseWhenTemplateRendererProvided() - { - $renderer = $this->prophesize(TemplateRendererInterface::class); - $renderer - ->render('app::home-page', Argument::type('array')) - ->willReturn(''); - - $homePage = new HomePageHandler( - get_class($this->container->reveal()), - $this->router->reveal(), - $renderer->reveal() - ); - - $response = $homePage->handle( - $this->prophesize(ServerRequestInterface::class)->reveal() - ); - - $this->assertInstanceOf(HtmlResponse::class, $response); - } -} diff --git a/test/AppTest/Handler/PingHandlerTest.php b/test/AppTest/Handler/PingHandlerTest.php deleted file mode 100644 index 83d3aae2..00000000 --- a/test/AppTest/Handler/PingHandlerTest.php +++ /dev/null @@ -1,26 +0,0 @@ -handle( - $this->prophesize(ServerRequestInterface::class)->reveal() - ); - - $json = json_decode((string) $response->getBody()); - - $this->assertInstanceOf(JsonResponse::class, $response); - $this->assertTrue(isset($json->ack)); - } -}