diff --git a/composer.json b/composer.json index 34e09a6..bc07192 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ { "name": "webfactory GmbH", "email": "info@webfactory.de", - "homepage": "http://www.webfactory.de", + "homepage": "https://www.webfactory.de", "role": "Developer" } ], diff --git a/phpunit.xml.dist b/phpunit.xml.dist index b6cf515..fcfc7c0 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,7 +1,7 @@ + xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"> tests diff --git a/src/NotModified/Attribute/ReplaceWithNotModifiedResponse.php b/src/NotModified/Attribute/ReplaceWithNotModifiedResponse.php index 2767abc..dc5486e 100644 --- a/src/NotModified/Attribute/ReplaceWithNotModifiedResponse.php +++ b/src/NotModified/Attribute/ReplaceWithNotModifiedResponse.php @@ -24,27 +24,17 @@ #[Attribute(Attribute::TARGET_METHOD)] final class ReplaceWithNotModifiedResponse { - /** @var array */ - private $parameters; - /** @var LastModifiedDeterminator[] */ - private $lastModifiedDeterminators; - - /** @var ContainerInterface */ - private $container; + private array $lastModifiedDeterminators; + private ContainerInterface $container; + private ?DateTime $lastModified = null; - /** @var DateTime|null */ - private $lastModified; - - public function __construct(array $parameters) - { - $this->parameters = $parameters; + public function __construct( + private readonly array $parameters, + ) { } - /** - * @return DateTime|null - */ - public function determineLastModified(Request $request) + public function determineLastModified(Request $request): ?DateTime { $this->initialiseLastModifiedDeterminators(); @@ -58,12 +48,12 @@ public function determineLastModified(Request $request) return $this->lastModified; } - public function setContainer(ContainerInterface $container) + public function setContainer(ContainerInterface $container): void { $this->container = $container; } - private function initialiseLastModifiedDeterminators() + private function initialiseLastModifiedDeterminators(): void { if (0 === count($this->parameters)) { throw new RuntimeException('The attribute '.get_class($this).' has to be parametrised with LastModifiedDeterminators.'); diff --git a/src/NotModified/EventListener.php b/src/NotModified/EventListener.php index 6d41933..cd6030a 100644 --- a/src/NotModified/EventListener.php +++ b/src/NotModified/EventListener.php @@ -24,27 +24,18 @@ */ final class EventListener { - /** @var ContainerInterface */ - private $container; - /** * Maps (master and sub) requests to their corresponding last modified date. This date is determined by the * ReplaceWithNotModifiedResponse annotation of the corresponding controller's action. - * - * @var SplObjectStorage */ - private $lastModified; + private SplObjectStorage $lastModified; - /** - * @var bool Symfony kernel.debug mode - */ - private $debug; - - public function __construct(ContainerInterface $container, bool $debug = false) - { - $this->container = $container; + public function __construct( + private readonly ContainerInterface $container, + // Symfony kernel.debug mode + private readonly bool $debug = false, + ) { $this->lastModified = new SplObjectStorage(); - $this->debug = $debug; } /** @@ -53,7 +44,7 @@ public function __construct(ContainerInterface $container, bool $debug = false) * header in the request, replace the determined controller action with a minimal action that just returns an * "empty" response with a 304 Not Modified HTTP status code. */ - public function onKernelController(ControllerEvent $event) + public function onKernelController(ControllerEvent $event): void { $annotation = $this->findAnnotation($event->getController()); if (!$annotation) { @@ -89,7 +80,7 @@ public function onKernelController(ControllerEvent $event) * If a last modified date was determined for the current (master or sub) request, set it to the response so the * client can use it for the "If-Modified-Since" header in subsequent requests. */ - public function onKernelResponse(ResponseEvent $event) + public function onKernelResponse(ResponseEvent $event): void { $request = $event->getRequest(); $response = $event->getResponse(); @@ -101,10 +92,8 @@ public function onKernelResponse(ResponseEvent $event) /** * @param $controllerCallable callable PHP callback pointing to the method to reflect on. - * - * @return ?ReplaceWithNotModifiedResponse The annotation, if found. Null otherwise. */ - private function findAnnotation(callable $controllerCallable) + private function findAnnotation(callable $controllerCallable): ?ReplaceWithNotModifiedResponse { if (!is_array($controllerCallable)) { return null; diff --git a/src/NotModified/services.xml b/src/NotModified/services.xml index 2380789..4b0e95b 100644 --- a/src/NotModified/services.xml +++ b/src/NotModified/services.xml @@ -2,7 +2,7 @@ + xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd"> diff --git a/tests/NotModified/Attribute/ReplaceWithNotModifiedResponseTest.php b/tests/NotModified/Attribute/ReplaceWithNotModifiedResponseTest.php index 1385ed7..99df1a4 100644 --- a/tests/NotModified/Attribute/ReplaceWithNotModifiedResponseTest.php +++ b/tests/NotModified/Attribute/ReplaceWithNotModifiedResponseTest.php @@ -117,15 +117,14 @@ final class FakeLastModifiedDeterminatorWithoutInterface final class MyLastModifedDeterminator implements LastModifiedDeterminator { - /** @var DateTime */ - private $lastModified; + private DateTime $lastModified; public function __construct(?DateTime $lastModified = null) { $this->lastModified = $lastModified ?: DateTime::createFromFormat('U', time()); } - public function getLastModified(Request $request) + public function getLastModified(Request $request): DateTime { return $this->lastModified; } diff --git a/tests/NotModified/EventListenerTest.php b/tests/NotModified/EventListenerTest.php index 2ee28ca..38e312f 100644 --- a/tests/NotModified/EventListenerTest.php +++ b/tests/NotModified/EventListenerTest.php @@ -33,27 +33,15 @@ final class EventListenerTest extends TestCase { /** * System under test. - * - * @var EventListener */ - private $eventListener; - - /** @var ContainerInterface|MockObject */ - private $container; - - /** @var ControllerEvent|MockObject */ - private $filterControllerEvent; - - /** @var Request */ - private $request; - - /** @var Response */ - private $response; + private EventListener $eventListener; + private ContainerInterface&MockObject $container; + private ControllerEvent|MockObject $filterControllerEvent; + private Request $request; + private Response $response; private $callable; - - /** @var KernelInterface|MockObject */ - private $kernel; + private KernelInterface&MockObject $kernel; protected function setUp(): void {