Skip to content

Commit 5f81c6e

Browse files
committed
use constructor property promotion
1 parent ff287af commit 5f81c6e

26 files changed

+117
-173
lines changed

AcceptHeaderItem.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
*/
1919
class AcceptHeaderItem
2020
{
21-
private string $value;
2221
private float $quality = 1.0;
2322
private int $index = 0;
2423
private array $attributes = [];
2524

26-
public function __construct(string $value, array $attributes = [])
27-
{
28-
$this->value = $value;
25+
public function __construct(
26+
private string $value,
27+
array $attributes = [],
28+
) {
2929
foreach ($attributes as $name => $value) {
3030
$this->setAttribute($name, $value);
3131
}

Cookie.php

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,10 @@ class Cookie
2222
public const SAMESITE_LAX = 'lax';
2323
public const SAMESITE_STRICT = 'strict';
2424

25-
protected string $name;
26-
protected ?string $value;
27-
protected ?string $domain;
2825
protected int $expire;
2926
protected string $path;
30-
protected ?bool $secure;
31-
protected bool $httpOnly;
3227

33-
private bool $raw;
3428
private ?string $sameSite = null;
35-
private bool $partitioned = false;
3629
private bool $secureDefault = false;
3730

3831
private const RESERVED_CHARS_LIST = "=,; \t\r\n\v\f";
@@ -94,8 +87,18 @@ public static function create(string $name, ?string $value = null, int|string|\D
9487
*
9588
* @throws \InvalidArgumentException
9689
*/
97-
public function __construct(string $name, ?string $value = null, int|string|\DateTimeInterface $expire = 0, ?string $path = '/', ?string $domain = null, ?bool $secure = null, bool $httpOnly = true, bool $raw = false, ?string $sameSite = self::SAMESITE_LAX, bool $partitioned = false)
98-
{
90+
public function __construct(
91+
protected string $name,
92+
protected ?string $value = null,
93+
int|string|\DateTimeInterface $expire = 0,
94+
?string $path = '/',
95+
protected ?string $domain = null,
96+
protected ?bool $secure = null,
97+
protected bool $httpOnly = true,
98+
private bool $raw = false,
99+
?string $sameSite = self::SAMESITE_LAX,
100+
private bool $partitioned = false,
101+
) {
99102
// from PHP source code
100103
if ($raw && false !== strpbrk($name, self::RESERVED_CHARS_LIST)) {
101104
throw new \InvalidArgumentException(sprintf('The cookie name "%s" contains invalid characters.', $name));
@@ -105,16 +108,9 @@ public function __construct(string $name, ?string $value = null, int|string|\Dat
105108
throw new \InvalidArgumentException('The cookie name cannot be empty.');
106109
}
107110

108-
$this->name = $name;
109-
$this->value = $value;
110-
$this->domain = $domain;
111111
$this->expire = self::expiresTimestamp($expire);
112112
$this->path = $path ?: '/';
113-
$this->secure = $secure;
114-
$this->httpOnly = $httpOnly;
115-
$this->raw = $raw;
116113
$this->sameSite = $this->withSameSite($sameSite)->sameSite;
117-
$this->partitioned = $partitioned;
118114
}
119115

120116
/**

File/UploadedFile.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
*/
3232
class UploadedFile extends File
3333
{
34-
private bool $test;
3534
private string $originalName;
3635
private string $mimeType;
3736
private int $error;
@@ -61,13 +60,17 @@ class UploadedFile extends File
6160
* @throws FileException If file_uploads is disabled
6261
* @throws FileNotFoundException If the file does not exist
6362
*/
64-
public function __construct(string $path, string $originalName, ?string $mimeType = null, ?int $error = null, bool $test = false)
65-
{
63+
public function __construct(
64+
string $path,
65+
string $originalName,
66+
?string $mimeType = null,
67+
?int $error = null,
68+
private bool $test = false,
69+
) {
6670
$this->originalName = $this->getName($originalName);
6771
$this->originalPath = strtr($originalName, '\\', '/');
6872
$this->mimeType = $mimeType ?: 'application/octet-stream';
6973
$this->error = $error ?: \UPLOAD_ERR_OK;
70-
$this->test = $test;
7174

7275
parent::__construct($path, \UPLOAD_ERR_OK === $this->error);
7376
}

ParameterBag.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@
2323
*/
2424
class ParameterBag implements \IteratorAggregate, \Countable
2525
{
26-
protected array $parameters;
27-
28-
public function __construct(array $parameters = [])
29-
{
30-
$this->parameters = $parameters;
26+
public function __construct(
27+
protected array $parameters = [],
28+
) {
3129
}
3230

3331
/**

Session/Attribute/AttributeBag.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,13 @@ class AttributeBag implements AttributeBagInterface, \IteratorAggregate, \Counta
2121
protected array $attributes = [];
2222

2323
private string $name = 'attributes';
24-
private string $storageKey;
2524

2625
/**
2726
* @param string $storageKey The key used to store attributes in the session
2827
*/
29-
public function __construct(string $storageKey = '_sf2_attributes')
30-
{
31-
$this->storageKey = $storageKey;
28+
public function __construct(
29+
private string $storageKey = '_sf2_attributes',
30+
) {
3231
}
3332

3433
public function getName(): string

Session/Flash/AutoExpireFlashBag.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@ class AutoExpireFlashBag implements FlashBagInterface
2020
{
2121
private string $name = 'flashes';
2222
private array $flashes = ['display' => [], 'new' => []];
23-
private string $storageKey;
2423

2524
/**
2625
* @param string $storageKey The key used to store flashes in the session
2726
*/
28-
public function __construct(string $storageKey = '_symfony_flashes')
29-
{
30-
$this->storageKey = $storageKey;
27+
public function __construct(
28+
private string $storageKey = '_symfony_flashes',
29+
) {
3130
}
3231

3332
public function getName(): string

Session/Flash/FlashBag.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@ class FlashBag implements FlashBagInterface
2020
{
2121
private string $name = 'flashes';
2222
private array $flashes = [];
23-
private string $storageKey;
2423

2524
/**
2625
* @param string $storageKey The key used to store flashes in the session
2726
*/
28-
public function __construct(string $storageKey = '_symfony_flashes')
29-
{
30-
$this->storageKey = $storageKey;
27+
public function __construct(
28+
private string $storageKey = '_symfony_flashes',
29+
) {
3130
}
3231

3332
public function getName(): string

Session/SessionBagProxy.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@
1818
*/
1919
final class SessionBagProxy implements SessionBagInterface
2020
{
21-
private SessionBagInterface $bag;
2221
private array $data;
2322
private ?int $usageIndex;
2423
private ?\Closure $usageReporter;
2524

26-
public function __construct(SessionBagInterface $bag, array &$data, ?int &$usageIndex, ?callable $usageReporter)
27-
{
25+
public function __construct(
26+
private SessionBagInterface $bag,
27+
array &$data,
28+
?int &$usageIndex,
29+
?callable $usageReporter,
30+
) {
2831
$this->bag = $bag;
2932
$this->data = &$data;
3033
$this->usageIndex = &$usageIndex;

Session/SessionFactory.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@ class_exists(Session::class);
2222
*/
2323
class SessionFactory implements SessionFactoryInterface
2424
{
25-
private RequestStack $requestStack;
26-
private SessionStorageFactoryInterface $storageFactory;
2725
private ?\Closure $usageReporter;
2826

29-
public function __construct(RequestStack $requestStack, SessionStorageFactoryInterface $storageFactory, ?callable $usageReporter = null)
30-
{
31-
$this->requestStack = $requestStack;
32-
$this->storageFactory = $storageFactory;
27+
public function __construct(
28+
private RequestStack $requestStack,
29+
private SessionStorageFactoryInterface $storageFactory,
30+
?callable $usageReporter = null,
31+
) {
3332
$this->usageReporter = null === $usageReporter ? null : $usageReporter(...);
3433
}
3534

Session/Storage/Handler/MarshallingSessionHandler.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,10 @@
1818
*/
1919
class MarshallingSessionHandler implements \SessionHandlerInterface, \SessionUpdateTimestampHandlerInterface
2020
{
21-
private AbstractSessionHandler $handler;
22-
private MarshallerInterface $marshaller;
23-
24-
public function __construct(AbstractSessionHandler $handler, MarshallerInterface $marshaller)
25-
{
26-
$this->handler = $handler;
27-
$this->marshaller = $marshaller;
21+
public function __construct(
22+
private AbstractSessionHandler $handler,
23+
private MarshallerInterface $marshaller,
24+
) {
2825
}
2926

3027
public function open(string $savePath, string $name): bool

0 commit comments

Comments
 (0)