From 31ae54c5513235a0cb3d0689ee4d87f355742ce9 Mon Sep 17 00:00:00 2001 From: Urban Suppiger Date: Thu, 2 May 2024 08:54:14 +0200 Subject: [PATCH] fix: static typing and final classes (#621) * fix: static typing and final classes * remove legacy code in Configuration class --- .../Compiler/HashGeneratorPass.php | 4 +- .../Compiler/LoggerPass.php | 2 +- .../Compiler/SessionListenerPass.php | 2 +- src/DependencyInjection/Configuration.php | 56 ++++++------------- .../FOSHttpCacheExtension.php | 12 ++-- src/EventListener/AbstractRuleListener.php | 4 +- src/EventListener/AttributesListener.php | 2 +- src/EventListener/CacheControlListener.php | 8 +-- src/EventListener/InvalidationListener.php | 4 +- src/EventListener/SwitchUserListener.php | 2 +- src/EventListener/TagListener.php | 4 +- src/EventListener/UserContextListener.php | 6 +- src/Exception/InvalidTagException.php | 2 +- src/FOSHttpCacheBundle.php | 2 +- .../CacheableRequestMatcher.php | 2 +- .../QueryStringRequestMatcher.php | 2 +- .../RequestMatcher/UnsafeRequestMatcher.php | 2 +- .../CacheableResponseMatcher.php | 10 +++- .../ExpressionResponseMatcher.php | 2 +- .../NonErrorResponseMatcher.php | 2 +- src/Http/RuleMatcher.php | 16 ++---- ...ontextInvalidationSessionLogoutHandler.php | 2 +- src/Twig/CacheTagExtension.php | 4 +- src/UserContext/RequestMatcher.php | 8 +-- src/UserContext/RoleProvider.php | 2 +- src/UserContextInvalidator.php | 6 +- 26 files changed, 73 insertions(+), 95 deletions(-) diff --git a/src/DependencyInjection/Compiler/HashGeneratorPass.php b/src/DependencyInjection/Compiler/HashGeneratorPass.php index 84438b07..c5799902 100644 --- a/src/DependencyInjection/Compiler/HashGeneratorPass.php +++ b/src/DependencyInjection/Compiler/HashGeneratorPass.php @@ -19,9 +19,9 @@ /** * Add tagged provider to the hash generator for user context. */ -class HashGeneratorPass implements CompilerPassInterface +final class HashGeneratorPass implements CompilerPassInterface { - const TAG_NAME = 'fos_http_cache.user_context_provider'; + public const TAG_NAME = 'fos_http_cache.user_context_provider'; /** * {@inheritdoc} diff --git a/src/DependencyInjection/Compiler/LoggerPass.php b/src/DependencyInjection/Compiler/LoggerPass.php index d350b461..276217ab 100644 --- a/src/DependencyInjection/Compiler/LoggerPass.php +++ b/src/DependencyInjection/Compiler/LoggerPass.php @@ -17,7 +17,7 @@ /** * Announce the log listener to the symfony event system. */ -class LoggerPass implements CompilerPassInterface +final class LoggerPass implements CompilerPassInterface { /** * {@inheritdoc} diff --git a/src/DependencyInjection/Compiler/SessionListenerPass.php b/src/DependencyInjection/Compiler/SessionListenerPass.php index 1eb7b137..97b5843d 100644 --- a/src/DependencyInjection/Compiler/SessionListenerPass.php +++ b/src/DependencyInjection/Compiler/SessionListenerPass.php @@ -20,7 +20,7 @@ * AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER from being leaked to * the client. */ -class SessionListenerPass implements CompilerPassInterface +final class SessionListenerPass implements CompilerPassInterface { /** * {@inheritdoc} diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 80e093d5..255615fd 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -18,7 +18,6 @@ use JeanBeru\HttpCacheCloudFront\Proxy\CloudFront; use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; use Symfony\Component\Config\Definition\Builder\NodeBuilder; -use Symfony\Component\Config\Definition\Builder\NodeDefinition; use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\ConfigurationInterface; use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; @@ -34,7 +33,7 @@ * @author David de Boer * @author David Buchmann */ -class Configuration implements ConfigurationInterface +final class Configuration implements ConfigurationInterface { /** * @var bool @@ -55,13 +54,7 @@ public function __construct($debug) public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('fos_http_cache'); - - // Keep compatibility with symfony/config < 4.2 - if (!method_exists($treeBuilder, 'getRootNode')) { - $rootNode = $treeBuilder->root('fos_http_cache'); - } else { - $rootNode = $treeBuilder->getRootNode(); - } + $rootNode = $treeBuilder->getRootNode(); $rootNode ->validate() @@ -240,7 +233,7 @@ private function isFastly(array $v): bool && array_key_exists('fastly', $v['proxy_client']); } - private function addCacheableResponseSection(ArrayNodeDefinition $rootNode) + private function addCacheableResponseSection(ArrayNodeDefinition $rootNode): void { $rootNode ->children() @@ -278,7 +271,7 @@ private function addCacheableResponseSection(ArrayNodeDefinition $rootNode) /** * Cache header control main section. */ - private function addCacheControlSection(ArrayNodeDefinition $rootNode) + private function addCacheControlSection(ArrayNodeDefinition $rootNode): void { $rules = $rootNode ->children() @@ -366,7 +359,7 @@ private function addCacheControlSection(ArrayNodeDefinition $rootNode) * * @param bool $matchResponse whether to also add fields to match response */ - private function addMatch(NodeBuilder $rules, $matchResponse = false) + private function addMatch(NodeBuilder $rules, $matchResponse = false): void { $match = $rules ->arrayNode('match') @@ -610,19 +603,11 @@ private function addProxyClientSection(ArrayNodeDefinition $rootNode): void /** * Get the configuration node for a HTTP dispatcher in a proxy client. - * - * @return NodeDefinition */ - private function getHttpDispatcherNode() + private function getHttpDispatcherNode(): ArrayNodeDefinition { $treeBuilder = new TreeBuilder('http'); - - // Keep compatibility with symfony/config < 4.2 - if (!method_exists($treeBuilder, 'getRootNode')) { - $node = $treeBuilder->root('http'); - } else { - $node = $treeBuilder->getRootNode(); - } + $node = $treeBuilder->getRootNode(); $node ->fixXmlConfig('server') @@ -650,16 +635,10 @@ private function getHttpDispatcherNode() return $node; } - private function getCloudflareHttpDispatcherNode() + private function getCloudflareHttpDispatcherNode(): ArrayNodeDefinition { $treeBuilder = new TreeBuilder('http'); - - // Keep compatibility with symfony/config < 4.2 - if (!method_exists($treeBuilder, 'getRootNode')) { - $node = $treeBuilder->root('http'); - } else { - $node = $treeBuilder->getRootNode(); - } + $node = $treeBuilder->getRootNode(); $node ->addDefaultsIfNotSet() @@ -680,10 +659,9 @@ private function getCloudflareHttpDispatcherNode() return $node; } - private function getFastlyHttpDispatcherNode() + private function getFastlyHttpDispatcherNode(): ArrayNodeDefinition { $treeBuilder = new TreeBuilder('http'); - $node = $treeBuilder->getRootNode(); $node @@ -709,7 +687,7 @@ private function getFastlyHttpDispatcherNode() return $node; } - private function addTestSection(ArrayNodeDefinition $rootNode) + private function addTestSection(ArrayNodeDefinition $rootNode): void { $rootNode ->children() @@ -752,7 +730,7 @@ private function addTestSection(ArrayNodeDefinition $rootNode) /** * Cache manager main section. */ - private function addCacheManagerSection(ArrayNodeDefinition $rootNode) + private function addCacheManagerSection(ArrayNodeDefinition $rootNode): void { $rootNode ->children() @@ -792,7 +770,7 @@ private function addCacheManagerSection(ArrayNodeDefinition $rootNode) ; } - private function addTagSection(ArrayNodeDefinition $rootNode) + private function addTagSection(ArrayNodeDefinition $rootNode): void { $rules = $rootNode ->children() @@ -848,7 +826,7 @@ private function addTagSection(ArrayNodeDefinition $rootNode) ; } - private function addInvalidationSection(ArrayNodeDefinition $rootNode) + private function addInvalidationSection(ArrayNodeDefinition $rootNode): void { $rules = $rootNode ->children() @@ -889,7 +867,7 @@ private function addInvalidationSection(ArrayNodeDefinition $rootNode) /** * User context main section. */ - private function addUserContextListenerSection(ArrayNodeDefinition $rootNode) + private function addUserContextListenerSection(ArrayNodeDefinition $rootNode): void { $rootNode ->children() @@ -958,7 +936,7 @@ private function addUserContextListenerSection(ArrayNodeDefinition $rootNode) ; } - private function addFlashMessageSection(ArrayNodeDefinition $rootNode) + private function addFlashMessageSection(ArrayNodeDefinition $rootNode): void { $rootNode ->children() @@ -988,7 +966,7 @@ private function addFlashMessageSection(ArrayNodeDefinition $rootNode) ->end(); } - private function addDebugSection(ArrayNodeDefinition $rootNode) + private function addDebugSection(ArrayNodeDefinition $rootNode): void { $rootNode ->children() diff --git a/src/DependencyInjection/FOSHttpCacheExtension.php b/src/DependencyInjection/FOSHttpCacheExtension.php index 8595b751..c2e281b3 100644 --- a/src/DependencyInjection/FOSHttpCacheExtension.php +++ b/src/DependencyInjection/FOSHttpCacheExtension.php @@ -31,7 +31,7 @@ use Symfony\Component\HttpKernel\Kernel; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; -class FOSHttpCacheExtension extends Extension +final class FOSHttpCacheExtension extends Extension { public function getConfiguration(array $config, ContainerBuilder $container): ConfigurationInterface { @@ -579,7 +579,7 @@ private function loadProxyServer(ContainerBuilder $container, XmlFileLoader $loa ); } - private function loadVarnishProxyServer(ContainerBuilder $container, XmlFileLoader $loader, $config): void + private function loadVarnishProxyServer(ContainerBuilder $container, XmlFileLoader $loader, array $config): void { $loader->load('varnish_proxy.xml'); foreach ($config as $key => $value) { @@ -590,7 +590,7 @@ private function loadVarnishProxyServer(ContainerBuilder $container, XmlFileLoad } } - private function loadNginxProxyServer(ContainerBuilder $container, XmlFileLoader $loader, $config): void + private function loadNginxProxyServer(ContainerBuilder $container, XmlFileLoader $loader, array $config): void { $loader->load('nginx_proxy.xml'); foreach ($config as $key => $value) { @@ -627,7 +627,7 @@ private function loadInvalidatorRules(ContainerBuilder $container, array $config } } - private function validateUrl($url, $msg): void + private function validateUrl(string $url, string $msg): void { $prefixed = $this->prefixSchema($url); @@ -636,7 +636,7 @@ private function validateUrl($url, $msg): void } } - private function prefixSchema($url) + private function prefixSchema(string $url): string { if (!str_contains($url, '://')) { $url = sprintf('%s://%s', 'http', $url); @@ -645,7 +645,7 @@ private function prefixSchema($url) return $url; } - private function getDefaultProxyClient(array $config) + private function getDefaultProxyClient(array $config): string { if (isset($config['default'])) { return $config['default']; diff --git a/src/EventListener/AbstractRuleListener.php b/src/EventListener/AbstractRuleListener.php index 041c48bc..a68b5c21 100644 --- a/src/EventListener/AbstractRuleListener.php +++ b/src/EventListener/AbstractRuleListener.php @@ -31,7 +31,7 @@ abstract class AbstractRuleListener public function addRule( RequestMatcherInterface $requestMatcher, array $settings = [] - ) { + ): void { $this->rulesMap[] = [$requestMatcher, $settings]; } @@ -40,7 +40,7 @@ public function addRule( * * @return array|false Settings to apply or false if no rule matched */ - protected function matchRule(Request $request) + protected function matchRule(Request $request): array|false { foreach ($this->rulesMap as $elements) { if ($elements[0]->matches($request)) { diff --git a/src/EventListener/AttributesListener.php b/src/EventListener/AttributesListener.php index 92382344..0991c817 100644 --- a/src/EventListener/AttributesListener.php +++ b/src/EventListener/AttributesListener.php @@ -15,7 +15,7 @@ * * @author Yoann Chocteau */ -class AttributesListener implements EventSubscriberInterface +final class AttributesListener implements EventSubscriberInterface { public function __construct( private ControllerResolverInterface $controllerResolver diff --git a/src/EventListener/CacheControlListener.php b/src/EventListener/CacheControlListener.php index 3ccb4e2d..87f08c18 100644 --- a/src/EventListener/CacheControlListener.php +++ b/src/EventListener/CacheControlListener.php @@ -26,7 +26,7 @@ * @author Lea Haensenberger * @author David Buchmann */ -class CacheControlListener implements EventSubscriberInterface +final class CacheControlListener implements EventSubscriberInterface { /** * Whether to skip this response and not set any cache headers. @@ -52,7 +52,7 @@ class CacheControlListener implements EventSubscriberInterface * If not empty, add a debug header with that name to all responses, * telling the cache proxy to add debug output. * - * @var string|bool Name of the header or false to add no header + * @var string|false Name of the header or false to add no header */ private string|false $debugHeader; @@ -96,7 +96,7 @@ public function onKernelResponse(ResponseEvent $event): void $response = $event->getResponse(); if ($this->debugHeader) { - $response->headers->set($this->debugHeader, 1, false); + $response->headers->set($this->debugHeader, '1', false); } // do not change cache directives on non-cacheable requests. @@ -125,7 +125,7 @@ public function onKernelResponse(ResponseEvent $event): void && null !== $options['reverse_proxy_ttl'] && !$response->headers->has('X-Reverse-Proxy-TTL') ) { - $response->headers->set('X-Reverse-Proxy-TTL', (int) $options['reverse_proxy_ttl'], false); + $response->headers->set('X-Reverse-Proxy-TTL', $options['reverse_proxy_ttl'], false); } if (!empty($options['vary'])) { diff --git a/src/EventListener/InvalidationListener.php b/src/EventListener/InvalidationListener.php index 019f7b0e..7ac5a976 100644 --- a/src/EventListener/InvalidationListener.php +++ b/src/EventListener/InvalidationListener.php @@ -33,7 +33,7 @@ * * @author David de Boer */ -class InvalidationListener extends AbstractRuleListener implements EventSubscriberInterface +final class InvalidationListener extends AbstractRuleListener implements EventSubscriberInterface { private CacheManager $cacheManager; private UrlGeneratorInterface $urlGenerator; @@ -136,7 +136,7 @@ private function handleInvalidation(Request $request, Response $response): void } // Check configured invalidators - if (!$invalidatorConfigs = $this->matchRule($request, $response)) { + if (!$invalidatorConfigs = $this->matchRule($request)) { return; } diff --git a/src/EventListener/SwitchUserListener.php b/src/EventListener/SwitchUserListener.php index 00f0a1bc..1749a540 100644 --- a/src/EventListener/SwitchUserListener.php +++ b/src/EventListener/SwitchUserListener.php @@ -16,7 +16,7 @@ use Symfony\Component\Security\Http\Event\SwitchUserEvent; use Symfony\Component\Security\Http\SecurityEvents; -class SwitchUserListener implements EventSubscriberInterface +final class SwitchUserListener implements EventSubscriberInterface { private UserContextInvalidator $invalidator; diff --git a/src/EventListener/TagListener.php b/src/EventListener/TagListener.php index 61ccfbd0..096423ca 100644 --- a/src/EventListener/TagListener.php +++ b/src/EventListener/TagListener.php @@ -27,7 +27,7 @@ * * @author David de Boer */ -class TagListener extends AbstractRuleListener implements EventSubscriberInterface +final class TagListener extends AbstractRuleListener implements EventSubscriberInterface { private CacheManager $cacheManager; private SymfonyResponseTagger $symfonyResponseTagger; @@ -108,7 +108,7 @@ public static function getSubscribedEvents(): array * Get the tags from the attributes on the controller that was used in the * request. * - * @return array List of tags affected by the request + * @return string[] List of tags affected by the request */ private function getAttributeTags(Request $request): array { diff --git a/src/EventListener/UserContextListener.php b/src/EventListener/UserContextListener.php index e49d9db5..e9b85d50 100644 --- a/src/EventListener/UserContextListener.php +++ b/src/EventListener/UserContextListener.php @@ -34,7 +34,7 @@ * @author Stefan Paschke * @author Joel Wurtz */ -class UserContextListener implements EventSubscriberInterface +final class UserContextListener implements EventSubscriberInterface { private RequestMatcherInterface $requestMatcher; private HashGenerator $hashGenerator; @@ -136,7 +136,7 @@ public function onKernelRequest(RequestEvent $event): void $response->setPublic(); if ($this->hasSessionListener) { // header to avoid Symfony SessionListener overwriting the response to private - $response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER, 1); + $response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER, '1'); } } else { $response->setClientTtl(0); @@ -201,7 +201,7 @@ public function onKernelResponse(ResponseEvent $event): void // user hash header was in vary or just added here by "add_vary_on_hash" if ($this->hasSessionListener && in_array($this->options['user_hash_header'], $vary, true)) { // header to avoid Symfony SessionListener overwriting the response to private - $response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER, 1); + $response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER, '1'); } } elseif ($this->options['add_vary_on_hash']) { /* diff --git a/src/Exception/InvalidTagException.php b/src/Exception/InvalidTagException.php index fcebbb4a..6906ba28 100644 --- a/src/Exception/InvalidTagException.php +++ b/src/Exception/InvalidTagException.php @@ -13,7 +13,7 @@ class InvalidTagException extends \InvalidArgumentException { - public function __construct($tag, $char) + public function __construct(string $tag, string $char) { parent::__construct(sprintf('Tag %s is invalid because it contains %s', $tag, $char)); } diff --git a/src/FOSHttpCacheBundle.php b/src/FOSHttpCacheBundle.php index d94b7dd4..3ab3dd14 100644 --- a/src/FOSHttpCacheBundle.php +++ b/src/FOSHttpCacheBundle.php @@ -18,7 +18,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Bundle\Bundle; -class FOSHttpCacheBundle extends Bundle +final class FOSHttpCacheBundle extends Bundle { /** * {@inheritdoc} diff --git a/src/Http/RequestMatcher/CacheableRequestMatcher.php b/src/Http/RequestMatcher/CacheableRequestMatcher.php index 95552751..0889f690 100644 --- a/src/Http/RequestMatcher/CacheableRequestMatcher.php +++ b/src/Http/RequestMatcher/CacheableRequestMatcher.php @@ -17,7 +17,7 @@ /** * @see https://tools.ietf.org/html/rfc7231#section-4.2.3 */ -class CacheableRequestMatcher implements RequestMatcherInterface +final class CacheableRequestMatcher implements RequestMatcherInterface { public function matches(Request $request): bool { diff --git a/src/Http/RequestMatcher/QueryStringRequestMatcher.php b/src/Http/RequestMatcher/QueryStringRequestMatcher.php index 8b85ec52..c28f4d4b 100644 --- a/src/Http/RequestMatcher/QueryStringRequestMatcher.php +++ b/src/Http/RequestMatcher/QueryStringRequestMatcher.php @@ -17,7 +17,7 @@ /** * Additional request matcher for query string matching. */ -class QueryStringRequestMatcher implements RequestMatcherInterface +final class QueryStringRequestMatcher implements RequestMatcherInterface { /** * @var string Regular expression to match the query string part of the request url diff --git a/src/Http/RequestMatcher/UnsafeRequestMatcher.php b/src/Http/RequestMatcher/UnsafeRequestMatcher.php index 718a261f..43cc80a8 100644 --- a/src/Http/RequestMatcher/UnsafeRequestMatcher.php +++ b/src/Http/RequestMatcher/UnsafeRequestMatcher.php @@ -14,7 +14,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestMatcherInterface; -class UnsafeRequestMatcher implements RequestMatcherInterface +final class UnsafeRequestMatcher implements RequestMatcherInterface { public function matches(Request $request): bool { diff --git a/src/Http/ResponseMatcher/CacheableResponseMatcher.php b/src/Http/ResponseMatcher/CacheableResponseMatcher.php index 371cfe81..df52b58f 100644 --- a/src/Http/ResponseMatcher/CacheableResponseMatcher.php +++ b/src/Http/ResponseMatcher/CacheableResponseMatcher.php @@ -18,15 +18,21 @@ * * @see https://tools.ietf.org/html/rfc7231#section-6.1 */ -class CacheableResponseMatcher implements ResponseMatcherInterface +final class CacheableResponseMatcher implements ResponseMatcherInterface { - private $cacheableStatusCodes = [ + /** + * @var int[] + */ + private array $cacheableStatusCodes = [ 200, 203, 204, 206, 300, 301, 404, 405, 410, 414, 501, ]; + /** + * @param int[] $additionalStatusCodes + */ public function __construct(array $additionalStatusCodes = []) { $this->cacheableStatusCodes = array_merge( diff --git a/src/Http/ResponseMatcher/ExpressionResponseMatcher.php b/src/Http/ResponseMatcher/ExpressionResponseMatcher.php index 3a5c5bc2..6c2eee5b 100644 --- a/src/Http/ResponseMatcher/ExpressionResponseMatcher.php +++ b/src/Http/ResponseMatcher/ExpressionResponseMatcher.php @@ -14,7 +14,7 @@ use Symfony\Component\ExpressionLanguage\ExpressionLanguage; use Symfony\Component\HttpFoundation\Response; -class ExpressionResponseMatcher implements ResponseMatcherInterface +final class ExpressionResponseMatcher implements ResponseMatcherInterface { private ?ExpressionLanguage $expressionLanguage; private string $expression; diff --git a/src/Http/ResponseMatcher/NonErrorResponseMatcher.php b/src/Http/ResponseMatcher/NonErrorResponseMatcher.php index 4cbeb70f..8fc17eee 100644 --- a/src/Http/ResponseMatcher/NonErrorResponseMatcher.php +++ b/src/Http/ResponseMatcher/NonErrorResponseMatcher.php @@ -19,7 +19,7 @@ * * @see https://tools.ietf.org/html/rfc7234#section-4.4 */ -class NonErrorResponseMatcher implements ResponseMatcherInterface +final class NonErrorResponseMatcher implements ResponseMatcherInterface { public function matches(Response $response) { diff --git a/src/Http/RuleMatcher.php b/src/Http/RuleMatcher.php index 9627d8e9..f31b1d56 100644 --- a/src/Http/RuleMatcher.php +++ b/src/Http/RuleMatcher.php @@ -23,25 +23,19 @@ * * @author David Buchmann */ -class RuleMatcher implements RuleMatcherInterface +final class RuleMatcher implements RuleMatcherInterface { - /** - * @var RequestMatcherInterface - */ - private $requestMatcher; + private ?RequestMatcherInterface $requestMatcher; - /** - * @var ResponseMatcherInterface - */ - private $responseMatcher; + private ?ResponseMatcherInterface $responseMatcher; /** * @param RequestMatcherInterface $requestMatcher|null Request matcher * @param ResponseMatcherInterface $responseMatcher|null Response matcher */ public function __construct( - RequestMatcherInterface $requestMatcher = null, - ResponseMatcherInterface $responseMatcher = null + ?RequestMatcherInterface $requestMatcher = null, + ?ResponseMatcherInterface $responseMatcher = null ) { $this->requestMatcher = $requestMatcher; $this->responseMatcher = $responseMatcher; diff --git a/src/Security/Http/Logout/ContextInvalidationSessionLogoutHandler.php b/src/Security/Http/Logout/ContextInvalidationSessionLogoutHandler.php index 5c48d6b7..5955f955 100644 --- a/src/Security/Http/Logout/ContextInvalidationSessionLogoutHandler.php +++ b/src/Security/Http/Logout/ContextInvalidationSessionLogoutHandler.php @@ -17,7 +17,7 @@ final class ContextInvalidationSessionLogoutHandler extends SessionLogoutListener { - private $invalidator; + private UserContextInvalidator $invalidator; public function __construct(UserContextInvalidator $invalidator) { diff --git a/src/Twig/CacheTagExtension.php b/src/Twig/CacheTagExtension.php index 8cd3c6fd..a62831a2 100644 --- a/src/Twig/CacheTagExtension.php +++ b/src/Twig/CacheTagExtension.php @@ -48,9 +48,9 @@ public function getFunctions(): array * * Calling this twig function adds nothing to the output. * - * @param string|array $tag + * @param string|string[] $tag */ - public function addTag($tag) + public function addTag($tag): void { $this->responseTagger->addTags((array) $tag); } diff --git a/src/UserContext/RequestMatcher.php b/src/UserContext/RequestMatcher.php index 9e552781..0df9f1b6 100644 --- a/src/UserContext/RequestMatcher.php +++ b/src/UserContext/RequestMatcher.php @@ -14,13 +14,13 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestMatcherInterface; -class RequestMatcher implements RequestMatcherInterface +final class RequestMatcher implements RequestMatcherInterface { - private $method; + private ?string $method; - private $accept; + private ?string $accept; - public function __construct($accept = 'application/vnd.fos.user-context-hash', $method = null) + public function __construct(?string $accept = 'application/vnd.fos.user-context-hash', ?string $method = null) { $this->accept = $accept; $this->method = $method; diff --git a/src/UserContext/RoleProvider.php b/src/UserContext/RoleProvider.php index d5dfd4ec..ef78946c 100644 --- a/src/UserContext/RoleProvider.php +++ b/src/UserContext/RoleProvider.php @@ -20,7 +20,7 @@ /** * The RoleProvider adds roles to the UserContext for the hash generation. */ -class RoleProvider implements ContextProvider +final class RoleProvider implements ContextProvider { /** * Create the role provider with a security context. diff --git a/src/UserContextInvalidator.php b/src/UserContextInvalidator.php index eaba4855..a7396b32 100644 --- a/src/UserContextInvalidator.php +++ b/src/UserContextInvalidator.php @@ -15,7 +15,7 @@ class UserContextInvalidator { - const USER_CONTEXT_TAG_PREFIX = 'fos_http_cache_hashlookup-'; + public const USER_CONTEXT_TAG_PREFIX = 'fos_http_cache_hashlookup-'; /** * @var TagCapable @@ -32,12 +32,12 @@ public function __construct(TagCapable $tagger) * * @param string $sessionId */ - public function invalidateContext($sessionId) + public function invalidateContext($sessionId): void { $this->tagger->invalidateTags([static::buildTag($sessionId)]); } - public static function buildTag($hash) + public static function buildTag(string $hash): string { return static::USER_CONTEXT_TAG_PREFIX.$hash; }