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

Session/Storage/Handler/MemcachedSessionHandler.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
*/
2222
class MemcachedSessionHandler extends AbstractSessionHandler
2323
{
24-
private \Memcached $memcached;
25-
2624
/**
2725
* Time to live in seconds.
2826
*/
@@ -42,10 +40,10 @@ class MemcachedSessionHandler extends AbstractSessionHandler
4240
*
4341
* @throws \InvalidArgumentException When unsupported options are passed
4442
*/
45-
public function __construct(\Memcached $memcached, array $options = [])
46-
{
47-
$this->memcached = $memcached;
48-
43+
public function __construct(
44+
private \Memcached $memcached,
45+
array $options = [],
46+
) {
4947
if ($diff = array_diff(array_keys($options), ['prefix', 'expiretime', 'ttl'])) {
5048
throw new \InvalidArgumentException(sprintf('The following options are not supported "%s".', implode(', ', $diff)));
5149
}

Session/Storage/Handler/StrictSessionHandler.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,14 @@
1818
*/
1919
class StrictSessionHandler extends AbstractSessionHandler
2020
{
21-
private \SessionHandlerInterface $handler;
2221
private bool $doDestroy;
2322

24-
public function __construct(\SessionHandlerInterface $handler)
25-
{
23+
public function __construct(
24+
private \SessionHandlerInterface $handler,
25+
) {
2626
if ($handler instanceof \SessionUpdateTimestampHandlerInterface) {
2727
throw new \LogicException(sprintf('"%s" is already an instance of "SessionUpdateTimestampHandlerInterface", you cannot wrap it with "%s".', get_debug_type($handler), self::class));
2828
}
29-
30-
$this->handler = $handler;
3129
}
3230

3331
/**

Session/Storage/MetadataBag.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,16 @@ class MetadataBag implements SessionBagInterface
2929
protected array $meta = [self::CREATED => 0, self::UPDATED => 0, self::LIFETIME => 0];
3030

3131
private string $name = '__metadata';
32-
private string $storageKey;
3332
private int $lastUsed;
34-
private int $updateThreshold;
3533

3634
/**
3735
* @param string $storageKey The key used to store bag in the session
3836
* @param int $updateThreshold The time to wait between two UPDATED updates
3937
*/
40-
public function __construct(string $storageKey = '_sf2_meta', int $updateThreshold = 0)
41-
{
42-
$this->storageKey = $storageKey;
43-
$this->updateThreshold = $updateThreshold;
38+
public function __construct(
39+
private string $storageKey = '_sf2_meta',
40+
private int $updateThreshold = 0,
41+
) {
4442
}
4543

4644
public function initialize(array &$array): void

Session/Storage/MockArraySessionStorage.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
class MockArraySessionStorage implements SessionStorageInterface
2929
{
3030
protected string $id = '';
31-
protected string $name;
3231
protected bool $started = false;
3332
protected bool $closed = false;
3433
protected array $data = [];
@@ -39,9 +38,10 @@ class MockArraySessionStorage implements SessionStorageInterface
3938
*/
4039
protected array $bags = [];
4140

42-
public function __construct(string $name = 'MOCKSESSID', ?MetadataBag $metaBag = null)
43-
{
44-
$this->name = $name;
41+
public function __construct(
42+
protected string $name = 'MOCKSESSID',
43+
?MetadataBag $metaBag = null,
44+
) {
4545
$this->setMetadataBag($metaBag);
4646
}
4747

Session/Storage/MockFileSessionStorageFactory.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,14 @@ class_exists(MockFileSessionStorage::class);
2121
*/
2222
class MockFileSessionStorageFactory implements SessionStorageFactoryInterface
2323
{
24-
private ?string $savePath;
25-
private string $name;
26-
private ?MetadataBag $metaBag;
27-
2824
/**
2925
* @see MockFileSessionStorage constructor.
3026
*/
31-
public function __construct(?string $savePath = null, string $name = 'MOCKSESSID', ?MetadataBag $metaBag = null)
32-
{
33-
$this->savePath = $savePath;
34-
$this->name = $name;
35-
$this->metaBag = $metaBag;
27+
public function __construct(
28+
private ?string $savePath = null,
29+
private string $name = 'MOCKSESSID',
30+
private ?MetadataBag $metaBag = null,
31+
) {
3632
}
3733

3834
public function createStorage(?Request $request): SessionStorageInterface

Session/Storage/NativeSessionStorageFactory.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,15 @@ class_exists(NativeSessionStorage::class);
2222
*/
2323
class NativeSessionStorageFactory implements SessionStorageFactoryInterface
2424
{
25-
private array $options;
26-
private AbstractProxy|\SessionHandlerInterface|null $handler;
27-
private ?MetadataBag $metaBag;
28-
private bool $secure;
29-
3025
/**
3126
* @see NativeSessionStorage constructor.
3227
*/
33-
public function __construct(array $options = [], AbstractProxy|\SessionHandlerInterface|null $handler = null, ?MetadataBag $metaBag = null, bool $secure = false)
34-
{
35-
$this->options = $options;
36-
$this->handler = $handler;
37-
$this->metaBag = $metaBag;
38-
$this->secure = $secure;
28+
public function __construct(
29+
private array $options = [],
30+
private AbstractProxy|\SessionHandlerInterface|null $handler = null,
31+
private ?MetadataBag $metaBag = null,
32+
private bool $secure = false,
33+
) {
3934
}
4035

4136
public function createStorage(?Request $request): SessionStorageInterface

Session/Storage/PhpBridgeSessionStorageFactory.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,11 @@ class_exists(PhpBridgeSessionStorage::class);
2222
*/
2323
class PhpBridgeSessionStorageFactory implements SessionStorageFactoryInterface
2424
{
25-
private AbstractProxy|\SessionHandlerInterface|null $handler;
26-
private ?MetadataBag $metaBag;
27-
private bool $secure;
28-
29-
public function __construct(AbstractProxy|\SessionHandlerInterface|null $handler = null, ?MetadataBag $metaBag = null, bool $secure = false)
30-
{
31-
$this->handler = $handler;
32-
$this->metaBag = $metaBag;
33-
$this->secure = $secure;
25+
public function __construct(
26+
private AbstractProxy|\SessionHandlerInterface|null $handler = null,
27+
private ?MetadataBag $metaBag = null,
28+
private bool $secure = false,
29+
) {
3430
}
3531

3632
public function createStorage(?Request $request): SessionStorageInterface

0 commit comments

Comments
 (0)