Skip to content

Commit 5d133b1

Browse files
committed
use constructor property promotion
1 parent 73b5874 commit 5d133b1

File tree

62 files changed

+331
-498
lines changed

Some content is hidden

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

62 files changed

+331
-498
lines changed

Authentication/AuthenticationUtils.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@
2323
*/
2424
class AuthenticationUtils
2525
{
26-
private RequestStack $requestStack;
27-
28-
public function __construct(RequestStack $requestStack)
29-
{
30-
$this->requestStack = $requestStack;
26+
public function __construct(
27+
private RequestStack $requestStack,
28+
) {
3129
}
3230

3331
public function getLastAuthenticationError(bool $clearSession = true): ?AuthenticationException

Authentication/AuthenticatorManager.php

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,28 +46,19 @@
4646
*/
4747
class AuthenticatorManager implements AuthenticatorManagerInterface, UserAuthenticatorInterface
4848
{
49-
private iterable $authenticators;
50-
private TokenStorageInterface $tokenStorage;
51-
private EventDispatcherInterface $eventDispatcher;
52-
private bool $eraseCredentials;
53-
private ?LoggerInterface $logger;
54-
private string $firewallName;
55-
private bool $hideUserNotFoundExceptions;
56-
private array $requiredBadges;
57-
5849
/**
5950
* @param iterable<mixed, AuthenticatorInterface> $authenticators
6051
*/
61-
public function __construct(iterable $authenticators, TokenStorageInterface $tokenStorage, EventDispatcherInterface $eventDispatcher, string $firewallName, ?LoggerInterface $logger = null, bool $eraseCredentials = true, bool $hideUserNotFoundExceptions = true, array $requiredBadges = [])
62-
{
63-
$this->authenticators = $authenticators;
64-
$this->tokenStorage = $tokenStorage;
65-
$this->eventDispatcher = $eventDispatcher;
66-
$this->firewallName = $firewallName;
67-
$this->logger = $logger;
68-
$this->eraseCredentials = $eraseCredentials;
69-
$this->hideUserNotFoundExceptions = $hideUserNotFoundExceptions;
70-
$this->requiredBadges = $requiredBadges;
52+
public function __construct(
53+
private iterable $authenticators,
54+
private TokenStorageInterface $tokenStorage,
55+
private EventDispatcherInterface $eventDispatcher,
56+
private string $firewallName,
57+
private ?LoggerInterface $logger = null,
58+
private bool $eraseCredentials = true,
59+
private bool $hideUserNotFoundExceptions = true,
60+
private array $requiredBadges = [],
61+
) {
7162
}
7263

7364
/**

Authentication/CustomAuthenticationFailureHandler.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@
2020
*/
2121
class CustomAuthenticationFailureHandler implements AuthenticationFailureHandlerInterface
2222
{
23-
private AuthenticationFailureHandlerInterface $handler;
24-
2523
/**
2624
* @param array $options Options for processing a successful authentication attempt
2725
*/
28-
public function __construct(AuthenticationFailureHandlerInterface $handler, array $options)
29-
{
30-
$this->handler = $handler;
26+
public function __construct(
27+
private AuthenticationFailureHandlerInterface $handler,
28+
array $options,
29+
) {
3130
if (method_exists($handler, 'setOptions')) {
3231
$this->handler->setOptions($options);
3332
}

Authentication/CustomAuthenticationSuccessHandler.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020
*/
2121
class CustomAuthenticationSuccessHandler implements AuthenticationSuccessHandlerInterface
2222
{
23-
private AuthenticationSuccessHandlerInterface $handler;
24-
2523
/**
2624
* @param array $options Options for processing a successful authentication attempt
2725
*/
28-
public function __construct(AuthenticationSuccessHandlerInterface $handler, array $options, string $firewallName)
29-
{
30-
$this->handler = $handler;
26+
public function __construct(
27+
private AuthenticationSuccessHandlerInterface $handler,
28+
array $options,
29+
string $firewallName,
30+
) {
3131
if (method_exists($handler, 'setOptions')) {
3232
$this->handler->setOptions($options);
3333
}

Authentication/DefaultAuthenticationFailureHandler.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,20 @@
3232
*/
3333
class DefaultAuthenticationFailureHandler implements AuthenticationFailureHandlerInterface
3434
{
35-
protected HttpKernelInterface $httpKernel;
36-
protected HttpUtils $httpUtils;
3735
protected array $options;
38-
protected ?LoggerInterface $logger;
3936
protected array $defaultOptions = [
4037
'failure_path' => null,
4138
'failure_forward' => false,
4239
'login_path' => '/login',
4340
'failure_path_parameter' => '_failure_path',
4441
];
4542

46-
public function __construct(HttpKernelInterface $httpKernel, HttpUtils $httpUtils, array $options = [], ?LoggerInterface $logger = null)
47-
{
48-
$this->httpKernel = $httpKernel;
49-
$this->httpUtils = $httpUtils;
50-
$this->logger = $logger;
43+
public function __construct(
44+
protected HttpKernelInterface $httpKernel,
45+
protected HttpUtils $httpUtils,
46+
array $options = [],
47+
protected ?LoggerInterface $logger = null,
48+
) {
5149
$this->setOptions($options);
5250
}
5351

Authentication/DefaultAuthenticationSuccessHandler.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ class DefaultAuthenticationSuccessHandler implements AuthenticationSuccessHandle
3030
{
3131
use TargetPathTrait;
3232

33-
protected HttpUtils $httpUtils;
3433
protected array $options;
35-
protected ?LoggerInterface $logger;
3634
protected ?string $firewallName = null;
3735
protected array $defaultOptions = [
3836
'always_use_default_target_path' => false,
@@ -45,10 +43,11 @@ class DefaultAuthenticationSuccessHandler implements AuthenticationSuccessHandle
4543
/**
4644
* @param array $options Options for processing a successful authentication attempt
4745
*/
48-
public function __construct(HttpUtils $httpUtils, array $options = [], ?LoggerInterface $logger = null)
49-
{
50-
$this->httpUtils = $httpUtils;
51-
$this->logger = $logger;
46+
public function __construct(
47+
protected HttpUtils $httpUtils,
48+
array $options = [],
49+
protected ?LoggerInterface $logger = null,
50+
) {
5251
$this->setOptions($options);
5352
}
5453

Authenticator/AbstractPreAuthenticatedAuthenticator.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,12 @@
3636
*/
3737
abstract class AbstractPreAuthenticatedAuthenticator implements InteractiveAuthenticatorInterface
3838
{
39-
private UserProviderInterface $userProvider;
40-
private TokenStorageInterface $tokenStorage;
41-
private string $firewallName;
42-
private ?LoggerInterface $logger;
43-
44-
public function __construct(UserProviderInterface $userProvider, TokenStorageInterface $tokenStorage, string $firewallName, ?LoggerInterface $logger = null)
45-
{
46-
$this->userProvider = $userProvider;
47-
$this->tokenStorage = $tokenStorage;
48-
$this->firewallName = $firewallName;
49-
$this->logger = $logger;
39+
public function __construct(
40+
private UserProviderInterface $userProvider,
41+
private TokenStorageInterface $tokenStorage,
42+
private string $firewallName,
43+
private ?LoggerInterface $logger = null
44+
) {
5045
}
5146

5247
/**

Authenticator/Debug/TraceableAuthenticatorManagerListener.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,12 @@
2525
*/
2626
final class TraceableAuthenticatorManagerListener extends AbstractListener implements ResetInterface
2727
{
28-
private AuthenticatorManagerListener $authenticationManagerListener;
2928
private array $authenticatorsInfo = [];
3029
private bool $hasVardumper;
3130

32-
public function __construct(AuthenticatorManagerListener $authenticationManagerListener)
33-
{
34-
$this->authenticationManagerListener = $authenticationManagerListener;
31+
public function __construct(
32+
private AuthenticatorManagerListener $authenticationManagerListener,
33+
) {
3534
$this->hasVardumper = class_exists(ClassStub::class);
3635
}
3736

Authenticator/FormLoginAuthenticator.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,16 @@
4040
*/
4141
class FormLoginAuthenticator extends AbstractLoginFormAuthenticator
4242
{
43-
private HttpUtils $httpUtils;
44-
private UserProviderInterface $userProvider;
45-
private AuthenticationSuccessHandlerInterface $successHandler;
46-
private AuthenticationFailureHandlerInterface $failureHandler;
4743
private array $options;
4844
private HttpKernelInterface $httpKernel;
4945

50-
public function __construct(HttpUtils $httpUtils, UserProviderInterface $userProvider, AuthenticationSuccessHandlerInterface $successHandler, AuthenticationFailureHandlerInterface $failureHandler, array $options)
51-
{
52-
$this->httpUtils = $httpUtils;
53-
$this->userProvider = $userProvider;
54-
$this->successHandler = $successHandler;
55-
$this->failureHandler = $failureHandler;
46+
public function __construct(
47+
private HttpUtils $httpUtils,
48+
private UserProviderInterface $userProvider,
49+
private AuthenticationSuccessHandlerInterface $successHandler,
50+
private AuthenticationFailureHandlerInterface $failureHandler,
51+
array $options,
52+
) {
5653
$this->options = array_merge([
5754
'username_parameter' => '_username',
5855
'password_parameter' => '_password',

Authenticator/HttpBasicAuthenticator.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,11 @@
3333
*/
3434
class HttpBasicAuthenticator implements AuthenticatorInterface, AuthenticationEntryPointInterface
3535
{
36-
private string $realmName;
37-
private UserProviderInterface $userProvider;
38-
private ?LoggerInterface $logger;
39-
40-
public function __construct(string $realmName, UserProviderInterface $userProvider, ?LoggerInterface $logger = null)
41-
{
42-
$this->realmName = $realmName;
43-
$this->userProvider = $userProvider;
44-
$this->logger = $logger;
36+
public function __construct(
37+
private string $realmName,
38+
private UserProviderInterface $userProvider,
39+
private ?LoggerInterface $logger = null,
40+
) {
4541
}
4642

4743
public function start(Request $request, ?AuthenticationException $authException = null): Response

Authenticator/JsonLoginAuthenticator.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,18 @@
4545
class JsonLoginAuthenticator implements InteractiveAuthenticatorInterface
4646
{
4747
private array $options;
48-
private HttpUtils $httpUtils;
49-
private UserProviderInterface $userProvider;
5048
private PropertyAccessorInterface $propertyAccessor;
51-
private ?AuthenticationSuccessHandlerInterface $successHandler;
52-
private ?AuthenticationFailureHandlerInterface $failureHandler;
5349
private ?TranslatorInterface $translator = null;
5450

55-
public function __construct(HttpUtils $httpUtils, UserProviderInterface $userProvider, ?AuthenticationSuccessHandlerInterface $successHandler = null, ?AuthenticationFailureHandlerInterface $failureHandler = null, array $options = [], ?PropertyAccessorInterface $propertyAccessor = null)
56-
{
51+
public function __construct(
52+
private HttpUtils $httpUtils,
53+
private UserProviderInterface $userProvider,
54+
private ?AuthenticationSuccessHandlerInterface $successHandler = null,
55+
private ?AuthenticationFailureHandlerInterface $failureHandler = null,
56+
array $options = [],
57+
?PropertyAccessorInterface $propertyAccessor = null,
58+
) {
5759
$this->options = array_merge(['username_path' => 'username', 'password_path' => 'password'], $options);
58-
$this->httpUtils = $httpUtils;
59-
$this->successHandler = $successHandler;
60-
$this->failureHandler = $failureHandler;
61-
$this->userProvider = $userProvider;
6260
$this->propertyAccessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor();
6361
}
6462

Authenticator/LoginLinkAuthenticator.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,15 @@
3131
*/
3232
final class LoginLinkAuthenticator extends AbstractAuthenticator implements InteractiveAuthenticatorInterface
3333
{
34-
private LoginLinkHandlerInterface $loginLinkHandler;
35-
private HttpUtils $httpUtils;
36-
private AuthenticationSuccessHandlerInterface $successHandler;
37-
private AuthenticationFailureHandlerInterface $failureHandler;
3834
private array $options;
3935

40-
public function __construct(LoginLinkHandlerInterface $loginLinkHandler, HttpUtils $httpUtils, AuthenticationSuccessHandlerInterface $successHandler, AuthenticationFailureHandlerInterface $failureHandler, array $options)
41-
{
42-
$this->loginLinkHandler = $loginLinkHandler;
43-
$this->httpUtils = $httpUtils;
44-
$this->successHandler = $successHandler;
45-
$this->failureHandler = $failureHandler;
36+
public function __construct(
37+
private LoginLinkHandlerInterface $loginLinkHandler,
38+
private HttpUtils $httpUtils,
39+
private AuthenticationSuccessHandlerInterface $successHandler,
40+
private AuthenticationFailureHandlerInterface $failureHandler,
41+
array $options,
42+
) {
4643
$this->options = $options + ['check_post_only' => false];
4744
}
4845

Authenticator/Passport/Badge/CsrfTokenBadge.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,16 @@
2525
class CsrfTokenBadge implements BadgeInterface
2626
{
2727
private bool $resolved = false;
28-
private string $csrfTokenId;
29-
private ?string $csrfToken;
3028

3129
/**
3230
* @param string $csrfTokenId An arbitrary string used to generate the value of the CSRF token.
3331
* Using a different string for each authenticator improves its security.
3432
* @param string|null $csrfToken The CSRF token presented in the request, if any
3533
*/
36-
public function __construct(string $csrfTokenId, #[\SensitiveParameter] ?string $csrfToken)
37-
{
38-
$this->csrfTokenId = $csrfTokenId;
39-
$this->csrfToken = $csrfToken;
34+
public function __construct(
35+
private string $csrfTokenId,
36+
#[\SensitiveParameter] private ?string $csrfToken,
37+
) {
4038
}
4139

4240
public function getCsrfTokenId(): string

Authenticator/Passport/Badge/PasswordUpgradeBadge.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@
2626
class PasswordUpgradeBadge implements BadgeInterface
2727
{
2828
private ?string $plaintextPassword = null;
29-
private ?PasswordUpgraderInterface $passwordUpgrader;
3029

3130
/**
3231
* @param string $plaintextPassword The presented password, used in the rehash
3332
* @param PasswordUpgraderInterface|null $passwordUpgrader The password upgrader, defaults to the UserProvider if null
3433
*/
35-
public function __construct(#[\SensitiveParameter] string $plaintextPassword, ?PasswordUpgraderInterface $passwordUpgrader = null)
36-
{
34+
public function __construct(
35+
#[\SensitiveParameter] string $plaintextPassword,
36+
private ?PasswordUpgraderInterface $passwordUpgrader = null,
37+
) {
3738
$this->plaintextPassword = $plaintextPassword;
38-
$this->passwordUpgrader = $passwordUpgrader;
3939
}
4040

4141
public function getAndErasePlaintextPassword(): string

Authenticator/Passport/Badge/UserBadge.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,9 @@ class UserBadge implements BadgeInterface
3030
{
3131
public const MAX_USERNAME_LENGTH = 4096;
3232

33-
private string $userIdentifier;
3433
/** @var callable|null */
3534
private $userLoader;
3635
private UserInterface $user;
37-
private ?array $attributes;
3836

3937
/**
4038
* Initializes the user badge.
@@ -49,15 +47,16 @@ class UserBadge implements BadgeInterface
4947
* is thrown). If this is not set, the default user provider will be used with
5048
* $userIdentifier as username.
5149
*/
52-
public function __construct(string $userIdentifier, ?callable $userLoader = null, ?array $attributes = null)
53-
{
50+
public function __construct(
51+
private string $userIdentifier,
52+
?callable $userLoader = null,
53+
private ?array $attributes = null,
54+
) {
5455
if (\strlen($userIdentifier) > self::MAX_USERNAME_LENGTH) {
5556
throw new BadCredentialsException('Username too long.');
5657
}
5758

58-
$this->userIdentifier = $userIdentifier;
5959
$this->userLoader = $userLoader;
60-
$this->attributes = $attributes;
6160
}
6261

6362
public function getUserIdentifier(): string

Authenticator/Passport/Credentials/CustomCredentials.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@
2424
class CustomCredentials implements CredentialsInterface
2525
{
2626
private \Closure $customCredentialsChecker;
27-
private mixed $credentials;
2827
private bool $resolved = false;
2928

3029
/**
3130
* @param callable $customCredentialsChecker the check function. If this function does not return `true`, a
3231
* BadCredentialsException is thrown. You may also throw a more
3332
* specific exception in the function.
3433
*/
35-
public function __construct(callable $customCredentialsChecker, mixed $credentials)
36-
{
34+
public function __construct(
35+
callable $customCredentialsChecker,
36+
private mixed $credentials,
37+
) {
3738
$this->customCredentialsChecker = $customCredentialsChecker(...);
38-
$this->credentials = $credentials;
3939
}
4040

4141
public function executeCustomChecker(UserInterface $user): void

0 commit comments

Comments
 (0)