Skip to content

Commit 0fd2112

Browse files
authored
Merge pull request #573 from FriendsOfSymfony/cs
strict types and constructor argument promotion
2 parents 064ab07 + d682faa commit 0fd2112

File tree

11 files changed

+58
-96
lines changed

11 files changed

+58
-96
lines changed

src/CacheInvalidator.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,11 @@ class CacheInvalidator
6161
*/
6262
public const CLEAR = 'clear';
6363

64-
private ProxyClient $cache;
65-
6664
private EventDispatcherInterface $eventDispatcher;
6765

68-
public function __construct(ProxyClient $cache)
69-
{
70-
$this->cache = $cache;
66+
public function __construct(
67+
private readonly ProxyClient $cache,
68+
) {
7169
}
7270

7371
/**

src/EventListener/LogListener.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@
2222
*/
2323
class LogListener implements EventSubscriberInterface
2424
{
25-
private LoggerInterface $logger;
26-
27-
public function __construct(LoggerInterface $logger)
28-
{
29-
$this->logger = $logger;
25+
public function __construct(
26+
private readonly LoggerInterface $logger,
27+
) {
3028
}
3129

3230
public static function getSubscribedEvents(): array

src/ProxyClient/HttpProxyClient.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@
2525
*/
2626
abstract class HttpProxyClient implements ProxyClient
2727
{
28-
/**
29-
* Dispatcher for invalidation HTTP requests.
30-
*/
31-
private Dispatcher $httpDispatcher;
32-
3328
private RequestFactoryInterface $requestFactory;
3429
private StreamFactoryInterface $streamFactory;
3530

@@ -43,20 +38,19 @@ abstract class HttpProxyClient implements ProxyClient
4338
/**
4439
* The base class has no options.
4540
*
46-
* @param Dispatcher $dispatcher Helper to send instructions to the caching proxy
41+
* @param Dispatcher $httpDispatcher Helper to send instructions to the caching proxy
4742
* @param array $options Options for this client
4843
* @param RequestFactoryInterface|null $requestFactory Factory for PSR-7 messages. If none supplied,
4944
* a default one is created
5045
* @param StreamFactoryInterface|null $streamFactory Factory for PSR-7 streams. If none supplied,
5146
* a default one is created
5247
*/
5348
public function __construct(
54-
Dispatcher $dispatcher,
49+
private readonly Dispatcher $httpDispatcher,
5550
array $options = [],
5651
?RequestFactoryInterface $requestFactory = null,
5752
?StreamFactoryInterface $streamFactory = null,
5853
) {
59-
$this->httpDispatcher = $dispatcher;
6054
$this->options = $this->configureOptions()->resolve($options);
6155
$this->requestFactory = $requestFactory ?: Psr17FactoryDiscovery::findRequestFactory();
6256
$this->streamFactory = $streamFactory ?: Psr17FactoryDiscovery::findStreamFactory();

src/SymfonyCache/CacheEvent.php

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,18 @@
2323
*/
2424
class CacheEvent extends BaseEvent
2525
{
26-
private CacheInvalidation $kernel;
27-
28-
private Request $request;
29-
30-
private ?Response $response;
31-
32-
private int $requestType;
33-
3426
/**
35-
* Make sure your $kernel implements CacheInvalidationInterface.
36-
*
37-
* @param CacheInvalidation $kernel the kernel raising with this event
38-
* @param Request $request the request being processed
39-
* @param Response|null $response the response, if available
40-
* @param int $requestType the request type (default HttpKernelInterface::MAIN_REQUEST)
27+
* Make sure your $kernel implements the CacheInvalidation interface.
4128
*/
42-
public function __construct(CacheInvalidation $kernel, Request $request, ?Response $response = null, int $requestType = HttpKernelInterface::MAIN_REQUEST)
43-
{
44-
$this->kernel = $kernel;
45-
$this->request = $request;
46-
$this->response = $response;
47-
$this->requestType = $requestType;
29+
public function __construct(
30+
/**
31+
* The kernel raising this event.
32+
*/
33+
private readonly CacheInvalidation $kernel,
34+
private readonly Request $request,
35+
private ?Response $response = null,
36+
private readonly int $requestType = HttpKernelInterface::MAIN_REQUEST,
37+
) {
4838
}
4939

5040
/**

src/SymfonyCache/CleanupCacheTagsListener.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,12 @@
2222
*/
2323
class CleanupCacheTagsListener implements EventSubscriberInterface
2424
{
25-
private string $tagsHeader;
26-
27-
/**
28-
* @param string $tagsHeader The header that is used for cache tags
29-
*/
30-
public function __construct(string $tagsHeader = TagHeaderFormatter::DEFAULT_HEADER_NAME)
31-
{
32-
$this->tagsHeader = $tagsHeader;
25+
public function __construct(
26+
/**
27+
* The header name for setting cache tags.
28+
*/
29+
private readonly string $tagsHeader = TagHeaderFormatter::DEFAULT_HEADER_NAME,
30+
) {
3331
}
3432

3533
public function removeTagsHeader(CacheEvent $e): void

src/SymfonyCache/CustomTtlListener.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,21 @@
2323
*/
2424
class CustomTtlListener implements EventSubscriberInterface
2525
{
26-
private string $ttlHeader;
27-
28-
private bool $keepTtlHeader;
29-
3026
/**
3127
* Header used for backing up the s-maxage.
3228
*/
3329
public const SMAXAGE_BACKUP = 'FOS-Smaxage-Backup';
3430

35-
/**
36-
* @param string $ttlHeader The header name that is used to specify the time to live
37-
* @param bool $keepTtlHeader Keep the custom TTL header on the response for later usage (e.g. debugging)
38-
*/
39-
public function __construct(string $ttlHeader = 'X-Reverse-Proxy-TTL', bool $keepTtlHeader = false)
40-
{
41-
$this->ttlHeader = $ttlHeader;
42-
$this->keepTtlHeader = $keepTtlHeader;
31+
public function __construct(
32+
/**
33+
* The header name that is used to specify the time to live.
34+
*/
35+
private readonly string $ttlHeader = 'X-Reverse-Proxy-TTL',
36+
/**
37+
* Keep the custom TTL header on the response for later usage (e.g. debugging).
38+
*/
39+
private readonly bool $keepTtlHeader = false,
40+
) {
4341
}
4442

4543
/**

src/SymfonyCache/KernelDispatcher.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,14 @@
3232
*/
3333
class KernelDispatcher implements Dispatcher
3434
{
35-
private HttpCacheProvider $httpCacheProvider;
36-
3735
/**
3836
* @var Request[]
3937
*/
4038
private array $queue = [];
4139

42-
public function __construct(HttpCacheProvider $httpCacheProvider)
43-
{
44-
$this->httpCacheProvider = $httpCacheProvider;
40+
public function __construct(
41+
private readonly HttpCacheProvider $httpCacheProvider,
42+
) {
4543
}
4644

4745
public function invalidate(RequestInterface $invalidationRequest, bool $validateHost = true): void

src/TagHeaderFormatter/CommaSeparatedTagHeaderFormatter.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,10 @@
1818
*/
1919
class CommaSeparatedTagHeaderFormatter implements TagHeaderFormatter, TagHeaderParser
2020
{
21-
private string $headerName;
22-
23-
private string $glue;
24-
25-
public function __construct(string $headerName = TagHeaderFormatter::DEFAULT_HEADER_NAME, string $glue = ',')
26-
{
27-
$this->headerName = $headerName;
28-
$this->glue = $glue;
21+
public function __construct(
22+
private readonly string $headerName = TagHeaderFormatter::DEFAULT_HEADER_NAME,
23+
private readonly string $glue = ',',
24+
) {
2925
}
3026

3127
public function getTagsHeaderName(): string

src/TagHeaderFormatter/MaxHeaderValueLengthFormatter.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,16 @@
2323
*/
2424
class MaxHeaderValueLengthFormatter implements TagHeaderFormatter, TagHeaderParser
2525
{
26-
private TagHeaderFormatter $inner;
27-
28-
private int $maxHeaderValueLength;
29-
3026
/**
3127
* The default value of the maximum header length is 4096 because most
3228
* servers limit header values to 4kb.
3329
* HTTP messages cannot carry characters outside the ISO-8859-1 standard so they all
3430
* use up just one byte.
3531
*/
36-
public function __construct(TagHeaderFormatter $inner, int $maxHeaderValueLength = 4096)
37-
{
38-
$this->inner = $inner;
39-
$this->maxHeaderValueLength = $maxHeaderValueLength;
32+
public function __construct(
33+
private readonly TagHeaderFormatter $inner,
34+
private readonly int $maxHeaderValueLength = 4096,
35+
) {
4036
}
4137

4238
public function getTagsHeaderName(): string

src/Test/HttpClient.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,16 @@ class HttpClient
2828
*/
2929
private ClientInterface $httpClient;
3030

31-
private string $hostname;
32-
33-
private string $port;
34-
35-
/**
36-
* @param string $hostname Default hostname if not specified in the URL
37-
* @param string $port Default port if not specified in the URL
38-
*/
39-
public function __construct(string $hostname, string $port)
40-
{
41-
$this->hostname = $hostname;
42-
$this->port = $port;
31+
public function __construct(
32+
/**
33+
* Default hostname if not specified in the URL.
34+
*/
35+
private readonly string $hostname,
36+
/**
37+
* Default port if not specified in the URL.
38+
*/
39+
private readonly string $port,
40+
) {
4341
}
4442

4543
/**

0 commit comments

Comments
 (0)