Skip to content

Commit cb1de10

Browse files
committed
minor #57281 [HtmlSanitizer][HttpClient][HttpFoundation][Ldap][Lock][PropertyInfo]  use constructor property promotion (xabbuh)
This PR was merged into the 7.2 branch. Discussion ---------- [HtmlSanitizer][HttpClient][HttpFoundation][Ldap][Lock][PropertyInfo]  use constructor property promotion | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | | License | MIT Commits ------- 557641cd88 use constructor property promotion
2 parents 1ec24a5 + 2484cac commit cb1de10

11 files changed

+52
-77
lines changed

CachingHttpClient.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,18 @@ class CachingHttpClient implements HttpClientInterface, ResetInterface
3535
{
3636
use HttpClientTrait;
3737

38-
private HttpClientInterface $client;
3938
private HttpCache $cache;
4039
private array $defaultOptions = self::OPTIONS_DEFAULTS;
4140

42-
public function __construct(HttpClientInterface $client, StoreInterface $store, array $defaultOptions = [])
43-
{
41+
public function __construct(
42+
private HttpClientInterface $client,
43+
StoreInterface $store,
44+
array $defaultOptions = [],
45+
) {
4446
if (!class_exists(HttpClientKernel::class)) {
4547
throw new \LogicException(sprintf('Using "%s" requires that the HttpKernel component version 4.3 or higher is installed, try running "composer require symfony/http-kernel:^5.4".', __CLASS__));
4648
}
4749

48-
$this->client = $client;
4950
$kernel = new HttpClientKernel($client);
5051
$this->cache = new HttpCache($kernel, $store, null, $defaultOptions);
5152

EventSourceHttpClient.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,11 @@ final class EventSourceHttpClient implements HttpClientInterface, ResetInterface
3131
AsyncDecoratorTrait::withOptions insteadof HttpClientTrait;
3232
}
3333

34-
private float $reconnectionTime;
35-
36-
public function __construct(?HttpClientInterface $client = null, float $reconnectionTime = 10.0)
37-
{
34+
public function __construct(
35+
?HttpClientInterface $client = null,
36+
private float $reconnectionTime = 10.0,
37+
) {
3838
$this->client = $client ?? HttpClient::create();
39-
$this->reconnectionTime = $reconnectionTime;
4039
}
4140

4241
public function connect(string $url, array $options = [], string $method = 'GET'): ResponseInterface

HttpClientTrait.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use Symfony\Component\HttpClient\Response\StreamableInterface;
1717
use Symfony\Component\HttpClient\Response\StreamWrapper;
1818
use Symfony\Component\Mime\MimeTypes;
19-
use Symfony\Contracts\HttpClient\HttpClientInterface;
2019

2120
/**
2221
* Provides the common logic from writing HttpClientInterface implementations.

NoPrivateNetworkHttpClient.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,17 @@ final class NoPrivateNetworkHttpClient implements HttpClientInterface, LoggerAwa
3030
{
3131
use HttpClientTrait;
3232

33-
private HttpClientInterface $client;
34-
private string|array|null $subnets;
35-
3633
/**
3734
* @param string|array|null $subnets String or array of subnets using CIDR notation that will be used by IpUtils.
3835
* If null is passed, the standard private subnets will be used.
3936
*/
40-
public function __construct(HttpClientInterface $client, string|array|null $subnets = null)
41-
{
37+
public function __construct(
38+
private HttpClientInterface $client,
39+
private string|array|null $subnets = null,
40+
) {
4241
if (!class_exists(IpUtils::class)) {
4342
throw new \LogicException(sprintf('You cannot use "%s" if the HttpFoundation component is not installed. Try running "composer require symfony/http-foundation".', __CLASS__));
4443
}
45-
46-
$this->client = $client;
47-
$this->subnets = $subnets;
4844
}
4945

5046
public function request(string $method, string $url, array $options = []): ResponseInterface

Psr18Client.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,11 @@ public function reset(): void
182182
*/
183183
class Psr18NetworkException extends \RuntimeException implements NetworkExceptionInterface
184184
{
185-
private RequestInterface $request;
186-
187-
public function __construct(TransportExceptionInterface $e, RequestInterface $request)
188-
{
185+
public function __construct(
186+
TransportExceptionInterface $e,
187+
private RequestInterface $request,
188+
) {
189189
parent::__construct($e->getMessage(), 0, $e);
190-
$this->request = $request;
191190
}
192191

193192
public function getRequest(): RequestInterface
@@ -201,12 +200,11 @@ public function getRequest(): RequestInterface
201200
*/
202201
class Psr18RequestException extends \InvalidArgumentException implements RequestExceptionInterface
203202
{
204-
private RequestInterface $request;
205-
206-
public function __construct(TransportExceptionInterface $e, RequestInterface $request)
207-
{
203+
public function __construct(
204+
TransportExceptionInterface $e,
205+
private RequestInterface $request,
206+
) {
208207
parent::__construct($e->getMessage(), 0, $e);
209-
$this->request = $request;
210208
}
211209

212210
public function getRequest(): RequestInterface

Response/AsyncContext.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,23 @@ final class AsyncContext
2727
{
2828
/** @var callable|null */
2929
private $passthru;
30-
private HttpClientInterface $client;
3130
private ResponseInterface $response;
3231
private array $info = [];
33-
/** @var resource|null */
34-
private $content;
35-
private int $offset;
3632

3733
/**
3834
* @param resource|null $content
3935
*/
40-
public function __construct(?callable &$passthru, HttpClientInterface $client, ResponseInterface &$response, array &$info, $content, int $offset)
41-
{
36+
public function __construct(
37+
?callable &$passthru,
38+
private HttpClientInterface $client,
39+
ResponseInterface &$response,
40+
array &$info,
41+
private $content,
42+
private int $offset,
43+
) {
4244
$this->passthru = &$passthru;
43-
$this->client = $client;
4445
$this->response = &$response;
4546
$this->info = &$info;
46-
$this->content = $content;
47-
$this->offset = $offset;
4847
}
4948

5049
/**

Retry/GenericRetryStrategy.php

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@ class GenericRetryStrategy implements RetryStrategyInterface
3636
510 => self::IDEMPOTENT_METHODS,
3737
];
3838

39-
private int $delayMs;
40-
private float $multiplier;
41-
private int $maxDelayMs;
42-
private float $jitter;
43-
4439
/**
4540
* @param array $statusCodes List of HTTP status codes that trigger a retry
4641
* @param int $delayMs Amount of time to delay (or the initial value when multiplier is used)
@@ -50,30 +45,26 @@ class GenericRetryStrategy implements RetryStrategyInterface
5045
*/
5146
public function __construct(
5247
private array $statusCodes = self::DEFAULT_RETRY_STATUS_CODES,
53-
int $delayMs = 1000,
54-
float $multiplier = 2.0,
55-
int $maxDelayMs = 0,
56-
float $jitter = 0.1,
48+
private int $delayMs = 1000,
49+
private float $multiplier = 2.0,
50+
private int $maxDelayMs = 0,
51+
private float $jitter = 0.1,
5752
) {
5853
if ($delayMs < 0) {
5954
throw new InvalidArgumentException(sprintf('Delay must be greater than or equal to zero: "%s" given.', $delayMs));
6055
}
61-
$this->delayMs = $delayMs;
6256

6357
if ($multiplier < 1) {
6458
throw new InvalidArgumentException(sprintf('Multiplier must be greater than or equal to one: "%s" given.', $multiplier));
6559
}
66-
$this->multiplier = $multiplier;
6760

6861
if ($maxDelayMs < 0) {
6962
throw new InvalidArgumentException(sprintf('Max delay must be greater than or equal to zero: "%s" given.', $maxDelayMs));
7063
}
71-
$this->maxDelayMs = $maxDelayMs;
7264

7365
if ($jitter < 0 || $jitter > 1) {
7466
throw new InvalidArgumentException(sprintf('Jitter must be between 0 and 1: "%s" given.', $jitter));
7567
}
76-
$this->jitter = $jitter;
7768
}
7869

7970
public function shouldRetry(AsyncContext $context, ?string $responseContent, ?TransportExceptionInterface $exception): ?bool

RetryableHttpClient.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@ class RetryableHttpClient implements HttpClientInterface, ResetInterface
3232
use AsyncDecoratorTrait;
3333

3434
private RetryStrategyInterface $strategy;
35-
private int $maxRetries;
36-
private ?LoggerInterface $logger;
3735
private array $baseUris = [];
3836

3937
/**
4038
* @param int $maxRetries The maximum number of times to retry
4139
*/
42-
public function __construct(HttpClientInterface $client, ?RetryStrategyInterface $strategy = null, int $maxRetries = 3, ?LoggerInterface $logger = null)
43-
{
40+
public function __construct(
41+
HttpClientInterface $client,
42+
?RetryStrategyInterface $strategy = null,
43+
private int $maxRetries = 3,
44+
private ?LoggerInterface $logger = null,
45+
) {
4446
$this->client = $client;
4547
$this->strategy = $strategy ?? new GenericRetryStrategy();
46-
$this->maxRetries = $maxRetries;
47-
$this->logger = $logger;
4848
}
4949

5050
public function withOptions(array $options): static

ScopingHttpClient.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,11 @@ class ScopingHttpClient implements HttpClientInterface, ResetInterface, LoggerAw
2828
{
2929
use HttpClientTrait;
3030

31-
private HttpClientInterface $client;
32-
private array $defaultOptionsByRegexp;
33-
private ?string $defaultRegexp;
34-
35-
public function __construct(HttpClientInterface $client, array $defaultOptionsByRegexp, ?string $defaultRegexp = null)
36-
{
37-
$this->client = $client;
38-
$this->defaultOptionsByRegexp = $defaultOptionsByRegexp;
39-
$this->defaultRegexp = $defaultRegexp;
40-
31+
public function __construct(
32+
private HttpClientInterface $client,
33+
private array $defaultOptionsByRegexp,
34+
private ?string $defaultRegexp = null,
35+
) {
4136
if (null !== $defaultRegexp && !isset($defaultOptionsByRegexp[$defaultRegexp])) {
4237
throw new InvalidArgumentException(sprintf('No options are mapped to the provided "%s" default regexp.', $defaultRegexp));
4338
}

Tests/AsyncDecoratorTraitTest.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,10 @@ protected function getHttpClient(string $testCase, ?\Closure $chunkFilter = null
4141
return new class($decoratedClient ?? parent::getHttpClient($testCase), $chunkFilter) implements HttpClientInterface {
4242
use AsyncDecoratorTrait;
4343

44-
private ?\Closure $chunkFilter;
45-
46-
public function __construct(HttpClientInterface $client, ?\Closure $chunkFilter = null)
47-
{
48-
$this->chunkFilter = $chunkFilter;
44+
public function __construct(
45+
HttpClientInterface $client,
46+
private ?\Closure $chunkFilter = null,
47+
) {
4948
$this->client = $client;
5049
}
5150

0 commit comments

Comments
 (0)