Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8d352bc

Browse filesBrowse files
committed
minor #53966 [OptionsResolver][PasswordHasher][PropertyAccess][Semaphore][Stopwatch][Yaml] use constructor property promotion (xabbuh)
This PR was merged into the 7.1 branch. Discussion ---------- [OptionsResolver][PasswordHasher][PropertyAccess][Semaphore][Stopwatch][Yaml] use constructor property promotion | Q | A | ------------- | --- | Branch? | 7.1 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | | License | MIT Commits ------- c4e4843 use constructor property promotion
2 parents 86b07f0 + c4e4843 commit 8d352bc
Copy full SHA for 8d352bc

17 files changed

+78
-119
lines changed

‎src/Symfony/Component/OptionsResolver/OptionConfigurator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/OptionsResolver/OptionConfigurator.php
+4-7Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,10 @@
1515

1616
final class OptionConfigurator
1717
{
18-
private string $name;
19-
private OptionsResolver $resolver;
20-
21-
public function __construct(string $name, OptionsResolver $resolver)
22-
{
23-
$this->name = $name;
24-
$this->resolver = $resolver;
18+
public function __construct(
19+
private string $name,
20+
private OptionsResolver $resolver,
21+
) {
2522
$this->resolver->setDefined($name);
2623
}
2724

‎src/Symfony/Component/PasswordHasher/Command/UserPasswordHashCommand.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/PasswordHasher/Command/UserPasswordHashCommand.php
+4-8Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,10 @@
3838
#[AsCommand(name: 'security:hash-password', description: 'Hash a user password')]
3939
class UserPasswordHashCommand extends Command
4040
{
41-
private PasswordHasherFactoryInterface $hasherFactory;
42-
private array $userClasses;
43-
44-
public function __construct(PasswordHasherFactoryInterface $hasherFactory, array $userClasses = [])
45-
{
46-
$this->hasherFactory = $hasherFactory;
47-
$this->userClasses = $userClasses;
48-
41+
public function __construct(
42+
private PasswordHasherFactoryInterface $hasherFactory,
43+
private array $userClasses = [],
44+
) {
4945
parent::__construct();
5046
}
5147

‎src/Symfony/Component/PasswordHasher/Hasher/MessageDigestPasswordHasher.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/PasswordHasher/Hasher/MessageDigestPasswordHasher.php
+5-10Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,23 @@ class MessageDigestPasswordHasher implements LegacyPasswordHasherInterface
2424
{
2525
use CheckPasswordLengthTrait;
2626

27-
private string $algorithm;
28-
private bool $encodeHashAsBase64;
29-
private int $iterations = 1;
3027
private int $hashLength = -1;
3128

3229
/**
3330
* @param string $algorithm The digest algorithm to use
3431
* @param bool $encodeHashAsBase64 Whether to base64 encode the password hash
3532
* @param int $iterations The number of iterations to use to stretch the password hash
3633
*/
37-
public function __construct(string $algorithm = 'sha512', bool $encodeHashAsBase64 = true, int $iterations = 5000)
38-
{
39-
$this->algorithm = $algorithm;
40-
$this->encodeHashAsBase64 = $encodeHashAsBase64;
41-
34+
public function __construct(
35+
private string $algorithm = 'sha512',
36+
private bool $encodeHashAsBase64 = true,
37+
private int $iterations = 5000,
38+
) {
4239
try {
4340
$this->hashLength = \strlen($this->hash('', 'salt'));
4441
} catch (\LogicException) {
4542
// ignore algorithm not supported
4643
}
47-
48-
$this->iterations = $iterations;
4944
}
5045

5146
public function hash(#[\SensitiveParameter] string $plainPassword, ?string $salt = null): string

‎src/Symfony/Component/PasswordHasher/Hasher/MigratingPasswordHasher.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/PasswordHasher/Hasher/MigratingPasswordHasher.php
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424
*/
2525
final class MigratingPasswordHasher implements PasswordHasherInterface
2626
{
27-
private PasswordHasherInterface $bestHasher;
2827
private array $extraHashers;
2928

30-
public function __construct(PasswordHasherInterface $bestHasher, PasswordHasherInterface ...$extraHashers)
31-
{
32-
$this->bestHasher = $bestHasher;
29+
public function __construct(
30+
private PasswordHasherInterface $bestHasher,
31+
PasswordHasherInterface ...$extraHashers,
32+
) {
3333
$this->extraHashers = $extraHashers;
3434
}
3535

‎src/Symfony/Component/PasswordHasher/Hasher/PasswordHasherFactory.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/PasswordHasher/Hasher/PasswordHasherFactory.php
+3-5Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,12 @@
2323
*/
2424
class PasswordHasherFactory implements PasswordHasherFactoryInterface
2525
{
26-
private array $passwordHashers;
27-
2826
/**
2927
* @param array<string, PasswordHasherInterface|array> $passwordHashers
3028
*/
31-
public function __construct(array $passwordHashers)
32-
{
33-
$this->passwordHashers = $passwordHashers;
29+
public function __construct(
30+
private array $passwordHashers,
31+
) {
3432
}
3533

3634
public function getPasswordHasher(string|PasswordAuthenticatedUserInterface|PasswordHasherAwareInterface $user): PasswordHasherInterface

‎src/Symfony/Component/PasswordHasher/Hasher/Pbkdf2PasswordHasher.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/PasswordHasher/Hasher/Pbkdf2PasswordHasher.php
+6-12Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ final class Pbkdf2PasswordHasher implements LegacyPasswordHasherInterface
3232
{
3333
use CheckPasswordLengthTrait;
3434

35-
private string $algorithm;
36-
private bool $encodeHashAsBase64;
37-
private int $iterations = 1;
38-
private int $length;
3935
private int $encodedLength = -1;
4036

4137
/**
@@ -44,19 +40,17 @@ final class Pbkdf2PasswordHasher implements LegacyPasswordHasherInterface
4440
* @param int $iterations The number of iterations to use to stretch the password hash
4541
* @param int $length Length of derived key to create
4642
*/
47-
public function __construct(string $algorithm = 'sha512', bool $encodeHashAsBase64 = true, int $iterations = 1000, int $length = 40)
48-
{
49-
$this->algorithm = $algorithm;
50-
$this->encodeHashAsBase64 = $encodeHashAsBase64;
51-
$this->length = $length;
52-
43+
public function __construct(
44+
private string $algorithm = 'sha512',
45+
private bool $encodeHashAsBase64 = true,
46+
private int $iterations = 1000,
47+
private int $length = 40,
48+
) {
5349
try {
5450
$this->encodedLength = \strlen($this->hash('', 'salt'));
5551
} catch (\LogicException) {
5652
// ignore unsupported algorithm
5753
}
58-
59-
$this->iterations = $iterations;
6054
}
6155

6256
public function hash(#[\SensitiveParameter] string $plainPassword, ?string $salt = null): string

‎src/Symfony/Component/PasswordHasher/Hasher/PlaintextPasswordHasher.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/PasswordHasher/Hasher/PlaintextPasswordHasher.php
+3-5Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,12 @@ class PlaintextPasswordHasher implements LegacyPasswordHasherInterface
2525
{
2626
use CheckPasswordLengthTrait;
2727

28-
private bool $ignorePasswordCase;
29-
3028
/**
3129
* @param bool $ignorePasswordCase Compare password case-insensitive
3230
*/
33-
public function __construct(bool $ignorePasswordCase = false)
34-
{
35-
$this->ignorePasswordCase = $ignorePasswordCase;
31+
public function __construct(
32+
private bool $ignorePasswordCase = false,
33+
) {
3634
}
3735

3836
public function hash(#[\SensitiveParameter] string $plainPassword, ?string $salt = null): string

‎src/Symfony/Component/PasswordHasher/Hasher/UserPasswordHasher.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/PasswordHasher/Hasher/UserPasswordHasher.php
+3-5Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@
2323
*/
2424
class UserPasswordHasher implements UserPasswordHasherInterface
2525
{
26-
private PasswordHasherFactoryInterface $hasherFactory;
27-
28-
public function __construct(PasswordHasherFactoryInterface $hasherFactory)
29-
{
30-
$this->hasherFactory = $hasherFactory;
26+
public function __construct(
27+
private PasswordHasherFactoryInterface $hasherFactory,
28+
) {
3129
}
3230

3331
public function hashPassword(PasswordAuthenticatedUserInterface $user, #[\SensitiveParameter] string $plainPassword): string

‎src/Symfony/Component/PropertyAccess/PropertyAccessor.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/PropertyAccess/PropertyAccessor.php
+7-4Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ class PropertyAccessor implements PropertyAccessorInterface
5959
private const CACHE_PREFIX_PROPERTY_PATH = 'p';
6060
private const RESULT_PROTO = [self::VALUE => null];
6161

62-
private int $magicMethodsFlags;
6362
private bool $ignoreInvalidIndices;
6463
private bool $ignoreInvalidProperty;
6564
private ?CacheItemPoolInterface $cacheItemPool;
@@ -79,9 +78,13 @@ class PropertyAccessor implements PropertyAccessorInterface
7978
* @param int $throw A bitwise combination of the THROW_* constants
8079
* to specify when exceptions should be thrown
8180
*/
82-
public function __construct(int $magicMethods = self::MAGIC_GET | self::MAGIC_SET, int $throw = self::THROW_ON_INVALID_PROPERTY_PATH, ?CacheItemPoolInterface $cacheItemPool = null, ?PropertyReadInfoExtractorInterface $readInfoExtractor = null, ?PropertyWriteInfoExtractorInterface $writeInfoExtractor = null)
83-
{
84-
$this->magicMethodsFlags = $magicMethods;
81+
public function __construct(
82+
private int $magicMethodsFlags = self::MAGIC_GET | self::MAGIC_SET,
83+
int $throw = self::THROW_ON_INVALID_PROPERTY_PATH,
84+
?CacheItemPoolInterface $cacheItemPool = null,
85+
?PropertyReadInfoExtractorInterface $readInfoExtractor = null,
86+
?PropertyWriteInfoExtractorInterface $writeInfoExtractor = null,
87+
) {
8588
$this->ignoreInvalidIndices = 0 === ($throw & self::THROW_ON_INVALID_INDEX);
8689
$this->cacheItemPool = $cacheItemPool instanceof NullAdapter ? null : $cacheItemPool; // Replace the NullAdapter by the null value
8790
$this->ignoreInvalidProperty = 0 === ($throw & self::THROW_ON_INVALID_PROPERTY_PATH);

‎src/Symfony/Component/PropertyAccess/PropertyPathIterator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/PropertyAccess/PropertyPathIterator.php
+3-6Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,10 @@
2121
*/
2222
class PropertyPathIterator extends \ArrayIterator implements PropertyPathIteratorInterface
2323
{
24-
protected PropertyPathInterface $path;
25-
26-
public function __construct(PropertyPathInterface $path)
27-
{
24+
public function __construct(
25+
protected PropertyPathInterface $path,
26+
) {
2827
parent::__construct($path->getElements());
29-
30-
$this->path = $path;
3128
}
3229

3330
public function isIndex(): bool

‎src/Symfony/Component/Semaphore/Key.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Semaphore/Key.php
+5-8Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121
*/
2222
final class Key
2323
{
24-
private string $resource;
25-
private int $limit;
26-
private int $weight;
2724
private ?float $expiringTime = null;
2825
private array $state = [];
2926

30-
public function __construct(string $resource, int $limit, int $weight = 1)
31-
{
27+
public function __construct(
28+
private string $resource,
29+
private int $limit,
30+
private int $weight = 1,
31+
) {
3232
if (1 > $limit) {
3333
throw new InvalidArgumentException("The limit ($limit) should be greater than 0.");
3434
}
@@ -38,9 +38,6 @@ public function __construct(string $resource, int $limit, int $weight = 1)
3838
if ($weight > $limit) {
3939
throw new InvalidArgumentException("The weight ($weight) should be lower or equals to the limit ($limit).");
4040
}
41-
$this->resource = $resource;
42-
$this->limit = $limit;
43-
$this->weight = $weight;
4441
}
4542

4643
public function __toString(): string

‎src/Symfony/Component/Semaphore/Semaphore.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Semaphore/Semaphore.php
+6-10Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,14 @@ final class Semaphore implements SemaphoreInterface, LoggerAwareInterface
2929
{
3030
use LoggerAwareTrait;
3131

32-
private Key $key;
33-
private PersistingStoreInterface $store;
34-
private float $ttlInSecond;
35-
private bool $autoRelease;
3632
private bool $dirty = false;
3733

38-
public function __construct(Key $key, PersistingStoreInterface $store, float $ttlInSecond = 300.0, bool $autoRelease = true)
39-
{
40-
$this->store = $store;
41-
$this->key = $key;
42-
$this->ttlInSecond = $ttlInSecond;
43-
$this->autoRelease = $autoRelease;
34+
public function __construct(
35+
private Key $key,
36+
private PersistingStoreInterface $store,
37+
private float $ttlInSecond = 300.0,
38+
private bool $autoRelease = true,
39+
) {
4440
}
4541

4642
public function __sleep(): array

‎src/Symfony/Component/Stopwatch/Section.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Stopwatch/Section.php
+4-6Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ class Section
2323
*/
2424
private array $events = [];
2525

26-
private ?float $origin;
27-
private bool $morePrecision;
2826
private ?string $id = null;
2927

3028
/**
@@ -36,10 +34,10 @@ class Section
3634
* @param float|null $origin Set the origin of the events in this section, use null to set their origin to their start time
3735
* @param bool $morePrecision If true, time is stored as float to keep the original microsecond precision
3836
*/
39-
public function __construct(?float $origin = null, bool $morePrecision = false)
40-
{
41-
$this->origin = $origin;
42-
$this->morePrecision = $morePrecision;
37+
public function __construct(
38+
private ?float $origin = null,
39+
private bool $morePrecision = false,
40+
) {
4341
}
4442

4543
/**

‎src/Symfony/Component/Stopwatch/Stopwatch.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Stopwatch/Stopwatch.php
+3-5Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ class_exists(Section::class);
2323
*/
2424
class Stopwatch implements ResetInterface
2525
{
26-
private bool $morePrecision;
27-
2826
/**
2927
* @var Section[]
3028
*/
@@ -38,9 +36,9 @@ class Stopwatch implements ResetInterface
3836
/**
3937
* @param bool $morePrecision If true, time is stored as float to keep the original microsecond precision
4038
*/
41-
public function __construct(bool $morePrecision = false)
42-
{
43-
$this->morePrecision = $morePrecision;
39+
public function __construct(
40+
private bool $morePrecision = false,
41+
) {
4442
$this->reset();
4543
}
4644

‎src/Symfony/Component/Stopwatch/StopwatchEvent.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Stopwatch/StopwatchEvent.php
+6-4Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ class StopwatchEvent
2525

2626
private float $origin;
2727
private string $category;
28-
private bool $morePrecision;
2928

3029
/**
3130
* @var float[]
@@ -42,11 +41,14 @@ class StopwatchEvent
4241
*
4342
* @throws \InvalidArgumentException When the raw time is not valid
4443
*/
45-
public function __construct(float $origin, ?string $category = null, bool $morePrecision = false, ?string $name = null)
46-
{
44+
public function __construct(
45+
float $origin,
46+
?string $category = null,
47+
private bool $morePrecision = false,
48+
?string $name = null,
49+
) {
4750
$this->origin = $this->formatTime($origin);
4851
$this->category = \is_string($category) ? $category : 'default';
49-
$this->morePrecision = $morePrecision;
5052
$this->name = $name ?? 'default';
5153
}
5254

‎src/Symfony/Component/Yaml/Exception/ParseException.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Exception/ParseException.php
+8-13Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,19 @@
1818
*/
1919
class ParseException extends RuntimeException
2020
{
21-
private ?string $parsedFile;
22-
private int $parsedLine;
23-
private ?string $snippet;
24-
private string $rawMessage;
25-
2621
/**
27-
* @param string $message The error message
22+
* @param string $rawMessage The error message
2823
* @param int $parsedLine The line where the error occurred
2924
* @param string|null $snippet The snippet of code near the problem
3025
* @param string|null $parsedFile The file name where the error occurred
3126
*/
32-
public function __construct(string $message, int $parsedLine = -1, ?string $snippet = null, ?string $parsedFile = null, ?\Throwable $previous = null)
33-
{
34-
$this->parsedFile = $parsedFile;
35-
$this->parsedLine = $parsedLine;
36-
$this->snippet = $snippet;
37-
$this->rawMessage = $message;
38-
27+
public function __construct(
28+
private string $rawMessage,
29+
private int $parsedLine = -1,
30+
private ?string $snippet = null,
31+
private ?string $parsedFile = null,
32+
?\Throwable $previous = null,
33+
) {
3934
$this->updateRepr();
4035

4136
parent::__construct($this->message, 0, $previous);

‎src/Symfony/Component/Yaml/Tag/TaggedValue.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Tag/TaggedValue.php
+4-7Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,10 @@
1717
*/
1818
final class TaggedValue
1919
{
20-
private string $tag;
21-
private mixed $value;
22-
23-
public function __construct(string $tag, mixed $value)
24-
{
25-
$this->tag = $tag;
26-
$this->value = $value;
20+
public function __construct(
21+
private string $tag,
22+
private mixed $value,
23+
) {
2724
}
2825

2926
public function getTag(): string

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.