Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0e786b6

Browse files
committed
minor #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

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

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

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

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@
2424
*/
2525
final class UnanimousStrategy 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/TraceableAccessDecisionManager.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,15 @@
2525
*/
2626
class TraceableAccessDecisionManager implements AccessDecisionManagerInterface
2727
{
28-
private AccessDecisionManagerInterface $manager;
2928
private ?AccessDecisionStrategyInterface $strategy = null;
3029
/** @var iterable<mixed, VoterInterface> */
3130
private iterable $voters = [];
3231
private array $decisionLog = []; // All decision logs
3332
private array $currentLog = []; // Logs being filled in
3433

35-
public function __construct(AccessDecisionManagerInterface $manager)
36-
{
37-
$this->manager = $manager;
38-
34+
public function __construct(
35+
private AccessDecisionManagerInterface $manager,
36+
) {
3937
// The strategy and voters are stored in a private properties of the decorated service
4038
if (property_exists($manager, 'strategy')) {
4139
$reflection = new \ReflectionProperty($manager::class, 'strategy');

src/Symfony/Component/Security/Core/Authorization/Voter/AuthenticatedVoter.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,9 @@ class AuthenticatedVoter implements CacheableVoterInterface
3333
public const IS_REMEMBERED = 'IS_REMEMBERED';
3434
public const PUBLIC_ACCESS = 'PUBLIC_ACCESS';
3535

36-
private AuthenticationTrustResolverInterface $authenticationTrustResolver;
37-
38-
public function __construct(AuthenticationTrustResolverInterface $authenticationTrustResolver)
39-
{
40-
$this->authenticationTrustResolver = $authenticationTrustResolver;
36+
public function __construct(
37+
private AuthenticationTrustResolverInterface $authenticationTrustResolver,
38+
) {
4139
}
4240

4341
public function vote(TokenInterface $token, mixed $subject, array $attributes): int

src/Symfony/Component/Security/Core/Authorization/Voter/ExpressionVoter.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,12 @@
2626
*/
2727
class ExpressionVoter implements CacheableVoterInterface
2828
{
29-
private ExpressionLanguage $expressionLanguage;
30-
private AuthenticationTrustResolverInterface $trustResolver;
31-
private AuthorizationCheckerInterface $authChecker;
32-
private ?RoleHierarchyInterface $roleHierarchy;
33-
34-
public function __construct(ExpressionLanguage $expressionLanguage, AuthenticationTrustResolverInterface $trustResolver, AuthorizationCheckerInterface $authChecker, ?RoleHierarchyInterface $roleHierarchy = null)
35-
{
36-
$this->expressionLanguage = $expressionLanguage;
37-
$this->trustResolver = $trustResolver;
38-
$this->authChecker = $authChecker;
39-
$this->roleHierarchy = $roleHierarchy;
29+
public function __construct(
30+
private ExpressionLanguage $expressionLanguage,
31+
private AuthenticationTrustResolverInterface $trustResolver,
32+
private AuthorizationCheckerInterface $authChecker,
33+
private ?RoleHierarchyInterface $roleHierarchy = null,
34+
) {
4035
}
4136

4237
public function supportsAttribute(string $attribute): bool

src/Symfony/Component/Security/Core/Authorization/Voter/RoleHierarchyVoter.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,10 @@
2222
*/
2323
class RoleHierarchyVoter extends RoleVoter
2424
{
25-
private RoleHierarchyInterface $roleHierarchy;
26-
27-
public function __construct(RoleHierarchyInterface $roleHierarchy, string $prefix = 'ROLE_')
28-
{
29-
$this->roleHierarchy = $roleHierarchy;
30-
25+
public function __construct(
26+
private RoleHierarchyInterface $roleHierarchy,
27+
string $prefix = 'ROLE_',
28+
) {
3129
parent::__construct($prefix);
3230
}
3331

src/Symfony/Component/Security/Core/Authorization/Voter/RoleVoter.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@
2020
*/
2121
class RoleVoter implements CacheableVoterInterface
2222
{
23-
private string $prefix;
24-
25-
public function __construct(string $prefix = 'ROLE_')
26-
{
27-
$this->prefix = $prefix;
23+
public function __construct(
24+
private string $prefix = 'ROLE_',
25+
) {
2826
}
2927

3028
public function vote(TokenInterface $token, mixed $subject, array $attributes): int

src/Symfony/Component/Security/Core/Authorization/Voter/TraceableVoter.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,10 @@
2424
*/
2525
class TraceableVoter implements CacheableVoterInterface
2626
{
27-
private VoterInterface $voter;
28-
private EventDispatcherInterface $eventDispatcher;
29-
30-
public function __construct(VoterInterface $voter, EventDispatcherInterface $eventDispatcher)
31-
{
32-
$this->voter = $voter;
33-
$this->eventDispatcher = $eventDispatcher;
27+
public function __construct(
28+
private VoterInterface $voter,
29+
private EventDispatcherInterface $eventDispatcher,
30+
) {
3431
}
3532

3633
public function vote(TokenInterface $token, mixed $subject, array $attributes): int

src/Symfony/Component/Security/Core/Event/AuthenticationEvent.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,13 @@
2121
*/
2222
class AuthenticationEvent extends Event
2323
{
24-
private TokenInterface $authenticationToken;
25-
26-
public function __construct(TokenInterface $token)
27-
{
28-
$this->authenticationToken = $token;
24+
public function __construct(
25+
private TokenInterface $token,
26+
) {
2927
}
3028

3129
public function getAuthenticationToken(): TokenInterface
3230
{
33-
return $this->authenticationToken;
31+
return $this->token;
3432
}
3533
}

0 commit comments

Comments
 (0)