Skip to content

Commit 557641c

Browse files
committed
use constructor property promotion
1 parent 1b4d67d commit 557641c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+298
-443
lines changed

src/Symfony/Component/HtmlSanitizer/HtmlSanitizer.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,17 @@
2222
*/
2323
final class HtmlSanitizer implements HtmlSanitizerInterface
2424
{
25-
private HtmlSanitizerConfig $config;
2625
private ParserInterface $parser;
2726

2827
/**
2928
* @var array<string, DomVisitor>
3029
*/
3130
private array $domVisitors = [];
3231

33-
public function __construct(HtmlSanitizerConfig $config, ?ParserInterface $parser = null)
34-
{
32+
public function __construct(
33+
private HtmlSanitizerConfig $config,
34+
?ParserInterface $parser = null,
35+
) {
3536
$this->config = $config;
3637
$this->parser = $parser ?? new MastermindsParser();
3738
}

src/Symfony/Component/HtmlSanitizer/Visitor/DomVisitor.php

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,6 @@
3333
*/
3434
final class DomVisitor
3535
{
36-
private HtmlSanitizerConfig $config;
37-
38-
/**
39-
* Registry of allowed/blocked elements:
40-
* * If an element is present as a key and contains an array, the element should be allowed
41-
* and the array is the list of allowed attributes.
42-
* * If an element is present as a key and contains "false", the element should be blocked.
43-
* * If an element is not present as a key, the element should be dropped.
44-
*
45-
* @var array<string, false|array<string, bool>>
46-
*/
47-
private array $elementsConfig;
48-
4936
/**
5037
* Registry of attributes to forcefully set on nodes, index by element and attribute.
5138
*
@@ -62,12 +49,16 @@ final class DomVisitor
6249
private array $attributeSanitizers = [];
6350

6451
/**
65-
* @param array<string, false|array<string, bool>> $elementsConfig
52+
* @param array<string, false|array<string, bool>> $elementsConfig Registry of allowed/blocked elements:
53+
* * If an element is present as a key and contains an array, the element should be allowed
54+
* and the array is the list of allowed attributes.
55+
* * If an element is present as a key and contains "false", the element should be blocked.
56+
* * If an element is not present as a key, the element should be dropped.
6657
*/
67-
public function __construct(HtmlSanitizerConfig $config, array $elementsConfig)
68-
{
69-
$this->config = $config;
70-
$this->elementsConfig = $elementsConfig;
58+
public function __construct(
59+
private HtmlSanitizerConfig $config,
60+
private array $elementsConfig,
61+
) {
7162
$this->forcedAttributes = $config->getForcedAttributes();
7263

7364
foreach ($config->getAttributeSanitizers() as $attributeSanitizer) {

src/Symfony/Component/HtmlSanitizer/Visitor/Node/BlockedNode.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@
1616
*/
1717
final class BlockedNode implements NodeInterface
1818
{
19-
private NodeInterface $parentNode;
2019
private array $children = [];
2120

22-
public function __construct(NodeInterface $parentNode)
23-
{
24-
$this->parentNode = $parentNode;
21+
public function __construct(
22+
private NodeInterface $parentNode,
23+
) {
2524
}
2625

2726
public function addChild(NodeInterface $node): void

src/Symfony/Component/HtmlSanitizer/Visitor/Node/Node.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,13 @@ final class Node implements NodeInterface
3737
'wbr' => true,
3838
];
3939

40-
private NodeInterface $parent;
41-
private string $tagName;
4240
private array $attributes = [];
4341
private array $children = [];
4442

45-
public function __construct(NodeInterface $parent, string $tagName)
46-
{
47-
$this->parent = $parent;
48-
$this->tagName = $tagName;
43+
public function __construct(
44+
private NodeInterface $parent,
45+
private string $tagName,
46+
) {
4947
}
5048

5149
public function getParent(): ?NodeInterface

src/Symfony/Component/HttpClient/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

src/Symfony/Component/HttpClient/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

src/Symfony/Component/HttpClient/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.

src/Symfony/Component/HttpClient/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

src/Symfony/Component/HttpClient/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

src/Symfony/Component/HttpClient/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
/**

0 commit comments

Comments
 (0)