Skip to content

Commit 0e786b6

Browse files
committed
minor symfony#57304 [Security] use constructor property promotion (xabbuh)
This PR was merged into the 7.2 branch. Discussion ---------- [Security] use constructor property promotion | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | | License | MIT Commits ------- b1e4439 use constructor property promotion
2 parents ee7ef2e + b1e4439 commit 0e786b6

File tree

95 files changed

+468
-707
lines changed

Some content is hidden

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

95 files changed

+468
-707
lines changed

src/Symfony/Component/Security/Core/Authentication/RememberMe/CacheTokenVerifier.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,17 @@
1818
*/
1919
class CacheTokenVerifier implements TokenVerifierInterface
2020
{
21-
private CacheItemPoolInterface $cache;
22-
private int $outdatedTokenTtl;
23-
private string $cacheKeyPrefix;
24-
2521
/**
2622
* @param int $outdatedTokenTtl How long the outdated token should still be considered valid. Defaults
2723
* to 60, which matches how often the PersistentRememberMeHandler will at
2824
* most refresh tokens. Increasing to more than that is not recommended,
2925
* but you may use a lower value.
3026
*/
31-
public function __construct(CacheItemPoolInterface $cache, int $outdatedTokenTtl = 60, string $cacheKeyPrefix = 'rememberme-stale-')
32-
{
33-
$this->cache = $cache;
34-
$this->outdatedTokenTtl = $outdatedTokenTtl;
35-
$this->cacheKeyPrefix = $cacheKeyPrefix;
27+
public function __construct(
28+
private CacheItemPoolInterface $cache,
29+
private int $outdatedTokenTtl = 60,
30+
private string $cacheKeyPrefix = 'rememberme-stale-',
31+
) {
3632
}
3733

3834
public function verifyToken(PersistentTokenInterface $token, #[\SensitiveParameter] string $tokenValue): bool

src/Symfony/Component/Security/Core/Authentication/RememberMe/PersistentToken.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818
*/
1919
final class PersistentToken implements PersistentTokenInterface
2020
{
21-
private string $class;
22-
private string $userIdentifier;
23-
private string $series;
24-
private string $tokenValue;
2521
private \DateTimeImmutable $lastUsed;
2622

27-
public function __construct(string $class, string $userIdentifier, string $series, #[\SensitiveParameter] string $tokenValue, \DateTimeInterface $lastUsed)
28-
{
23+
public function __construct(
24+
private string $class,
25+
private string $userIdentifier,
26+
private string $series,
27+
#[\SensitiveParameter] private string $tokenValue,
28+
\DateTimeInterface $lastUsed,
29+
) {
2930
if (!$class) {
3031
throw new \InvalidArgumentException('$class must not be empty.');
3132
}
@@ -39,10 +40,6 @@ public function __construct(string $class, string $userIdentifier, string $serie
3940
throw new \InvalidArgumentException('$tokenValue must not be empty.');
4041
}
4142

42-
$this->class = $class;
43-
$this->userIdentifier = $userIdentifier;
44-
$this->series = $series;
45-
$this->tokenValue = $tokenValue;
4643
$this->lastUsed = \DateTimeImmutable::createFromInterface($lastUsed);
4744
}
4845

src/Symfony/Component/Security/Core/Authentication/Token/PreAuthenticatedToken.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,21 @@
2020
*/
2121
class PreAuthenticatedToken extends AbstractToken
2222
{
23-
private string $firewallName;
24-
2523
/**
2624
* @param string[] $roles
2725
*/
28-
public function __construct(UserInterface $user, string $firewallName, array $roles = [])
29-
{
26+
public function __construct(
27+
UserInterface $user,
28+
private string $firewallName,
29+
array $roles = [],
30+
) {
3031
parent::__construct($roles);
3132

3233
if ('' === $firewallName) {
3334
throw new \InvalidArgumentException('$firewallName must not be empty.');
3435
}
3536

3637
$this->setUser($user);
37-
$this->firewallName = $firewallName;
3838
}
3939

4040
public function getFirewallName(): string

src/Symfony/Component/Security/Core/Authentication/Token/RememberMeToken.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@
2222
class RememberMeToken extends AbstractToken
2323
{
2424
private ?string $secret = null;
25-
private string $firewallName;
2625

2726
/**
2827
* @throws \InvalidArgumentException
2928
*/
30-
public function __construct(UserInterface $user, string $firewallName)
31-
{
29+
public function __construct(
30+
UserInterface $user,
31+
private string $firewallName,
32+
) {
3233
parent::__construct($user->getRoles());
3334

3435
if (\func_num_args() > 2) {
@@ -40,8 +41,6 @@ public function __construct(UserInterface $user, string $firewallName)
4041
throw new InvalidArgumentException('$firewallName must not be empty.');
4142
}
4243

43-
$this->firewallName = $firewallName;
44-
4544
$this->setUser($user);
4645
}
4746

src/Symfony/Component/Security/Core/Authentication/Token/Storage/UsageTrackingTokenStorage.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,12 @@
2424
*/
2525
final class UsageTrackingTokenStorage implements TokenStorageInterface, ServiceSubscriberInterface
2626
{
27-
private TokenStorageInterface $storage;
28-
private ContainerInterface $container;
2927
private bool $enableUsageTracking = false;
3028

31-
public function __construct(TokenStorageInterface $storage, ContainerInterface $container)
32-
{
33-
$this->storage = $storage;
34-
$this->container = $container;
29+
public function __construct(
30+
private TokenStorageInterface $storage,
31+
private ContainerInterface $container,
32+
) {
3533
}
3634

3735
public function getToken(): ?TokenInterface

src/Symfony/Component/Security/Core/Authentication/Token/SwitchUserToken.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
*/
2121
class SwitchUserToken extends UsernamePasswordToken
2222
{
23-
private TokenInterface $originalToken;
2423
private ?string $originatedFromUri = null;
2524

2625
/**
@@ -29,11 +28,15 @@ class SwitchUserToken extends UsernamePasswordToken
2928
*
3029
* @throws \InvalidArgumentException
3130
*/
32-
public function __construct(UserInterface $user, string $firewallName, array $roles, TokenInterface $originalToken, ?string $originatedFromUri = null)
33-
{
31+
public function __construct(
32+
UserInterface $user,
33+
string $firewallName,
34+
array $roles,
35+
private TokenInterface $originalToken,
36+
?string $originatedFromUri = null,
37+
) {
3438
parent::__construct($user, $firewallName, $roles);
3539

36-
$this->originalToken = $originalToken;
3740
$this->originatedFromUri = $originatedFromUri;
3841
}
3942

src/Symfony/Component/Security/Core/Authentication/Token/UsernamePasswordToken.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@
2020
*/
2121
class UsernamePasswordToken extends AbstractToken
2222
{
23-
private string $firewallName;
24-
25-
public function __construct(UserInterface $user, string $firewallName, array $roles = [])
26-
{
23+
public function __construct(
24+
UserInterface $user,
25+
private string $firewallName,
26+
array $roles = [],
27+
) {
2728
parent::__construct($roles);
2829

2930
if ('' === $firewallName) {
3031
throw new \InvalidArgumentException('$firewallName must not be empty.');
3132
}
3233

3334
$this->setUser($user);
34-
$this->firewallName = $firewallName;
3535
}
3636

3737
public function getFirewallName(): string

src/Symfony/Component/Security/Core/Authorization/AccessDecisionManager.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@ final class AccessDecisionManager implements AccessDecisionManagerInterface
3232
VoterInterface::ACCESS_ABSTAIN => true,
3333
];
3434

35-
private iterable $voters;
3635
private array $votersCacheAttributes = [];
3736
private array $votersCacheObject = [];
3837
private AccessDecisionStrategyInterface $strategy;
3938

4039
/**
4140
* @param iterable<mixed, VoterInterface> $voters An array or an iterator of VoterInterface instances
4241
*/
43-
public function __construct(iterable $voters = [], ?AccessDecisionStrategyInterface $strategy = null)
44-
{
45-
$this->voters = $voters;
42+
public function __construct(
43+
private iterable $voters = [],
44+
?AccessDecisionStrategyInterface $strategy = null,
45+
) {
4646
$this->strategy = $strategy ?? new AffirmativeStrategy();
4747
}
4848

src/Symfony/Component/Security/Core/Authorization/Strategy/AffirmativeStrategy.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@
2424
*/
2525
final class AffirmativeStrategy implements AccessDecisionStrategyInterface, \Stringable
2626
{
27-
private bool $allowIfAllAbstainDecisions;
28-
29-
public function __construct(bool $allowIfAllAbstainDecisions = false)
30-
{
31-
$this->allowIfAllAbstainDecisions = $allowIfAllAbstainDecisions;
27+
public function __construct(
28+
private bool $allowIfAllAbstainDecisions = false,
29+
) {
3230
}
3331

3432
public function decide(\Traversable $results): bool

src/Symfony/Component/Security/Core/Authorization/Strategy/ConsensusStrategy.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,10 @@
3232
*/
3333
final class ConsensusStrategy implements AccessDecisionStrategyInterface, \Stringable
3434
{
35-
private bool $allowIfAllAbstainDecisions;
36-
private bool $allowIfEqualGrantedDeniedDecisions;
37-
38-
public function __construct(bool $allowIfAllAbstainDecisions = false, bool $allowIfEqualGrantedDeniedDecisions = true)
39-
{
40-
$this->allowIfAllAbstainDecisions = $allowIfAllAbstainDecisions;
41-
$this->allowIfEqualGrantedDeniedDecisions = $allowIfEqualGrantedDeniedDecisions;
35+
public function __construct(
36+
private bool $allowIfAllAbstainDecisions = false,
37+
private bool $allowIfEqualGrantedDeniedDecisions = true,
38+
) {
4239
}
4340

4441
public function decide(\Traversable $results): bool

0 commit comments

Comments
 (0)