From 51f8ec3decaa203bc82a6c60cf26b0c7ac2f69f2 Mon Sep 17 00:00:00 2001 From: Christian Scheb Date: Sat, 4 Nov 2023 13:20:53 +0100 Subject: [PATCH] Apply phpcs fixes --- app/src/Entity/User.php | 12 +++---- phpcs.xml.dist | 1 + .../EventListener/CheckBackupCodeListener.php | 2 +- src/bundle/Controller/FormController.php | 4 +-- .../Factory/Security/TwoFactorFactory.php | 8 ++--- .../SchebTwoFactorExtension.php | 2 +- .../Persister/DoctrinePersisterFactory.php | 4 +-- .../Model/PreferredProviderInterface.php | 2 +- .../AuthenticationTrustResolver.php | 10 +++--- .../TwoFactorProviderNotFoundException.php | 5 +-- .../Authentication/Token/TwoFactorToken.php | 25 +++++---------- .../Token/TwoFactorTokenInterface.php | 2 +- .../Authorization/TwoFactorAccessDecider.php | 4 +-- .../Voter/TwoFactorInProgressVoter.php | 2 +- .../Credentials/TwoFactorCodeCredentials.php | 2 +- .../Authenticator/TwoFactorAuthenticator.php | 8 ++--- .../CheckTwoFactorCodeListener.php | 4 +-- .../SuppressRememberMeListener.php | 2 +- .../Http/Firewall/ExceptionListener.php | 2 +- .../Http/Firewall/TwoFactorAccessListener.php | 2 +- .../Security/Http/Utils/JsonRequestUtils.php | 2 +- .../Security/Http/Utils/ParameterBagUtils.php | 4 +-- .../TwoFactor/AuthenticationContext.php | 2 +- .../TwoFactor/Csrf/NullCsrfTokenManager.php | 2 +- .../AuthenticationSuccessEventSuppressor.php | 2 +- .../Event/AuthenticationTokenListener.php | 4 +-- .../TwoFactor/Event/TwoFactorFormListener.php | 2 +- .../DefaultIpWhitelistProvider.php | 6 +--- .../Provider/TwoFactorProviderInitiator.php | 4 +-- .../TwoFactorProviderPreparationListener.php | 8 ++--- src/email/Mailer/SymfonyAuthCodeMailer.php | 4 +-- src/email/Model/Email/TwoFactorInterface.php | 2 +- .../Model/Google/TwoFactorInterface.php | 2 +- .../Provider/Google/GoogleTotpFactory.php | 4 +-- src/totp/Model/Totp/TotpConfiguration.php | 8 ++--- src/totp/Model/Totp/TwoFactorInterface.php | 2 +- .../TwoFactor/Provider/Totp/TotpFactory.php | 6 ++-- .../EventListener/TrustedDeviceListener.php | 2 +- .../TwoFactor/Trusted/JwtTokenEncoder.php | 4 +-- .../Trusted/TrustedCookieResponseListener.php | 12 +++---- .../Trusted/TrustedDeviceTokenEncoder.php | 2 +- .../Trusted/TrustedDeviceTokenStorage.php | 6 ++-- tests/Controller/FormControllerTest.php | 6 ++-- .../Factory/Security/TwoFactorFactoryTest.php | 4 +-- .../Security/TwoFactorServicesFactoryTest.php | 22 ++++++------- .../SchebTwoFactorExtensionTest.php | 12 +++---- .../Token/TwoFactorTokenTest.php | 2 +- .../TwoFactorAccessDeciderTest.php | 4 +-- .../Voter/TwoFactorInProgressVoterTest.php | 2 +- ...faultAuthenticationRequiredHandlerTest.php | 2 +- .../TwoFactorAuthenticatorTest.php | 12 ++++--- .../AbstractCheckCodeListenerTestSetup.php | 2 +- .../CheckBackupCodeListenerTest.php | 1 + .../CheckTwoFactorCodeListenerTest.php | 1 + .../SuppressRememberMeListenerTest.php | 2 +- .../Http/Firewall/ExceptionListenerTest.php | 4 +-- .../Firewall/TwoFactorAccessListenerTest.php | 2 +- .../AuthenticationContextFactoryTest.php | 2 +- .../AbstractAuthenticationContextTestCase.php | 2 +- .../Event/AuthenticationTokenListenerTest.php | 2 +- .../Email/EmailTwoFactorProviderTest.php | 2 +- .../Email/Generator/CodeGeneratorTest.php | 2 +- ...ogleAuthenticatorTwoFactorProviderTest.php | 4 +-- .../Provider/Google/GoogleTotpFactoryTest.php | 4 +-- ...TotpAuthenticatorTwoFactorProviderTest.php | 4 +-- .../Provider/Totp/TotpFactoryTest.php | 4 +-- ...oFactorProviderPreparationListenerTest.php | 4 +-- .../TwoFactor/Trusted/JwtTokenEncoderTest.php | 8 ++--- .../TrustedCookieResponseListenerTest.php | 10 +++--- .../Trusted/TrustedDeviceTokenStorageTest.php | 32 +++++++++---------- .../TwoFactor/TwoFactorFirewallConfigTest.php | 2 +- tests/TestCase.php | 1 - 72 files changed, 171 insertions(+), 183 deletions(-) diff --git a/app/src/Entity/User.php b/app/src/Entity/User.php index 8278ec37..8cfe2c27 100644 --- a/app/src/Entity/User.php +++ b/app/src/Entity/User.php @@ -41,13 +41,13 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface, EmailTw private bool $emailAuthenticationEnabled = true; #[ORM\Column(type: 'integer')] - private ?string $emailAuthenticationCode = null; + private string|null $emailAuthenticationCode = null; #[ORM\Column(type: 'boolean')] private bool $googleAuthenticatorEnabled = true; #[ORM\Column(type: 'string')] - private ?string $googleAuthenticatorSecret = null; + private string|null $googleAuthenticatorSecret = null; #[ORM\Column(type: 'boolean')] private bool $totpAuthenticationEnabled = true; @@ -72,12 +72,12 @@ public function getEmail(): string return $this->email; } - public function getSalt(): ?string + public function getSalt(): string|null { return null; } - public function getPassword(): ?string + public function getPassword(): string|null { return $this->password; } @@ -163,7 +163,7 @@ public function getGoogleAuthenticatorSecret(): string return $this->googleAuthenticatorSecret; } - public function setGoogleAuthenticatorSecret(?string $googleAuthenticatorSecret): void + public function setGoogleAuthenticatorSecret(string|null $googleAuthenticatorSecret): void { $this->googleAuthenticatorSecret = $googleAuthenticatorSecret; } @@ -183,7 +183,7 @@ public function getTotpAuthenticationUsername(): string return $this->username; } - public function getTotpAuthenticationConfiguration(): ?TotpConfigurationInterface + public function getTotpAuthenticationConfiguration(): TotpConfigurationInterface|null { return new TotpConfiguration($this->googleAuthenticatorSecret, TotpConfiguration::ALGORITHM_SHA1, 30, 6); } diff --git a/phpcs.xml.dist b/phpcs.xml.dist index e1ff2d44..be675947 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -33,6 +33,7 @@ + diff --git a/src/backup-code/Security/Http/EventListener/CheckBackupCodeListener.php b/src/backup-code/Security/Http/EventListener/CheckBackupCodeListener.php index 22108ca4..5bdda600 100644 --- a/src/backup-code/Security/Http/EventListener/CheckBackupCodeListener.php +++ b/src/backup-code/Security/Http/EventListener/CheckBackupCodeListener.php @@ -36,7 +36,7 @@ protected function isValidCode(string $providerName, object $user, string $code) } /** - * {@inheritdoc} + * {@inheritDoc} */ public static function getSubscribedEvents(): array { diff --git a/src/bundle/Controller/FormController.php b/src/bundle/Controller/FormController.php index de8211dd..8422c75e 100644 --- a/src/bundle/Controller/FormController.php +++ b/src/bundle/Controller/FormController.php @@ -28,7 +28,7 @@ public function __construct( private TwoFactorProviderRegistry $providerRegistry, private TwoFactorFirewallContext $twoFactorFirewallContext, private LogoutUrlGenerator $logoutUrlGenerator, - private ?TrustedDeviceManagerInterface $trustedDeviceManager, + private TrustedDeviceManagerInterface|null $trustedDeviceManager, private bool $trustedFeatureEnabled, ) { } @@ -107,7 +107,7 @@ protected function renderForm(string $providerName, Request $request, TwoFactorT return $renderer->renderForm($request, $templateVars); } - protected function getLastAuthenticationException(SessionInterface $session): ?AuthenticationException + protected function getLastAuthenticationException(SessionInterface $session): AuthenticationException|null { $authException = $session->get(SecurityRequestAttributes::AUTHENTICATION_ERROR); if ($authException instanceof AuthenticationException) { diff --git a/src/bundle/DependencyInjection/Factory/Security/TwoFactorFactory.php b/src/bundle/DependencyInjection/Factory/Security/TwoFactorFactory.php index 9169063e..7e262b1f 100644 --- a/src/bundle/DependencyInjection/Factory/Security/TwoFactorFactory.php +++ b/src/bundle/DependencyInjection/Factory/Security/TwoFactorFactory.php @@ -95,7 +95,7 @@ public function addConfiguration(NodeDefinition $builder): void } /** - * {@inheritdoc} + * {@inheritDoc} */ public function createAuthenticator(ContainerBuilder $container, string $firewallName, array $config, string $userProviderId): string { @@ -115,7 +115,7 @@ public function createAuthenticator(ContainerBuilder $container, string $firewal $twoFactorFirewallConfigId, $successHandlerId, $failureHandlerId, - $authRequiredHandlerId + $authRequiredHandlerId, ); } @@ -125,7 +125,7 @@ private function createAuthenticatorService( string $twoFactorFirewallConfigId, string $successHandlerId, string $failureHandlerId, - string $authRequiredHandlerId + string $authRequiredHandlerId, ): string { $authenticatorId = self::AUTHENTICATOR_ID_PREFIX.$firewallName; $container @@ -149,7 +149,7 @@ private function createAuthenticationTokenCreatedListener(ContainerBuilder $cont } /** - * {@inheritdoc} + * {@inheritDoc} */ public function createListeners(ContainerBuilder $container, string $firewallName, array $config): array { diff --git a/src/bundle/DependencyInjection/SchebTwoFactorExtension.php b/src/bundle/DependencyInjection/SchebTwoFactorExtension.php index 3573b336..1a750518 100644 --- a/src/bundle/DependencyInjection/SchebTwoFactorExtension.php +++ b/src/bundle/DependencyInjection/SchebTwoFactorExtension.php @@ -21,7 +21,7 @@ class SchebTwoFactorExtension extends Extension { /** - * {@inheritdoc} + * {@inheritDoc} */ public function load(array $configs, ContainerBuilder $container): void { diff --git a/src/bundle/Model/Persister/DoctrinePersisterFactory.php b/src/bundle/Model/Persister/DoctrinePersisterFactory.php index 1128d5ee..a1a167ac 100644 --- a/src/bundle/Model/Persister/DoctrinePersisterFactory.php +++ b/src/bundle/Model/Persister/DoctrinePersisterFactory.php @@ -18,8 +18,8 @@ class DoctrinePersisterFactory private ManagerRegistry $managerRegistry; public function __construct( - ?ManagerRegistry $managerRegistry, - private ?string $objectManagerName, + ManagerRegistry|null $managerRegistry, + private string|null $objectManagerName, ) { if (null === $managerRegistry) { $msg = 'scheb/2fa-bundle requires Doctrine to manage the user entity. If you don\'t want something else '; diff --git a/src/bundle/Model/PreferredProviderInterface.php b/src/bundle/Model/PreferredProviderInterface.php index 853f73ea..ab614bc5 100644 --- a/src/bundle/Model/PreferredProviderInterface.php +++ b/src/bundle/Model/PreferredProviderInterface.php @@ -9,5 +9,5 @@ interface PreferredProviderInterface /** * Return the alias of the preferred two-factor provider (if chosen by the user). */ - public function getPreferredTwoFactorProvider(): ?string; + public function getPreferredTwoFactorProvider(): string|null; } diff --git a/src/bundle/Security/Authentication/AuthenticationTrustResolver.php b/src/bundle/Security/Authentication/AuthenticationTrustResolver.php index ea9e7fbd..f2ab5bbd 100644 --- a/src/bundle/Security/Authentication/AuthenticationTrustResolver.php +++ b/src/bundle/Security/Authentication/AuthenticationTrustResolver.php @@ -24,7 +24,7 @@ public function __construct(private AuthenticationTrustResolverInterface $decora * * @deprecated since Symfony 5.4, use !isAuthenticated() instead */ - public function isAnonymous(?TokenInterface $token = null): bool + public function isAnonymous(TokenInterface|null $token = null): bool { if (!method_exists($this->decoratedTrustResolver, 'isAnonymous')) { throw new RuntimeException('Method "isAnonymous" was not declared on the decorated AuthenticationTrustResolverInterface'); @@ -33,12 +33,12 @@ public function isAnonymous(?TokenInterface $token = null): bool return $this->decoratedTrustResolver->isAnonymous($token); } - public function isRememberMe(?TokenInterface $token = null): bool + public function isRememberMe(TokenInterface|null $token = null): bool { return $this->decoratedTrustResolver->isRememberMe($token); } - public function isFullFledged(?TokenInterface $token = null): bool + public function isFullFledged(TokenInterface|null $token = null): bool { return !$this->isTwoFactorToken($token) && $this->decoratedTrustResolver->isFullFledged($token); } @@ -46,7 +46,7 @@ public function isFullFledged(?TokenInterface $token = null): bool /** * Compatibility for Symfony >= 5.4. */ - public function isAuthenticated(?TokenInterface $token = null): bool + public function isAuthenticated(TokenInterface|null $token = null): bool { // The "isAuthenticated" method must be declared in Symfony >= 6.0 if (method_exists($this->decoratedTrustResolver, 'isAuthenticated')) { @@ -62,7 +62,7 @@ public function isAuthenticated(?TokenInterface $token = null): bool throw new RuntimeException('Neither method "isAuthenticated" nor "isAnonymous" was declared on the decorated AuthenticationTrustResolverInterface'); } - private function isTwoFactorToken(?TokenInterface $token): bool + private function isTwoFactorToken(TokenInterface|null $token): bool { return $token instanceof TwoFactorTokenInterface; } diff --git a/src/bundle/Security/Authentication/Exception/TwoFactorProviderNotFoundException.php b/src/bundle/Security/Authentication/Exception/TwoFactorProviderNotFoundException.php index 4dfd9997..cfd2e3ea 100644 --- a/src/bundle/Security/Authentication/Exception/TwoFactorProviderNotFoundException.php +++ b/src/bundle/Security/Authentication/Exception/TwoFactorProviderNotFoundException.php @@ -14,14 +14,14 @@ class TwoFactorProviderNotFoundException extends AuthenticationException public const MESSAGE_KEY = 'Two-factor provider not found.'; /** @psalm-suppress PropertyNotSetInConstructor */ - private ?string $provider; + private string|null $provider; public function getMessageKey(): string { return self::MESSAGE_KEY; } - public function getProvider(): ?string + public function getProvider(): string|null { return $this->provider; } @@ -53,6 +53,7 @@ public function __serialize(): array public function __unserialize(array $data): void { [$this->provider, $parentData] = $data; + parent::__unserialize($parentData); } } diff --git a/src/bundle/Security/Authentication/Token/TwoFactorToken.php b/src/bundle/Security/Authentication/Token/TwoFactorToken.php index 1a08d1c8..e371e92e 100644 --- a/src/bundle/Security/Authentication/Token/TwoFactorToken.php +++ b/src/bundle/Security/Authentication/Token/TwoFactorToken.php @@ -9,7 +9,6 @@ use RuntimeException; use Scheb\TwoFactorBundle\Security\TwoFactor\Provider\Exception\UnknownTwoFactorProviderException; use Scheb\TwoFactorBundle\Security\UsernameHelper; -use Stringable; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; use Symfony\Component\Security\Core\User\UserInterface; use function array_key_exists; @@ -22,16 +21,11 @@ use function sprintf; use function unserialize; -class TwoFactorToken implements TwoFactorTokenInterface, Stringable +class TwoFactorToken implements TwoFactorTokenInterface { - private TokenInterface $authenticatedToken; - /** @var array */ private array $attributes = []; - /** @var string[] */ - private array $twoFactorProviders; - /** @var bool[] */ private array $preparedProviders = []; @@ -39,17 +33,14 @@ class TwoFactorToken implements TwoFactorTokenInterface, Stringable * @param string[] $twoFactorProviders */ public function __construct( - TokenInterface $authenticatedToken, - private ?string $credentials, + private TokenInterface $authenticatedToken, + private string|null $credentials, private string $firewallName, - array $twoFactorProviders, + private array $twoFactorProviders, ) { if (null === $authenticatedToken->getUser()) { throw new InvalidArgumentException('The authenticated token must have a user object set.'); } - - $this->authenticatedToken = $authenticatedToken; - $this->twoFactorProviders = $twoFactorProviders; } public function getUser(): UserInterface @@ -98,7 +89,7 @@ public function getRoles(): array } /** - * {@inheritdoc} + * {@inheritDoc} */ public function getRoleNames(): array { @@ -117,7 +108,7 @@ public function createWithCredentials(string $credentials): TwoFactorTokenInterf return $credentialsToken; } - public function getCredentials(): ?string + public function getCredentials(): string|null { return $this->credentials; } @@ -133,7 +124,7 @@ public function getAuthenticatedToken(): TokenInterface } /** - * {@inheritdoc} + * {@inheritDoc} */ public function getTwoFactorProviders(): array { @@ -146,7 +137,7 @@ public function preferTwoFactorProvider(string $preferredProvider): void array_unshift($this->twoFactorProviders, $preferredProvider); } - public function getCurrentTwoFactorProvider(): ?string + public function getCurrentTwoFactorProvider(): string|null { $first = reset($this->twoFactorProviders); diff --git a/src/bundle/Security/Authentication/Token/TwoFactorTokenInterface.php b/src/bundle/Security/Authentication/Token/TwoFactorTokenInterface.php index 59726b2f..029df1e6 100644 --- a/src/bundle/Security/Authentication/Token/TwoFactorTokenInterface.php +++ b/src/bundle/Security/Authentication/Token/TwoFactorTokenInterface.php @@ -51,7 +51,7 @@ public function preferTwoFactorProvider(string $preferredProvider): void; /** * Return the alias of the two-factor provider, which is currently active. */ - public function getCurrentTwoFactorProvider(): ?string; + public function getCurrentTwoFactorProvider(): string|null; /** * Flag a two-factor provider as complete. The provider's alias is passed as the argument. diff --git a/src/bundle/Security/Authorization/TwoFactorAccessDecider.php b/src/bundle/Security/Authorization/TwoFactorAccessDecider.php index e0f6a786..c3d4d0f6 100644 --- a/src/bundle/Security/Authorization/TwoFactorAccessDecider.php +++ b/src/bundle/Security/Authorization/TwoFactorAccessDecider.php @@ -56,13 +56,13 @@ public function isAccessible(Request $request, TokenInterface $token): bool // sorting the LogoutListener in programmatically. When a lazy firewall is used, the LogoutListener is executed // last, because all other listeners are encapsulated into LazyFirewallContext, which is invoked first. $logoutPath = $this->removeQueryParameters( - $this->makeRelativeToBaseUrl($this->logoutUrlGenerator->getLogoutPath(), $request) + $this->makeRelativeToBaseUrl($this->logoutUrlGenerator->getLogoutPath(), $request), ); return $this->httpUtils->checkRequestPath($request, $logoutPath); // Let the logout route pass } - private function isPubliclyAccessAttribute(?array $attributes): bool + private function isPubliclyAccessAttribute(array|null $attributes): bool { if (null === $attributes) { // No access control at all is treated "non-public" by 2fa diff --git a/src/bundle/Security/Authorization/Voter/TwoFactorInProgressVoter.php b/src/bundle/Security/Authorization/Voter/TwoFactorInProgressVoter.php index ad76cfd5..14e9a2d3 100644 --- a/src/bundle/Security/Authorization/Voter/TwoFactorInProgressVoter.php +++ b/src/bundle/Security/Authorization/Voter/TwoFactorInProgressVoter.php @@ -18,7 +18,7 @@ class TwoFactorInProgressVoter implements VoterInterface public const IS_AUTHENTICATED_2FA_IN_PROGRESS = 'IS_AUTHENTICATED_2FA_IN_PROGRESS'; /** - * {@inheritdoc} + * {@inheritDoc} */ public function vote(TokenInterface $token, mixed $subject, array $attributes): int { diff --git a/src/bundle/Security/Http/Authenticator/Passport/Credentials/TwoFactorCodeCredentials.php b/src/bundle/Security/Http/Authenticator/Passport/Credentials/TwoFactorCodeCredentials.php index 7ca531c0..72a8b0b1 100644 --- a/src/bundle/Security/Http/Authenticator/Passport/Credentials/TwoFactorCodeCredentials.php +++ b/src/bundle/Security/Http/Authenticator/Passport/Credentials/TwoFactorCodeCredentials.php @@ -17,7 +17,7 @@ class TwoFactorCodeCredentials implements CredentialsInterface public function __construct( private TwoFactorTokenInterface $twoFactorToken, - private ?string $code, + private string|null $code, ) { } diff --git a/src/bundle/Security/Http/Authenticator/TwoFactorAuthenticator.php b/src/bundle/Security/Http/Authenticator/TwoFactorAuthenticator.php index ea13572f..70969258 100644 --- a/src/bundle/Security/Http/Authenticator/TwoFactorAuthenticator.php +++ b/src/bundle/Security/Http/Authenticator/TwoFactorAuthenticator.php @@ -50,12 +50,12 @@ public function __construct( private AuthenticationFailureHandlerInterface $failureHandler, private AuthenticationRequiredHandlerInterface $authenticationRequiredHandler, private EventDispatcherInterface $eventDispatcher, - ?LoggerInterface $logger = null + LoggerInterface|null $logger = null, ) { $this->logger = $logger ?? new NullLogger(); } - public function supports(Request $request): ?bool + public function supports(Request $request): bool|null { return $this->twoFactorFirewallConfig->isCheckPathRequest($request); } @@ -142,7 +142,7 @@ private function isAuthenticationComplete(TwoFactorTokenInterface $token): bool return !$this->twoFactorFirewallConfig->isMultiFactor() || $token->allTwoFactorProvidersAuthenticated(); } - public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response + public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): Response|null { $this->logger->info('User has been two-factor authenticated successfully.', ['username' => UsernameHelper::getTokenUsername($token)]); $this->dispatchTwoFactorAuthenticationEvent(TwoFactorAuthenticationEvents::SUCCESS, $request, $token); @@ -159,7 +159,7 @@ public function onAuthenticationSuccess(Request $request, TokenInterface $token, return $this->successHandler->onAuthenticationSuccess($request, $token); } - public function onAuthenticationFailure(Request $request, AuthenticationException $exception): ?Response + public function onAuthenticationFailure(Request $request, AuthenticationException $exception): Response|null { $currentToken = $this->tokenStorage->getToken(); assert($currentToken instanceof TwoFactorTokenInterface); diff --git a/src/bundle/Security/Http/EventListener/CheckTwoFactorCodeListener.php b/src/bundle/Security/Http/EventListener/CheckTwoFactorCodeListener.php index 5461279a..f1d6a085 100644 --- a/src/bundle/Security/Http/EventListener/CheckTwoFactorCodeListener.php +++ b/src/bundle/Security/Http/EventListener/CheckTwoFactorCodeListener.php @@ -20,7 +20,7 @@ class CheckTwoFactorCodeListener extends AbstractCheckCodeListener public function __construct( PreparationRecorderInterface $preparationRecorder, - private TwoFactorProviderRegistry $providerRegistry + private TwoFactorProviderRegistry $providerRegistry, ) { parent::__construct($preparationRecorder); } @@ -44,7 +44,7 @@ protected function isValidCode(string $providerName, object $user, string $code) } /** - * {@inheritdoc} + * {@inheritDoc} */ public static function getSubscribedEvents(): array { diff --git a/src/bundle/Security/Http/EventListener/SuppressRememberMeListener.php b/src/bundle/Security/Http/EventListener/SuppressRememberMeListener.php index a0931403..8402363c 100644 --- a/src/bundle/Security/Http/EventListener/SuppressRememberMeListener.php +++ b/src/bundle/Security/Http/EventListener/SuppressRememberMeListener.php @@ -39,7 +39,7 @@ public function onSuccessfulLogin(LoginSuccessEvent $event): void } /** - * {@inheritdoc} + * {@inheritDoc} */ public static function getSubscribedEvents(): array { diff --git a/src/bundle/Security/Http/Firewall/ExceptionListener.php b/src/bundle/Security/Http/Firewall/ExceptionListener.php index e436eb4a..6d3f37d0 100644 --- a/src/bundle/Security/Http/Firewall/ExceptionListener.php +++ b/src/bundle/Security/Http/Firewall/ExceptionListener.php @@ -66,7 +66,7 @@ private function handleAccessDeniedException(ExceptionEvent $exceptionEvent): vo } /** - * {@inheritdoc} + * {@inheritDoc} */ public static function getSubscribedEvents(): array { diff --git a/src/bundle/Security/Http/Firewall/TwoFactorAccessListener.php b/src/bundle/Security/Http/Firewall/TwoFactorAccessListener.php index c6537eb5..03abe017 100644 --- a/src/bundle/Security/Http/Firewall/TwoFactorAccessListener.php +++ b/src/bundle/Security/Http/Firewall/TwoFactorAccessListener.php @@ -28,7 +28,7 @@ public function __construct( ) { } - public function supports(Request $request): ?bool + public function supports(Request $request): bool|null { // When the path is explicitly configured for anonymous access, no need to check access (important for lazy // firewalls, to prevent the response cache control to be flagged "private") diff --git a/src/bundle/Security/Http/Utils/JsonRequestUtils.php b/src/bundle/Security/Http/Utils/JsonRequestUtils.php index 0bdb6e41..7af1a834 100644 --- a/src/bundle/Security/Http/Utils/JsonRequestUtils.php +++ b/src/bundle/Security/Http/Utils/JsonRequestUtils.php @@ -22,7 +22,7 @@ */ class JsonRequestUtils { - private static ?PropertyAccessor $propertyAccessor = null; + private static PropertyAccessor|null $propertyAccessor = null; public static function isJsonRequest(Request $request): bool { diff --git a/src/bundle/Security/Http/Utils/ParameterBagUtils.php b/src/bundle/Security/Http/Utils/ParameterBagUtils.php index c38d885f..ba320a18 100644 --- a/src/bundle/Security/Http/Utils/ParameterBagUtils.php +++ b/src/bundle/Security/Http/Utils/ParameterBagUtils.php @@ -18,7 +18,7 @@ */ class ParameterBagUtils { - private static ?PropertyAccessor $propertyAccessor = null; + private static PropertyAccessor|null $propertyAccessor = null; /** * @see \Symfony\Component\Security\Http\ParameterBagUtils @@ -26,7 +26,7 @@ class ParameterBagUtils * Returns a request "parameter" value. * Paths like foo[bar] will be evaluated to find deeper items in nested data structures. */ - public static function getRequestParameterValue(Request $request, string $path): ?string + public static function getRequestParameterValue(Request $request, string $path): string|null { $pos = strpos($path, '['); if (false === $pos) { diff --git a/src/bundle/Security/TwoFactor/AuthenticationContext.php b/src/bundle/Security/TwoFactor/AuthenticationContext.php index 50a0168e..0cdd97b5 100644 --- a/src/bundle/Security/TwoFactor/AuthenticationContext.php +++ b/src/bundle/Security/TwoFactor/AuthenticationContext.php @@ -16,7 +16,7 @@ public function __construct( private Request $request, private TokenInterface $token, private Passport $passport, - private string $firewallName + private string $firewallName, ) { } diff --git a/src/bundle/Security/TwoFactor/Csrf/NullCsrfTokenManager.php b/src/bundle/Security/TwoFactor/Csrf/NullCsrfTokenManager.php index d93ccf72..d160da49 100644 --- a/src/bundle/Security/TwoFactor/Csrf/NullCsrfTokenManager.php +++ b/src/bundle/Security/TwoFactor/Csrf/NullCsrfTokenManager.php @@ -22,7 +22,7 @@ public function refreshToken(string $tokenId): CsrfToken return new CsrfToken($tokenId, ''); } - public function removeToken(string $tokenId): ?string + public function removeToken(string $tokenId): string|null { return null; } diff --git a/src/bundle/Security/TwoFactor/Event/AuthenticationSuccessEventSuppressor.php b/src/bundle/Security/TwoFactor/Event/AuthenticationSuccessEventSuppressor.php index 9ba1cd3b..8b871258 100644 --- a/src/bundle/Security/TwoFactor/Event/AuthenticationSuccessEventSuppressor.php +++ b/src/bundle/Security/TwoFactor/Event/AuthenticationSuccessEventSuppressor.php @@ -32,7 +32,7 @@ public function onLogin(AuthenticationEvent $event): void } /** - * {@inheritdoc} + * {@inheritDoc} */ public static function getSubscribedEvents(): array { diff --git a/src/bundle/Security/TwoFactor/Event/AuthenticationTokenListener.php b/src/bundle/Security/TwoFactor/Event/AuthenticationTokenListener.php index 9eb1d82b..b25cfdaf 100644 --- a/src/bundle/Security/TwoFactor/Event/AuthenticationTokenListener.php +++ b/src/bundle/Security/TwoFactor/Event/AuthenticationTokenListener.php @@ -25,7 +25,7 @@ public function __construct( private TwoFactorConditionRegistry $twoFactorConditionRegistry, private TwoFactorProviderInitiator $twoFactorProviderInitiator, private AuthenticationContextFactoryInterface $authenticationContextFactory, - private RequestStack $requestStack + private RequestStack $requestStack, ) { } @@ -70,7 +70,7 @@ private function getRequest(): Request } /** - * {@inheritdoc} + * {@inheritDoc} */ public static function getSubscribedEvents(): array { diff --git a/src/bundle/Security/TwoFactor/Event/TwoFactorFormListener.php b/src/bundle/Security/TwoFactor/Event/TwoFactorFormListener.php index b7a6aed1..c653282c 100644 --- a/src/bundle/Security/TwoFactor/Event/TwoFactorFormListener.php +++ b/src/bundle/Security/TwoFactor/Event/TwoFactorFormListener.php @@ -45,7 +45,7 @@ public function onKernelRequest(RequestEvent $requestEvent): void } /** - * {@inheritdoc} + * {@inheritDoc} */ public static function getSubscribedEvents(): array { diff --git a/src/bundle/Security/TwoFactor/IpWhitelist/DefaultIpWhitelistProvider.php b/src/bundle/Security/TwoFactor/IpWhitelist/DefaultIpWhitelistProvider.php index 0f901886..549f2d8e 100644 --- a/src/bundle/Security/TwoFactor/IpWhitelist/DefaultIpWhitelistProvider.php +++ b/src/bundle/Security/TwoFactor/IpWhitelist/DefaultIpWhitelistProvider.php @@ -11,15 +11,11 @@ */ class DefaultIpWhitelistProvider implements IpWhitelistProviderInterface { - /** @var string[] */ - private array $ipWhitelist; - /** * @param string[] $ipWhitelist */ - public function __construct(array $ipWhitelist) + public function __construct(private array $ipWhitelist) { - $this->ipWhitelist = $ipWhitelist; } /** diff --git a/src/bundle/Security/TwoFactor/Provider/TwoFactorProviderInitiator.php b/src/bundle/Security/TwoFactor/Provider/TwoFactorProviderInitiator.php index aa1555aa..95f089f5 100644 --- a/src/bundle/Security/TwoFactor/Provider/TwoFactorProviderInitiator.php +++ b/src/bundle/Security/TwoFactor/Provider/TwoFactorProviderInitiator.php @@ -17,7 +17,7 @@ class TwoFactorProviderInitiator { public function __construct( private TwoFactorProviderRegistry $providerRegistry, - private TwoFactorTokenFactoryInterface $twoFactorTokenFactory + private TwoFactorTokenFactoryInterface $twoFactorTokenFactory, ) { } @@ -40,7 +40,7 @@ private function getActiveTwoFactorProviders(AuthenticationContextInterface $con return $activeTwoFactorProviders; } - public function beginTwoFactorAuthentication(AuthenticationContextInterface $context): ?TwoFactorTokenInterface + public function beginTwoFactorAuthentication(AuthenticationContextInterface $context): TwoFactorTokenInterface|null { $activeTwoFactorProviders = $this->getActiveTwoFactorProviders($context); diff --git a/src/bundle/Security/TwoFactor/Provider/TwoFactorProviderPreparationListener.php b/src/bundle/Security/TwoFactor/Provider/TwoFactorProviderPreparationListener.php index 4fdadbae..ca401ea6 100644 --- a/src/bundle/Security/TwoFactor/Provider/TwoFactorProviderPreparationListener.php +++ b/src/bundle/Security/TwoFactor/Provider/TwoFactorProviderPreparationListener.php @@ -31,16 +31,16 @@ class TwoFactorProviderPreparationListener implements EventSubscriberInterface // Execute right before ContextListener, which is serializing the security token into the session public const RESPONSE_LISTENER_PRIORITY = 1; - private ?TwoFactorTokenInterface $twoFactorToken = null; + private TwoFactorTokenInterface|null $twoFactorToken = null; private LoggerInterface $logger; public function __construct( private TwoFactorProviderRegistry $providerRegistry, private PreparationRecorderInterface $preparationRecorder, - ?LoggerInterface $logger, + LoggerInterface|null $logger, private string $firewallName, private bool $prepareOnLogin, - private bool $prepareOnAccessDenied + private bool $prepareOnAccessDenied, ) { $this->logger = $logger ?? new NullLogger(); } @@ -125,7 +125,7 @@ private function supports(TokenInterface $token): bool } /** - * {@inheritdoc} + * {@inheritDoc} */ public static function getSubscribedEvents(): array { diff --git a/src/email/Mailer/SymfonyAuthCodeMailer.php b/src/email/Mailer/SymfonyAuthCodeMailer.php index c6d0e6ba..b6d57263 100644 --- a/src/email/Mailer/SymfonyAuthCodeMailer.php +++ b/src/email/Mailer/SymfonyAuthCodeMailer.php @@ -18,8 +18,8 @@ class SymfonyAuthCodeMailer implements AuthCodeMailerInterface public function __construct( private MailerInterface $mailer, - ?string $senderEmail, - ?string $senderName, + string|null $senderEmail, + string|null $senderName, ) { if (null !== $senderEmail && null !== $senderName) { $this->senderAddress = new Address($senderEmail, $senderName); diff --git a/src/email/Model/Email/TwoFactorInterface.php b/src/email/Model/Email/TwoFactorInterface.php index 69dfd2ae..1232f377 100644 --- a/src/email/Model/Email/TwoFactorInterface.php +++ b/src/email/Model/Email/TwoFactorInterface.php @@ -19,7 +19,7 @@ public function getEmailAuthRecipient(): string; /** * Return the authentication code. */ - public function getEmailAuthCode(): ?string; + public function getEmailAuthCode(): string|null; /** * Set the authentication code. diff --git a/src/google-authenticator/Model/Google/TwoFactorInterface.php b/src/google-authenticator/Model/Google/TwoFactorInterface.php index c2e02bda..857ee4fc 100644 --- a/src/google-authenticator/Model/Google/TwoFactorInterface.php +++ b/src/google-authenticator/Model/Google/TwoFactorInterface.php @@ -20,5 +20,5 @@ public function getGoogleAuthenticatorUsername(): string; * Return the Google Authenticator secret * When an empty string is returned, the Google authentication is disabled. */ - public function getGoogleAuthenticatorSecret(): ?string; + public function getGoogleAuthenticatorSecret(): string|null; } diff --git a/src/google-authenticator/Security/TwoFactor/Provider/Google/GoogleTotpFactory.php b/src/google-authenticator/Security/TwoFactor/Provider/Google/GoogleTotpFactory.php index 5ad9f51d..462b13fd 100644 --- a/src/google-authenticator/Security/TwoFactor/Provider/Google/GoogleTotpFactory.php +++ b/src/google-authenticator/Security/TwoFactor/Provider/Google/GoogleTotpFactory.php @@ -16,8 +16,8 @@ class GoogleTotpFactory { public function __construct( - private ?string $server, - private ?string $issuer, + private string|null $server, + private string|null $issuer, private int $digits, ) { } diff --git a/src/totp/Model/Totp/TotpConfiguration.php b/src/totp/Model/Totp/TotpConfiguration.php index 5f8dfff5..f974dbdb 100644 --- a/src/totp/Model/Totp/TotpConfiguration.php +++ b/src/totp/Model/Totp/TotpConfiguration.php @@ -15,8 +15,6 @@ class TotpConfiguration implements TotpConfigurationInterface public const ALGORITHM_SHA256 = 'sha256'; public const ALGORITHM_SHA512 = 'sha512'; - private string $algorithm; - /** * @param string $secret Base32 encoded secret key * @param string $algorithm Hashing algorithm to be used, see class constants for available values @@ -25,15 +23,13 @@ class TotpConfiguration implements TotpConfigurationInterface */ public function __construct( private string $secret, - string $algorithm, + private string $algorithm, private int $period, private int $digits, ) { if (!self::isValidAlgorithm($algorithm)) { throw new InvalidArgumentException(sprintf('The algorithm "%s" is not supported', $algorithm)); } - - $this->algorithm = $algorithm; } private static function isValidAlgorithm(string $algorithm): bool @@ -46,7 +42,7 @@ private static function isValidAlgorithm(string $algorithm): bool self::ALGORITHM_SHA256, self::ALGORITHM_SHA512, ], - true + true, ); } diff --git a/src/totp/Model/Totp/TwoFactorInterface.php b/src/totp/Model/Totp/TwoFactorInterface.php index cbffc98c..dd0db1ed 100644 --- a/src/totp/Model/Totp/TwoFactorInterface.php +++ b/src/totp/Model/Totp/TwoFactorInterface.php @@ -19,5 +19,5 @@ public function getTotpAuthenticationUsername(): string; /** * Return the configuration for TOTP authentication. */ - public function getTotpAuthenticationConfiguration(): ?TotpConfigurationInterface; + public function getTotpAuthenticationConfiguration(): TotpConfigurationInterface|null; } diff --git a/src/totp/Security/TwoFactor/Provider/Totp/TotpFactory.php b/src/totp/Security/TwoFactor/Provider/Totp/TotpFactory.php index c07bef15..334e05ff 100644 --- a/src/totp/Security/TwoFactor/Provider/Totp/TotpFactory.php +++ b/src/totp/Security/TwoFactor/Provider/Totp/TotpFactory.php @@ -19,8 +19,8 @@ class TotpFactory * @param array $customParameters */ public function __construct( - private ?string $server, - private ?string $issuer, + private string|null $server, + private string|null $issuer, private array $customParameters, ) { } @@ -42,7 +42,7 @@ public function createTotpForUser(TwoFactorInterface $user): TOTPInterface $secret, $totpConfiguration->getPeriod(), $totpConfiguration->getAlgorithm(), - $totpConfiguration->getDigits() + $totpConfiguration->getDigits(), ); $userAndHost = $user->getTotpAuthenticationUsername().($this->server ? '@'.$this->server : ''); diff --git a/src/trusted-device/Security/Http/EventListener/TrustedDeviceListener.php b/src/trusted-device/Security/Http/EventListener/TrustedDeviceListener.php index 801f2133..82279925 100644 --- a/src/trusted-device/Security/Http/EventListener/TrustedDeviceListener.php +++ b/src/trusted-device/Security/Http/EventListener/TrustedDeviceListener.php @@ -47,7 +47,7 @@ public function onSuccessfulLogin(LoginSuccessEvent $loginSuccessEvent): void } /** - * {@inheritdoc} + * {@inheritDoc} */ public static function getSubscribedEvents(): array { diff --git a/src/trusted-device/Security/TwoFactor/Trusted/JwtTokenEncoder.php b/src/trusted-device/Security/TwoFactor/Trusted/JwtTokenEncoder.php index 4a34d53a..67cfa301 100644 --- a/src/trusted-device/Security/TwoFactor/Trusted/JwtTokenEncoder.php +++ b/src/trusted-device/Security/TwoFactor/Trusted/JwtTokenEncoder.php @@ -27,7 +27,7 @@ class JwtTokenEncoder private Clock $clock; - public function __construct(private Configuration $configuration, ?Clock $clock = null) + public function __construct(private Configuration $configuration, Clock|null $clock = null) { $this->clock = $clock ?? SystemClock::fromSystemTimezone(); } @@ -44,7 +44,7 @@ public function generateToken(string $username, string $firewallName, int $versi return $builder->getToken($this->configuration->signer(), $this->configuration->signingKey()); } - public function decodeToken(string $encodedToken): ?Plain + public function decodeToken(string $encodedToken): Plain|null { if (0 === strlen($encodedToken)) { return null; diff --git a/src/trusted-device/Security/TwoFactor/Trusted/TrustedCookieResponseListener.php b/src/trusted-device/Security/TwoFactor/Trusted/TrustedCookieResponseListener.php index ebb373ec..e1740a9d 100644 --- a/src/trusted-device/Security/TwoFactor/Trusted/TrustedCookieResponseListener.php +++ b/src/trusted-device/Security/TwoFactor/Trusted/TrustedCookieResponseListener.php @@ -25,10 +25,10 @@ public function __construct( private TrustedDeviceTokenStorage $trustedTokenStorage, private int $trustedTokenLifetime, private string $cookieName, - private ?bool $cookieSecure, - private ?string $cookieSameSite, - private ?string $cookiePath, - private ?string $cookieDomain, + private bool|null $cookieSecure, + private string|null $cookieSameSite, + private string|null $cookiePath, + private string|null $cookieDomain, ) { } @@ -59,7 +59,7 @@ public function onKernelResponse(ResponseEvent $event): void null === $this->cookieSecure ? $event->getRequest()->isSecure() : $this->cookieSecure, true, false, - $this->cookieSameSite + $this->cookieSameSite, ); $response = $event->getResponse(); @@ -86,7 +86,7 @@ protected function getDateTimeNow(): DateTimeImmutable } /** - * {@inheritdoc} + * {@inheritDoc} */ public static function getSubscribedEvents(): array { diff --git a/src/trusted-device/Security/TwoFactor/Trusted/TrustedDeviceTokenEncoder.php b/src/trusted-device/Security/TwoFactor/Trusted/TrustedDeviceTokenEncoder.php index 49b4f504..8a5629d0 100644 --- a/src/trusted-device/Security/TwoFactor/Trusted/TrustedDeviceTokenEncoder.php +++ b/src/trusted-device/Security/TwoFactor/Trusted/TrustedDeviceTokenEncoder.php @@ -28,7 +28,7 @@ public function generateToken(string $username, string $firewall, int $version): return new TrustedDeviceToken($jwtToken); } - public function decodeToken(string $trustedTokenEncoded): ?TrustedDeviceToken + public function decodeToken(string $trustedTokenEncoded): TrustedDeviceToken|null { if (0 === strlen($trustedTokenEncoded)) { return null; diff --git a/src/trusted-device/Security/TwoFactor/Trusted/TrustedDeviceTokenStorage.php b/src/trusted-device/Security/TwoFactor/Trusted/TrustedDeviceTokenStorage.php index 4d9128ef..8e9bf46e 100644 --- a/src/trusted-device/Security/TwoFactor/Trusted/TrustedDeviceTokenStorage.php +++ b/src/trusted-device/Security/TwoFactor/Trusted/TrustedDeviceTokenStorage.php @@ -19,7 +19,7 @@ class TrustedDeviceTokenStorage private const TOKEN_DELIMITER = ';'; /** @var TrustedDeviceToken[] */ - private ?array $trustedTokenList; + private array|null $trustedTokenList; private bool $updateCookie = false; @@ -36,7 +36,7 @@ public function hasUpdatedCookie(): bool return $this->updateCookie; } - public function getCookieValue(): ?string + public function getCookieValue(): string|null { return implode(self::TOKEN_DELIMITER, array_map(static function (TrustedDeviceToken $token): string { return $token->serialize(); @@ -136,7 +136,7 @@ private function readTrustedTokenList(): array return $trustedTokenList; } - private function readCookieValue(): ?string + private function readCookieValue(): string|null { $cookieValue = $this->getRequest()->cookies->get($this->cookieName, null); diff --git a/tests/Controller/FormControllerTest.php b/tests/Controller/FormControllerTest.php index cb628fe0..9c18c1ef 100644 --- a/tests/Controller/FormControllerTest.php +++ b/tests/Controller/FormControllerTest.php @@ -118,7 +118,7 @@ private function initControllerWithTrustedFeature(bool $trustedFeature): void $this->twoFactorFirewallContext, $this->logoutUrlGenerator, $this->trustedDeviceManager, - $trustedFeature + $trustedFeature, ); } @@ -206,7 +206,7 @@ private function assertTemplateVars(callable $callback): void /** * @param array|null $errorData */ - private function assertTemplateVarsHaveAuthenticationError(?string $error, ?array $errorData): void + private function assertTemplateVarsHaveAuthenticationError(string|null $error, array|null $errorData): void { $this->assertTemplateVars(function (array $templateVars) use ($error, $errorData) { $this->assertArrayHasKey('authenticationError', $templateVars); @@ -259,7 +259,7 @@ public function form_hasAuthenticationError_passErrorToRenderer(): void $this->assertTemplateVarsHaveAuthenticationError( TwoFactorProviderNotFoundException::MESSAGE_KEY, - ['{{ provider }}' => 'unknownProvider'] + ['{{ provider }}' => 'unknownProvider'], ); $this->controller->form($this->request); diff --git a/tests/DependencyInjection/Factory/Security/TwoFactorFactoryTest.php b/tests/DependencyInjection/Factory/Security/TwoFactorFactoryTest.php index 9d461d92..a4ff0cad 100644 --- a/tests/DependencyInjection/Factory/Security/TwoFactorFactoryTest.php +++ b/tests/DependencyInjection/Factory/Security/TwoFactorFactoryTest.php @@ -56,7 +56,7 @@ private function getEmptyConfig(): array */ private function getFullConfig(): array { - $yaml = <<container, self::FIREWALL_NAME, array_merge(self::DEFAULT_CONFIG, $customConfig), - self::USER_PROVIDER + self::USER_PROVIDER, ); } diff --git a/tests/DependencyInjection/Factory/Security/TwoFactorServicesFactoryTest.php b/tests/DependencyInjection/Factory/Security/TwoFactorServicesFactoryTest.php index cd97f414..2a1f4862 100644 --- a/tests/DependencyInjection/Factory/Security/TwoFactorServicesFactoryTest.php +++ b/tests/DependencyInjection/Factory/Security/TwoFactorServicesFactoryTest.php @@ -35,7 +35,7 @@ public function createSuccessHandler_defaultHandler_createSuccessHandlerDefiniti $this->container, self::FIREWALL_NAME, self::DEFAULT_CONFIG, - self::TWO_FACTOR_FIREWALL_CONFIG_ID + self::TWO_FACTOR_FIREWALL_CONFIG_ID, ); $this->assertEquals('security.authentication.success_handler.two_factor.firewallName', $returnValue); @@ -53,7 +53,7 @@ public function createSuccessHandler_customSuccessHandler_useCustomSuccessHandle $this->container, self::FIREWALL_NAME, ['success_handler' => 'my_success_handler'], - self::TWO_FACTOR_FIREWALL_CONFIG_ID + self::TWO_FACTOR_FIREWALL_CONFIG_ID, ); $this->assertEquals('my_success_handler', $returnValue); @@ -69,7 +69,7 @@ public function createFailureHandler_defaultHandler_createFailureHandlerDefiniti $this->container, self::FIREWALL_NAME, self::DEFAULT_CONFIG, - self::TWO_FACTOR_FIREWALL_CONFIG_ID + self::TWO_FACTOR_FIREWALL_CONFIG_ID, ); $this->assertEquals('security.authentication.failure_handler.two_factor.firewallName', $returnValue); @@ -87,7 +87,7 @@ public function createFailureHandler_customFailureHandler_useCustomFailureHandle $this->container, self::FIREWALL_NAME, ['failure_handler' => 'my_failure_handler'], - self::TWO_FACTOR_FIREWALL_CONFIG_ID + self::TWO_FACTOR_FIREWALL_CONFIG_ID, ); $this->assertEquals('my_failure_handler', $returnValue); @@ -103,7 +103,7 @@ public function createAuthenticationRequiredHandler_defaultHandler_createAuthent $this->container, self::FIREWALL_NAME, self::DEFAULT_CONFIG, - self::TWO_FACTOR_FIREWALL_CONFIG_ID + self::TWO_FACTOR_FIREWALL_CONFIG_ID, ); $this->assertEquals('security.authentication.authentication_required_handler.two_factor.firewallName', $returnValue); @@ -121,7 +121,7 @@ public function createAuthenticationRequiredHandler_customAuthenticationRequired $this->container, self::FIREWALL_NAME, ['authentication_required_handler' => 'my_authentication_required_handler'], - self::TWO_FACTOR_FIREWALL_CONFIG_ID + self::TWO_FACTOR_FIREWALL_CONFIG_ID, ); $this->assertEquals('my_authentication_required_handler', $returnValue); @@ -163,7 +163,7 @@ public function createTwoFactorFirewallConfig_configGiven_createFirewallConfigDe $returnValue = $this->servicesFactory->createTwoFactorFirewallConfig( $this->container, self::FIREWALL_NAME, - self::DEFAULT_CONFIG + self::DEFAULT_CONFIG, ); $this->assertEquals('security.firewall_config.two_factor.firewallName', $returnValue); @@ -188,7 +188,7 @@ public function createProviderPreparationListener_withSettings_createProviderPre [ 'prepare_on_login' => true, 'prepare_on_access_denied' => false, - ] + ], ); $this->assertTrue($this->container->hasDefinition('security.authentication.provider_preparation_listener.two_factor.firewallName')); @@ -208,7 +208,7 @@ public function create_createForFirewall_createExceptionListener(): void $this->servicesFactory->createKernelExceptionListener( $this->container, self::FIREWALL_NAME, - self::AUTH_REQUIRED_HANDLER_ID + self::AUTH_REQUIRED_HANDLER_ID, ); $this->assertTrue($this->container->hasDefinition('security.authentication.kernel_exception_listener.two_factor.firewallName')); @@ -225,7 +225,7 @@ public function create_createForFirewall_createAccessListener(): void $this->servicesFactory->createAccessListener( $this->container, self::FIREWALL_NAME, - self::TWO_FACTOR_FIREWALL_CONFIG_ID + self::TWO_FACTOR_FIREWALL_CONFIG_ID, ); $this->assertTrue($this->container->hasDefinition('security.authentication.access_listener.two_factor.firewallName')); @@ -241,7 +241,7 @@ public function create_createForFirewall_createFormListener(): void $this->servicesFactory->createFormListener( $this->container, self::FIREWALL_NAME, - self::TWO_FACTOR_FIREWALL_CONFIG_ID + self::TWO_FACTOR_FIREWALL_CONFIG_ID, ); $this->assertTrue($this->container->hasDefinition('security.authentication.form_listener.two_factor.firewallName')); diff --git a/tests/DependencyInjection/SchebTwoFactorExtensionTest.php b/tests/DependencyInjection/SchebTwoFactorExtensionTest.php index 4a336967..d89748e3 100644 --- a/tests/DependencyInjection/SchebTwoFactorExtensionTest.php +++ b/tests/DependencyInjection/SchebTwoFactorExtensionTest.php @@ -137,7 +137,7 @@ public function load_falsyEnvVarBasedConfig_setConfigValues(): void */ public function load_offOrFalseStringEnvVarBasedConfig_setConfigValues(): void { - $yaml = <<|null */ - private function getEmptyConfig(): ?array + private function getEmptyConfig(): array|null { $yaml = ''; $parser = new Parser(); @@ -629,7 +629,7 @@ private function getEmptyConfig(): ?array */ private function getFullConfig(): array { - $yaml = <<accessDecider = new TwoFactorAccessDecider($this->accessMap, $this->accessDecisionManager, $this->httpUtils, $this->logoutUrlGenerator); } - private function stubAccessMapReturnsAttributes(?array $attributes): void + private function stubAccessMapReturnsAttributes(array|null $attributes): void { $this->attributes = $attributes; $this->accessMap diff --git a/tests/Security/Authorization/Voter/TwoFactorInProgressVoterTest.php b/tests/Security/Authorization/Voter/TwoFactorInProgressVoterTest.php index 71743348..44ef717f 100644 --- a/tests/Security/Authorization/Voter/TwoFactorInProgressVoterTest.php +++ b/tests/Security/Authorization/Voter/TwoFactorInProgressVoterTest.php @@ -34,7 +34,7 @@ public function vote_isNotTwoFactorToken_returnAbstain(): void * @test * @dataProvider provideAttributeAndExpectedResult */ - public function vote_isTwoFactorToken_returnAbstain(?string $checkAttribute, int $expectedResult): void + public function vote_isTwoFactorToken_returnAbstain(string|null $checkAttribute, int $expectedResult): void { $token = $this->createMock(TwoFactorTokenInterface::class); $returnValue = $this->voter->vote($token, null, [$checkAttribute]); diff --git a/tests/Security/Http/Authentication/DefaultAuthenticationRequiredHandlerTest.php b/tests/Security/Http/Authentication/DefaultAuthenticationRequiredHandlerTest.php index be79c1d7..1cc89f0c 100644 --- a/tests/Security/Http/Authentication/DefaultAuthenticationRequiredHandlerTest.php +++ b/tests/Security/Http/Authentication/DefaultAuthenticationRequiredHandlerTest.php @@ -45,7 +45,7 @@ protected function setUp(): void $this->handler = new DefaultAuthenticationRequiredHandler( $this->httpUtils, - $this->twoFactorFirewallConfig + $this->twoFactorFirewallConfig, ); } diff --git a/tests/Security/Http/Authenticator/TwoFactorAuthenticatorTest.php b/tests/Security/Http/Authenticator/TwoFactorAuthenticatorTest.php index 69c065e2..69a294a3 100644 --- a/tests/Security/Http/Authenticator/TwoFactorAuthenticatorTest.php +++ b/tests/Security/Http/Authenticator/TwoFactorAuthenticatorTest.php @@ -83,7 +83,7 @@ protected function setUp(): void $this->failureHandler, $this->authenticationRequiredHandler, $this->eventDispatcher, - $this->createMock(LoggerInterface::class) + $this->createMock(LoggerInterface::class), ); } @@ -120,7 +120,7 @@ private function stubRememberMeSetsTrusted(bool $rememberMeSetsTrusted): void ->willReturn($rememberMeSetsTrusted); } - private function createTwoFactorToken(?TokenInterface $authenticatedToken = null, bool $allProvidersAuthenticated = false): MockObject|TwoFactorTokenInterface + private function createTwoFactorToken(TokenInterface|null $authenticatedToken = null, bool $allProvidersAuthenticated = false): MockObject|TwoFactorTokenInterface { $user = $this->createMock(UserInterface::class); // Compatibility for Symfony < 6.0 @@ -200,13 +200,15 @@ private function expectDispatchEvents(array $events): void $this->eventDispatcher ->expects($matcher) ->method('dispatch') - ->with($this->isInstanceOf( - TwoFactorAuthenticationEvent::class), + ->with( + $this->isInstanceOf( + TwoFactorAuthenticationEvent::class, + ), $this->callback(function ($value) use ($matcher, $events) { $this->assertEquals($events[$matcher->numberOfInvocations() - 1], $value); return true; - }) + }), ); } diff --git a/tests/Security/Http/EventListener/AbstractCheckCodeListenerTestSetup.php b/tests/Security/Http/EventListener/AbstractCheckCodeListenerTestSetup.php index 1e28bd52..761d1872 100644 --- a/tests/Security/Http/EventListener/AbstractCheckCodeListenerTestSetup.php +++ b/tests/Security/Http/EventListener/AbstractCheckCodeListenerTestSetup.php @@ -61,7 +61,7 @@ protected function stubAllPreconditionsFulfilled(): void $this->stubPreparationPrepared(true); } - private function createTwoFactorToken(?string $currentProvider): MockObject|TwoFactorTokenInterface + private function createTwoFactorToken(string|null $currentProvider): MockObject|TwoFactorTokenInterface { $token = $this->createMock(TwoFactorTokenInterface::class); $token diff --git a/tests/Security/Http/EventListener/CheckBackupCodeListenerTest.php b/tests/Security/Http/EventListener/CheckBackupCodeListenerTest.php index 0c8f565e..66fda4c4 100644 --- a/tests/Security/Http/EventListener/CheckBackupCodeListenerTest.php +++ b/tests/Security/Http/EventListener/CheckBackupCodeListenerTest.php @@ -18,6 +18,7 @@ class CheckBackupCodeListenerTest extends AbstractCheckCodeListenerTestSetup protected function setUp(): void { parent::setUp(); + $this->backupCodeManager = $this->createMock(BackupCodeManagerInterface::class); $this->listener = new CheckBackupCodeListener($this->preparationRecorder, $this->backupCodeManager); } diff --git a/tests/Security/Http/EventListener/CheckTwoFactorCodeListenerTest.php b/tests/Security/Http/EventListener/CheckTwoFactorCodeListenerTest.php index 04f0ee0e..519f2d55 100644 --- a/tests/Security/Http/EventListener/CheckTwoFactorCodeListenerTest.php +++ b/tests/Security/Http/EventListener/CheckTwoFactorCodeListenerTest.php @@ -23,6 +23,7 @@ class CheckTwoFactorCodeListenerTest extends AbstractCheckCodeListenerTestSetup protected function setUp(): void { parent::setUp(); + $this->providerRegistry = $this->createMock(TwoFactorProviderRegistry::class); $this->listener = new CheckTwoFactorCodeListener($this->preparationRecorder, $this->providerRegistry); } diff --git a/tests/Security/Http/EventListener/SuppressRememberMeListenerTest.php b/tests/Security/Http/EventListener/SuppressRememberMeListenerTest.php index 932dba69..f688431b 100644 --- a/tests/Security/Http/EventListener/SuppressRememberMeListenerTest.php +++ b/tests/Security/Http/EventListener/SuppressRememberMeListenerTest.php @@ -34,7 +34,7 @@ private function createRememberMeBadge(bool $isEnabled): MockObject|RememberMeBa return $badge; } - private function createPassportWithRememberMeBadge(?RememberMeBadge $badge): MockObject|Passport + private function createPassportWithRememberMeBadge(RememberMeBadge|null $badge): MockObject|Passport { $passport = $this->createMock(Passport::class); $passport diff --git a/tests/Security/Http/Firewall/ExceptionListenerTest.php b/tests/Security/Http/Firewall/ExceptionListenerTest.php index 2b145e2c..22f868c2 100644 --- a/tests/Security/Http/Firewall/ExceptionListenerTest.php +++ b/tests/Security/Http/Firewall/ExceptionListenerTest.php @@ -46,7 +46,7 @@ protected function setUp(): void self::FIREWALL_NAME, $this->tokenStorage, $this->authenticationRequiredHandler, - $this->eventDispatcher + $this->eventDispatcher, ); } @@ -92,7 +92,7 @@ private function createExceptionEvent(Throwable $exception): ExceptionEvent $this->createMock(HttpKernelInterface::class), $this->request, HttpKernelInterface::MAIN_REQUEST, - $exception + $exception, ); } diff --git a/tests/Security/Http/Firewall/TwoFactorAccessListenerTest.php b/tests/Security/Http/Firewall/TwoFactorAccessListenerTest.php index 6a54f1a4..4203b4e9 100644 --- a/tests/Security/Http/Firewall/TwoFactorAccessListenerTest.php +++ b/tests/Security/Http/Firewall/TwoFactorAccessListenerTest.php @@ -34,7 +34,7 @@ protected function setUp(): void $this->accessListener = new TwoFactorAccessListener( $this->twoFactorFirewallConfig, $this->tokenStorage, - $this->twoFactorAccessDecider + $this->twoFactorAccessDecider, ); } diff --git a/tests/Security/TwoFactor/AuthenticationContextFactoryTest.php b/tests/Security/TwoFactor/AuthenticationContextFactoryTest.php index e0b742ed..5b3a0dda 100644 --- a/tests/Security/TwoFactor/AuthenticationContextFactoryTest.php +++ b/tests/Security/TwoFactor/AuthenticationContextFactoryTest.php @@ -34,7 +34,7 @@ public function create_onCreate_returnAuthenticationContext(): void { $this->assertInstanceOf( AuthenticationContext::class, - $this->authenticationContextFactory->create($this->request, $this->token, $this->passport, 'firewallName') + $this->authenticationContextFactory->create($this->request, $this->token, $this->passport, 'firewallName'), ); } } diff --git a/tests/Security/TwoFactor/Condition/AbstractAuthenticationContextTestCase.php b/tests/Security/TwoFactor/Condition/AbstractAuthenticationContextTestCase.php index 765831a3..58488ddc 100644 --- a/tests/Security/TwoFactor/Condition/AbstractAuthenticationContextTestCase.php +++ b/tests/Security/TwoFactor/Condition/AbstractAuthenticationContextTestCase.php @@ -17,7 +17,7 @@ abstract class AbstractAuthenticationContextTestCase extends TestCase { protected const FIREWALL_NAME = 'firewallName'; - protected function createAuthenticationContext(?Request $request = null, ?TokenInterface $token = null, ?UserInterface $user = null): MockObject|AuthenticationContextInterface + protected function createAuthenticationContext(Request|null $request = null, TokenInterface|null $token = null, UserInterface|null $user = null): MockObject|AuthenticationContextInterface { $context = $this->createMock(AuthenticationContextInterface::class); $context diff --git a/tests/Security/TwoFactor/Event/AuthenticationTokenListenerTest.php b/tests/Security/TwoFactor/Event/AuthenticationTokenListenerTest.php index d42571c8..d6d46247 100644 --- a/tests/Security/TwoFactor/Event/AuthenticationTokenListenerTest.php +++ b/tests/Security/TwoFactor/Event/AuthenticationTokenListenerTest.php @@ -45,7 +45,7 @@ protected function setUp(): void $this->twoFactorConditionRegistry, $this->twoFactorProviderInitiator, $this->authenticationContextFactory, - $requestStack + $requestStack, ); } diff --git a/tests/Security/TwoFactor/Provider/Email/EmailTwoFactorProviderTest.php b/tests/Security/TwoFactor/Provider/Email/EmailTwoFactorProviderTest.php index d6a464ad..38baa53e 100644 --- a/tests/Security/TwoFactor/Provider/Email/EmailTwoFactorProviderTest.php +++ b/tests/Security/TwoFactor/Provider/Email/EmailTwoFactorProviderTest.php @@ -44,7 +44,7 @@ private function createUser(bool $emailAuthEnabled = true): MockObject|UserWithT return $user; } - private function createAuthenticationContext(?UserInterface $user = null): MockObject|AuthenticationContextInterface + private function createAuthenticationContext(UserInterface|null $user = null): MockObject|AuthenticationContextInterface { $authContext = $this->createMock(AuthenticationContextInterface::class); $authContext diff --git a/tests/Security/TwoFactor/Provider/Email/Generator/CodeGeneratorTest.php b/tests/Security/TwoFactor/Provider/Email/Generator/CodeGeneratorTest.php index 0a6e757b..fd1bb21b 100644 --- a/tests/Security/TwoFactor/Provider/Email/Generator/CodeGeneratorTest.php +++ b/tests/Security/TwoFactor/Provider/Email/Generator/CodeGeneratorTest.php @@ -39,7 +39,7 @@ public function generateAndSend_useOriginalCodeGenerator_codeBetweenRange(): voi ->method('setEmailAuthCode') ->with($this->logicalAnd( $this->greaterThanOrEqual(10000), - $this->lessThanOrEqual(99999) + $this->lessThanOrEqual(99999), )); // Construct test subject with original class diff --git a/tests/Security/TwoFactor/Provider/Google/GoogleAuthenticatorTwoFactorProviderTest.php b/tests/Security/TwoFactor/Provider/Google/GoogleAuthenticatorTwoFactorProviderTest.php index b0d3ac10..cfbd01d8 100644 --- a/tests/Security/TwoFactor/Provider/Google/GoogleAuthenticatorTwoFactorProviderTest.php +++ b/tests/Security/TwoFactor/Provider/Google/GoogleAuthenticatorTwoFactorProviderTest.php @@ -28,7 +28,7 @@ protected function setUp(): void $this->provider = new GoogleAuthenticatorTwoFactorProvider($this->authenticator, $formRenderer); } - private function createUser(bool $enabled = true, ?string $secret = self::SECRET): MockObject|UserWithTwoFactorInterface + private function createUser(bool $enabled = true, string|null $secret = self::SECRET): MockObject|UserWithTwoFactorInterface { $user = $this->createMock(UserWithTwoFactorInterface::class); $user @@ -43,7 +43,7 @@ private function createUser(bool $enabled = true, ?string $secret = self::SECRET return $user; } - private function createAuthenticationContext(?UserInterface $user = null): MockObject|AuthenticationContextInterface + private function createAuthenticationContext(UserInterface|null $user = null): MockObject|AuthenticationContextInterface { $authContext = $this->createMock(AuthenticationContextInterface::class); $authContext diff --git a/tests/Security/TwoFactor/Provider/Google/GoogleTotpFactoryTest.php b/tests/Security/TwoFactor/Provider/Google/GoogleTotpFactoryTest.php index 2e58a39f..35bedf38 100644 --- a/tests/Security/TwoFactor/Provider/Google/GoogleTotpFactoryTest.php +++ b/tests/Security/TwoFactor/Provider/Google/GoogleTotpFactoryTest.php @@ -20,7 +20,7 @@ class GoogleTotpFactoryTest extends TestCase private const CUSTOM_DIGITS = 8; private const DEFAULT_DIGITS = 6; - private function createUserMock(?string $secret = self::SECRET): MockObject|TwoFactorInterface + private function createUserMock(string|null $secret = self::SECRET): MockObject|TwoFactorInterface { $user = $this->createMock(TwoFactorInterface::class); $user @@ -76,7 +76,7 @@ public function createTotpForUser_factoryCalled_returnTotpObject(): void * @test * @dataProvider provideHostnameAndIssuer */ - public function getProvisioningUri_hostnameAndIssuerGiven_returnProvisioningUri(?string $hostname, ?string $issuer, int $digits, string $expectedUrl): void + public function getProvisioningUri_hostnameAndIssuerGiven_returnProvisioningUri(string|null $hostname, string|null $issuer, int $digits, string $expectedUrl): void { $user = $this->createUserMock(); $totp = (new GoogleTotpFactory($hostname, $issuer, $digits))->createTotpForUser($user); diff --git a/tests/Security/TwoFactor/Provider/Totp/TotpAuthenticatorTwoFactorProviderTest.php b/tests/Security/TwoFactor/Provider/Totp/TotpAuthenticatorTwoFactorProviderTest.php index 1fc737ab..7788a850 100644 --- a/tests/Security/TwoFactor/Provider/Totp/TotpAuthenticatorTwoFactorProviderTest.php +++ b/tests/Security/TwoFactor/Provider/Totp/TotpAuthenticatorTwoFactorProviderTest.php @@ -29,7 +29,7 @@ protected function setUp(): void $this->provider = new TotpAuthenticatorTwoFactorProvider($this->authenticator, $formRenderer); } - private function createUser(bool $enabled = true, bool $hasTotpConfiguration = true, ?string $secret = self::SECRET): MockObject|TwoFactorInterface + private function createUser(bool $enabled = true, bool $hasTotpConfiguration = true, string|null $secret = self::SECRET): MockObject|TwoFactorInterface { $user = $this->createMock(UserWithTwoFactorInterface::class); $user @@ -54,7 +54,7 @@ private function createUser(bool $enabled = true, bool $hasTotpConfiguration = t return $user; } - private function createAuthenticationContext(?UserInterface $user = null): MockObject|AuthenticationContextInterface + private function createAuthenticationContext(UserInterface|null $user = null): MockObject|AuthenticationContextInterface { $authContext = $this->createMock(AuthenticationContextInterface::class); $authContext diff --git a/tests/Security/TwoFactor/Provider/Totp/TotpFactoryTest.php b/tests/Security/TwoFactor/Provider/Totp/TotpFactoryTest.php index c419aef8..20151b7f 100644 --- a/tests/Security/TwoFactor/Provider/Totp/TotpFactoryTest.php +++ b/tests/Security/TwoFactor/Provider/Totp/TotpFactoryTest.php @@ -27,7 +27,7 @@ class TotpFactoryTest extends TestCase private const DIGITS = 8; private const ALGORITHM = TotpConfiguration::ALGORITHM_SHA256; - private function createUserMock(bool $hasTotpConfiguration = true, ?string $secret = self::SECRET): MockObject|TwoFactorInterface + private function createUserMock(bool $hasTotpConfiguration = true, string|null $secret = self::SECRET): MockObject|TwoFactorInterface { $user = $this->createMock(TwoFactorInterface::class); $user @@ -91,7 +91,7 @@ public function createTotpForUser_factoryCalled_returnTotpObject(): void * @test * @dataProvider provideHostnameAndIssuer */ - public function getProvisioningUri_hostnameAndIssuerGiven_returnProvisioningUri(?string $hostname, ?string $issuer, array $customParameters, string $expectedUrl): void + public function getProvisioningUri_hostnameAndIssuerGiven_returnProvisioningUri(string|null $hostname, string|null $issuer, array $customParameters, string $expectedUrl): void { $user = $this->createUserMock(); $totp = (new TotpFactory($hostname, $issuer, $customParameters))->createTotpForUser($user); diff --git a/tests/Security/TwoFactor/Provider/TwoFactorProviderPreparationListenerTest.php b/tests/Security/TwoFactor/Provider/TwoFactorProviderPreparationListenerTest.php index e232c1f5..c8a0f43d 100644 --- a/tests/Security/TwoFactor/Provider/TwoFactorProviderPreparationListenerTest.php +++ b/tests/Security/TwoFactor/Provider/TwoFactorProviderPreparationListenerTest.php @@ -31,7 +31,7 @@ class TwoFactorProviderPreparationListenerTest extends TestCase private MockObject|PreparationRecorderInterface $preparationRecorder; private MockObject|TwoFactorToken $token; private MockObject|UserInterface $user; - private ?TwoFactorProviderPreparationListener $listener = null; + private TwoFactorProviderPreparationListener|null $listener = null; protected function setUp(): void { @@ -64,7 +64,7 @@ private function initTwoFactorProviderPreparationListener(bool $prepareOnLogin, $this->createMock(LoggerInterface::class), self::FIREWALL_NAME, $prepareOnLogin, - $prepareOnAccessDenied + $prepareOnAccessDenied, ); } diff --git a/tests/Security/TwoFactor/Trusted/JwtTokenEncoderTest.php b/tests/Security/TwoFactor/Trusted/JwtTokenEncoderTest.php index 3db8c1ef..86a1e2bb 100644 --- a/tests/Security/TwoFactor/Trusted/JwtTokenEncoderTest.php +++ b/tests/Security/TwoFactor/Trusted/JwtTokenEncoderTest.php @@ -96,7 +96,7 @@ public function decodeToken_validAlgAndSignature_returnDecodedToken(): void '%s.%s.%s', base64_encode('{"typ":"JWT","alg":"HS256"}'), 'eyJ0ZXN0IjoidG9rZW5JZCJ9', - 'sQft2vmMyZ1kL1FPLN5vsg0akuyMoDMNjP9adFxnYOs' + 'sQft2vmMyZ1kL1FPLN5vsg0akuyMoDMNjP9adFxnYOs', ); $this->assertInstanceOf(Plain::class, $this->encoder->decodeToken($encodedToken)); @@ -111,7 +111,7 @@ public function decodeToken_ignoredAlgNone_returnNull(): void '%s.%s.%s', base64_encode('{"typ":"JWT","alg":"none"}'), // Modified the algorithm from 'HS256' to 'none' 'eyJ0ZXN0IjoidG9rZW5JZCJ9', - 'sQft2vmMyZ1kL1FPLN5vsg0akuyMoDMNjP9adFxnYOs' + 'sQft2vmMyZ1kL1FPLN5vsg0akuyMoDMNjP9adFxnYOs', ); $this->assertNull($this->encoder->decodeToken($encodedNoneAlgToken)); @@ -126,7 +126,7 @@ public function decodeToken_ignoredAlgTest_returnNull(): void '%s.%s.%s', base64_encode('{"typ":"JWT","alg":"test"}'), // Modified the algorithm from 'HS256' to 'test' 'eyJ0ZXN0IjoidG9rZW5JZCJ9', - 'sQft2vmMyZ1kL1FPLN5vsg0akuyMoDMNjP9adFxnYOs' + 'sQft2vmMyZ1kL1FPLN5vsg0akuyMoDMNjP9adFxnYOs', ); $this->assertNull($this->encoder->decodeToken($encodedTestAlgToken)); @@ -141,7 +141,7 @@ public function decodeToken_validAlgWrongSignature_returnNull(): void '%s.%s.%s', base64_encode('{"typ":"JWT","alg":"HS256"}'), 'eyJ0ZXN0IjoidG9rZW5JZCJ9', - 'invalid' + 'invalid', ); $this->assertNull($this->encoder->decodeToken($encodedInvalidSignatureToken)); diff --git a/tests/Security/TwoFactor/Trusted/TrustedCookieResponseListenerTest.php b/tests/Security/TwoFactor/Trusted/TrustedCookieResponseListenerTest.php index 3a603484..898dd171 100644 --- a/tests/Security/TwoFactor/Trusted/TrustedCookieResponseListenerTest.php +++ b/tests/Security/TwoFactor/Trusted/TrustedCookieResponseListenerTest.php @@ -28,7 +28,7 @@ protected function setUp(): void $this->response = new Response(); } - private function createTrustedCookieResponseListener(?string $domain = null, ?bool $cookieSecure = true): TrustedCookieResponseListener + private function createTrustedCookieResponseListener(string|null $domain = null, bool|null $cookieSecure = true): TrustedCookieResponseListener { $cookieResponseListener = new TestableTrustedCookieResponseListener( $this->trustedTokenStorage, @@ -37,7 +37,7 @@ private function createTrustedCookieResponseListener(?string $domain = null, ?bo $cookieSecure, Cookie::SAMESITE_LAX, '/cookie-path', - $domain + $domain, ); $cookieResponseListener->now = new DateTimeImmutable('2018-01-01 00:00:00'); @@ -58,7 +58,7 @@ private function createEventWithRequest(Request $request): ResponseEvent $this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MAIN_REQUEST, - $this->response + $this->response, ); } @@ -113,7 +113,7 @@ public function onKernelResponse_hasUpdatedCookie_addCookieHeader(): void true, true, false, - Cookie::SAMESITE_LAX + Cookie::SAMESITE_LAX, ); $this->assertEquals($expectedCookie, $cookies[0]); } @@ -144,7 +144,7 @@ public function onKernelResponse_hasDomainConfigured_setCookieDomain(): void true, true, false, - Cookie::SAMESITE_LAX + Cookie::SAMESITE_LAX, ); $this->assertEquals($expectedCookie, $cookies[0]); } diff --git a/tests/Security/TwoFactor/Trusted/TrustedDeviceTokenStorageTest.php b/tests/Security/TwoFactor/Trusted/TrustedDeviceTokenStorageTest.php index f7a038a0..dac3ba2a 100644 --- a/tests/Security/TwoFactor/Trusted/TrustedDeviceTokenStorageTest.php +++ b/tests/Security/TwoFactor/Trusted/TrustedDeviceTokenStorageTest.php @@ -44,7 +44,7 @@ private function stubGenerateNewToken(MockObject $newToken): void ->willReturn($newToken); } - private function stubDecodeToken(?TrustedDeviceToken ...$serializedValues): void + private function stubDecodeToken(TrustedDeviceToken|null ...$serializedValues): void { $this->tokenEncoder ->expects($this->any()) @@ -82,7 +82,7 @@ public function hasTrustedToken_differentRealm_returnFalse(): void { $this->stubCookieHasToken('serializedToken'); $this->stubDecodeToken( - $this->createTokenWithProperties('serializedToken', false, true, false) + $this->createTokenWithProperties('serializedToken', false, true, false), ); $returnValue = $this->tokenStorage->hasTrustedToken('username', 'firewallName', 1); @@ -96,7 +96,7 @@ public function hasTrustedToken_sameRealmDifferentVersion_returnFalse(): void { $this->stubCookieHasToken('serializedToken'); $this->stubDecodeToken( - $this->createTokenWithProperties('serializedToken', true, false, false) + $this->createTokenWithProperties('serializedToken', true, false, false), ); $returnValue = $this->tokenStorage->hasTrustedToken('username', 'firewallName', 1); @@ -110,7 +110,7 @@ public function hasTrustedToken_sameRealmSameVersionIsExpired_returnFalse(): voi { $this->stubCookieHasToken('serializedToken'); $this->stubDecodeToken( - $this->createTokenWithProperties('serializedToken', true, true, true) + $this->createTokenWithProperties('serializedToken', true, true, true), ); $returnValue = $this->tokenStorage->hasTrustedToken('username', 'firewallName', 1); @@ -125,7 +125,7 @@ public function hasTrustedToken_sameRealmSameVersion_returnTrue(): void $this->stubCookieHasToken('serializedToken1;serializedToken2'); $this->stubDecodeToken( $this->createTokenWithProperties('serializedToken1', false, true, false), - $this->createTokenWithProperties('serializedToken2', true, true, false) + $this->createTokenWithProperties('serializedToken2', true, true, false), ); $returnValue = $this->tokenStorage->hasTrustedToken('username', 'firewallName', 1); @@ -153,7 +153,7 @@ public function clearTrustedToken_removeExistingToken_removeTokenAndHasUpdatedCo $this->stubCookieHasToken('serializedToken'); $this->stubDecodeToken( // Realm matches, version doesn't need to match - $this->createTokenWithProperties('serializedToken', true, false, false) + $this->createTokenWithProperties('serializedToken', true, false, false), ); $this->tokenStorage->clearTrustedToken('username', 'firewallName'); @@ -170,7 +170,7 @@ public function clearTrustedToken_removeNonExistingToken_doNothing(): void $this->stubCookieHasToken('serializedToken'); $this->stubDecodeToken( // Realm doesn't match, version doesn't need to match - $this->createTokenWithProperties('serializedToken', false, false, false) + $this->createTokenWithProperties('serializedToken', false, false, false), ); $this->tokenStorage->clearTrustedToken('username', 'firewallName'); @@ -196,7 +196,7 @@ public function hasUpdatedCookie_hasInvalidToken_returnTrue(): void $this->stubCookieHasToken('validToken;invalidToken'); $this->stubDecodeToken( $this->createMock(TrustedDeviceToken::class), - null + null, ); $returnValue = $this->tokenStorage->hasUpdatedCookie(); @@ -211,7 +211,7 @@ public function hasUpdatedCookie_allValidToken_returnFalse(): void $this->stubCookieHasToken('validToken1;validToken2'); $this->stubDecodeToken( $this->createTokenWithProperties('validToken1', true, true, false), - $this->createTokenWithProperties('validToken2', true, true, false) + $this->createTokenWithProperties('validToken2', true, true, false), ); $returnValue = $this->tokenStorage->hasUpdatedCookie(); @@ -235,7 +235,7 @@ public function hasUpdatedCookie_hasTokenCalledWithAllValidToken_returnFalse(): { $this->stubCookieHasToken('validToken'); $this->stubDecodeToken( - $this->createTokenWithProperties('validToken', true, true, false) + $this->createTokenWithProperties('validToken', true, true, false), ); $this->tokenStorage->hasTrustedToken('username', 'firewallName', 1); @@ -250,7 +250,7 @@ public function hasUpdatedCookie_hasTokenCalledWithInvalidToken_returnTrue(): vo { $this->stubCookieHasToken('differentVersionToken'); $this->stubDecodeToken( - $this->createTokenWithProperties('differentVersionToken', true, false, false) + $this->createTokenWithProperties('differentVersionToken', true, false, false), ); $this->tokenStorage->hasTrustedToken('username', 'firewallName', 1); @@ -266,7 +266,7 @@ public function getCookieValue_hasMultipleToken_returnSerializedToken(): void $this->stubCookieHasToken('validToken1;validToken2'); $this->stubDecodeToken( $this->createTokenWithProperties('validToken1', true, true, false), - $this->createTokenWithProperties('validToken2', true, true, false) + $this->createTokenWithProperties('validToken2', true, true, false), ); $returnValue = $this->tokenStorage->getCookieValue(); @@ -281,7 +281,7 @@ public function getCookieValue_hasInvalidToken_returnSerializedWithoutInvalidTok $this->stubCookieHasToken('validToken;invalidToken'); $this->stubDecodeToken( $this->createTokenWithProperties('validToken', true, true, false), - null + null, ); $returnValue = $this->tokenStorage->getCookieValue(); @@ -296,7 +296,7 @@ public function getCookieValue_addToken_returnSerializedWithNewToken(): void $this->stubCookieHasToken('validToken1;validToken2'); $this->stubDecodeToken( $this->createTokenWithProperties('validToken1', false, true, false), - $this->createTokenWithProperties('validToken2', false, true, false) + $this->createTokenWithProperties('validToken2', false, true, false), ); $this->stubGenerateNewToken($this->createTokenWithProperties('newToken', true, true, false)); @@ -313,7 +313,7 @@ public function getCookieValue_refreshExistingToken_returnSerializedWithReplaced $this->stubCookieHasToken('validToken1;validToken2'); $this->stubDecodeToken( $this->createTokenWithProperties('validToken1', true, true, false), - $this->createTokenWithProperties('validToken2', false, true, false) + $this->createTokenWithProperties('validToken2', false, true, false), ); $this->stubGenerateNewToken($this->createTokenWithProperties('newToken', true, true, false)); @@ -329,7 +329,7 @@ public function getCookieValue_hasTokenCalledWithInvalidToken_returnSerializedWi { $this->stubCookieHasToken('differentVersionToken;validToken'); $this->stubDecodeToken( - $this->createTokenWithProperties('validToken', true, true, false) + $this->createTokenWithProperties('validToken', true, true, false), ); $this->tokenStorage->hasTrustedToken('username', 'firewallName', 2); diff --git a/tests/Security/TwoFactor/TwoFactorFirewallConfigTest.php b/tests/Security/TwoFactor/TwoFactorFirewallConfigTest.php index 8d6a7dc8..18872902 100644 --- a/tests/Security/TwoFactor/TwoFactorFirewallConfigTest.php +++ b/tests/Security/TwoFactor/TwoFactorFirewallConfigTest.php @@ -45,7 +45,7 @@ private function createConfig(array $options = self::FULL_OPTIONS): TwoFactorFir $options, self::FIREWALL_NAME, $this->httpUtils, - $this->requestDataReader + $this->requestDataReader, ); } diff --git a/tests/TestCase.php b/tests/TestCase.php index cd7654a4..09408a09 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -5,7 +5,6 @@ namespace Scheb\TwoFactorBundle\Tests; use PHPUnit\Framework\TestCase as PHPUnitTestCase; -use Symfony\Component\HttpKernel\Kernel; // phpcs:ignore Symfony.NamingConventions.ValidClassName abstract class TestCase extends PHPUnitTestCase