diff --git a/src/CacheInvalidator.php b/src/CacheInvalidator.php index 1523d811..fe81a60d 100644 --- a/src/CacheInvalidator.php +++ b/src/CacheInvalidator.php @@ -61,13 +61,11 @@ class CacheInvalidator */ public const CLEAR = 'clear'; - private ProxyClient $cache; - private EventDispatcherInterface $eventDispatcher; - public function __construct(ProxyClient $cache) - { - $this->cache = $cache; + public function __construct( + private readonly ProxyClient $cache, + ) { } /** diff --git a/src/EventListener/LogListener.php b/src/EventListener/LogListener.php index a8031d68..55454356 100644 --- a/src/EventListener/LogListener.php +++ b/src/EventListener/LogListener.php @@ -22,11 +22,9 @@ */ class LogListener implements EventSubscriberInterface { - private LoggerInterface $logger; - - public function __construct(LoggerInterface $logger) - { - $this->logger = $logger; + public function __construct( + private readonly LoggerInterface $logger, + ) { } public static function getSubscribedEvents(): array diff --git a/src/ProxyClient/HttpProxyClient.php b/src/ProxyClient/HttpProxyClient.php index 7115fd16..10e77539 100644 --- a/src/ProxyClient/HttpProxyClient.php +++ b/src/ProxyClient/HttpProxyClient.php @@ -25,11 +25,6 @@ */ abstract class HttpProxyClient implements ProxyClient { - /** - * Dispatcher for invalidation HTTP requests. - */ - private Dispatcher $httpDispatcher; - private RequestFactoryInterface $requestFactory; private StreamFactoryInterface $streamFactory; @@ -43,7 +38,7 @@ abstract class HttpProxyClient implements ProxyClient /** * The base class has no options. * - * @param Dispatcher $dispatcher Helper to send instructions to the caching proxy + * @param Dispatcher $httpDispatcher Helper to send instructions to the caching proxy * @param array $options Options for this client * @param RequestFactoryInterface|null $requestFactory Factory for PSR-7 messages. If none supplied, * a default one is created @@ -51,12 +46,11 @@ abstract class HttpProxyClient implements ProxyClient * a default one is created */ public function __construct( - Dispatcher $dispatcher, + private readonly Dispatcher $httpDispatcher, array $options = [], ?RequestFactoryInterface $requestFactory = null, ?StreamFactoryInterface $streamFactory = null, ) { - $this->httpDispatcher = $dispatcher; $this->options = $this->configureOptions()->resolve($options); $this->requestFactory = $requestFactory ?: Psr17FactoryDiscovery::findRequestFactory(); $this->streamFactory = $streamFactory ?: Psr17FactoryDiscovery::findStreamFactory(); diff --git a/src/SymfonyCache/CacheEvent.php b/src/SymfonyCache/CacheEvent.php index 9de1c466..d94d94eb 100644 --- a/src/SymfonyCache/CacheEvent.php +++ b/src/SymfonyCache/CacheEvent.php @@ -23,28 +23,18 @@ */ class CacheEvent extends BaseEvent { - private CacheInvalidation $kernel; - - private Request $request; - - private ?Response $response; - - private int $requestType; - /** - * Make sure your $kernel implements CacheInvalidationInterface. - * - * @param CacheInvalidation $kernel the kernel raising with this event - * @param Request $request the request being processed - * @param Response|null $response the response, if available - * @param int $requestType the request type (default HttpKernelInterface::MAIN_REQUEST) + * Make sure your $kernel implements the CacheInvalidation interface. */ - public function __construct(CacheInvalidation $kernel, Request $request, ?Response $response = null, int $requestType = HttpKernelInterface::MAIN_REQUEST) - { - $this->kernel = $kernel; - $this->request = $request; - $this->response = $response; - $this->requestType = $requestType; + public function __construct( + /** + * The kernel raising this event. + */ + private readonly CacheInvalidation $kernel, + private readonly Request $request, + private ?Response $response = null, + private readonly int $requestType = HttpKernelInterface::MAIN_REQUEST, + ) { } /** diff --git a/src/SymfonyCache/CleanupCacheTagsListener.php b/src/SymfonyCache/CleanupCacheTagsListener.php index 16b65a1f..68f042e6 100644 --- a/src/SymfonyCache/CleanupCacheTagsListener.php +++ b/src/SymfonyCache/CleanupCacheTagsListener.php @@ -22,14 +22,12 @@ */ class CleanupCacheTagsListener implements EventSubscriberInterface { - private string $tagsHeader; - - /** - * @param string $tagsHeader The header that is used for cache tags - */ - public function __construct(string $tagsHeader = TagHeaderFormatter::DEFAULT_HEADER_NAME) - { - $this->tagsHeader = $tagsHeader; + public function __construct( + /** + * The header name for setting cache tags. + */ + private readonly string $tagsHeader = TagHeaderFormatter::DEFAULT_HEADER_NAME, + ) { } public function removeTagsHeader(CacheEvent $e): void diff --git a/src/SymfonyCache/CustomTtlListener.php b/src/SymfonyCache/CustomTtlListener.php index 8bad52a5..ffc72468 100644 --- a/src/SymfonyCache/CustomTtlListener.php +++ b/src/SymfonyCache/CustomTtlListener.php @@ -23,23 +23,21 @@ */ class CustomTtlListener implements EventSubscriberInterface { - private string $ttlHeader; - - private bool $keepTtlHeader; - /** * Header used for backing up the s-maxage. */ public const SMAXAGE_BACKUP = 'FOS-Smaxage-Backup'; - /** - * @param string $ttlHeader The header name that is used to specify the time to live - * @param bool $keepTtlHeader Keep the custom TTL header on the response for later usage (e.g. debugging) - */ - public function __construct(string $ttlHeader = 'X-Reverse-Proxy-TTL', bool $keepTtlHeader = false) - { - $this->ttlHeader = $ttlHeader; - $this->keepTtlHeader = $keepTtlHeader; + public function __construct( + /** + * The header name that is used to specify the time to live. + */ + private readonly string $ttlHeader = 'X-Reverse-Proxy-TTL', + /** + * Keep the custom TTL header on the response for later usage (e.g. debugging). + */ + private readonly bool $keepTtlHeader = false, + ) { } /** diff --git a/src/SymfonyCache/KernelDispatcher.php b/src/SymfonyCache/KernelDispatcher.php index c7a23a47..a0d6b8a0 100644 --- a/src/SymfonyCache/KernelDispatcher.php +++ b/src/SymfonyCache/KernelDispatcher.php @@ -32,16 +32,14 @@ */ class KernelDispatcher implements Dispatcher { - private HttpCacheProvider $httpCacheProvider; - /** * @var Request[] */ private array $queue = []; - public function __construct(HttpCacheProvider $httpCacheProvider) - { - $this->httpCacheProvider = $httpCacheProvider; + public function __construct( + private readonly HttpCacheProvider $httpCacheProvider, + ) { } public function invalidate(RequestInterface $invalidationRequest, bool $validateHost = true): void diff --git a/src/TagHeaderFormatter/CommaSeparatedTagHeaderFormatter.php b/src/TagHeaderFormatter/CommaSeparatedTagHeaderFormatter.php index cb34c1fb..f3cecb06 100644 --- a/src/TagHeaderFormatter/CommaSeparatedTagHeaderFormatter.php +++ b/src/TagHeaderFormatter/CommaSeparatedTagHeaderFormatter.php @@ -18,14 +18,10 @@ */ class CommaSeparatedTagHeaderFormatter implements TagHeaderFormatter, TagHeaderParser { - private string $headerName; - - private string $glue; - - public function __construct(string $headerName = TagHeaderFormatter::DEFAULT_HEADER_NAME, string $glue = ',') - { - $this->headerName = $headerName; - $this->glue = $glue; + public function __construct( + private readonly string $headerName = TagHeaderFormatter::DEFAULT_HEADER_NAME, + private readonly string $glue = ',', + ) { } public function getTagsHeaderName(): string diff --git a/src/TagHeaderFormatter/MaxHeaderValueLengthFormatter.php b/src/TagHeaderFormatter/MaxHeaderValueLengthFormatter.php index 5895f6b6..57efe849 100644 --- a/src/TagHeaderFormatter/MaxHeaderValueLengthFormatter.php +++ b/src/TagHeaderFormatter/MaxHeaderValueLengthFormatter.php @@ -23,20 +23,16 @@ */ class MaxHeaderValueLengthFormatter implements TagHeaderFormatter, TagHeaderParser { - private TagHeaderFormatter $inner; - - private int $maxHeaderValueLength; - /** * The default value of the maximum header length is 4096 because most * servers limit header values to 4kb. * HTTP messages cannot carry characters outside the ISO-8859-1 standard so they all * use up just one byte. */ - public function __construct(TagHeaderFormatter $inner, int $maxHeaderValueLength = 4096) - { - $this->inner = $inner; - $this->maxHeaderValueLength = $maxHeaderValueLength; + public function __construct( + private readonly TagHeaderFormatter $inner, + private readonly int $maxHeaderValueLength = 4096, + ) { } public function getTagsHeaderName(): string diff --git a/src/Test/HttpClient.php b/src/Test/HttpClient.php index b2bb2c16..af9d9048 100644 --- a/src/Test/HttpClient.php +++ b/src/Test/HttpClient.php @@ -28,18 +28,16 @@ class HttpClient */ private ClientInterface $httpClient; - private string $hostname; - - private string $port; - - /** - * @param string $hostname Default hostname if not specified in the URL - * @param string $port Default port if not specified in the URL - */ - public function __construct(string $hostname, string $port) - { - $this->hostname = $hostname; - $this->port = $port; + public function __construct( + /** + * Default hostname if not specified in the URL. + */ + private readonly string $hostname, + /** + * Default port if not specified in the URL. + */ + private readonly string $port, + ) { } /** diff --git a/src/Test/PHPUnit/AbstractCacheConstraint.php b/src/Test/PHPUnit/AbstractCacheConstraint.php index c61a8102..1d135884 100644 --- a/src/Test/PHPUnit/AbstractCacheConstraint.php +++ b/src/Test/PHPUnit/AbstractCacheConstraint.php @@ -16,11 +16,9 @@ abstract class AbstractCacheConstraint extends Constraint { - protected string $header; - - public function __construct(string $header = 'X-Cache') - { - $this->header = $header; + public function __construct( + protected string $header = 'X-Cache', + ) { } public function matches($other): bool