Skip to content

Commit

Permalink
Apply phpcs fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
scheb committed Nov 4, 2023
1 parent 3fe29b0 commit 51f8ec3
Show file tree
Hide file tree
Showing 72 changed files with 171 additions and 183 deletions.
12 changes: 6 additions & 6 deletions app/src/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

<!-- We don't want this -->
<exclude name="Generic.Formatting.MultipleStatementAlignment"/>
<exclude name="SlevomatCodingStandard.Commenting.RequireOneLineDocComment.MultiLineDocComment"/>
</rule>

<!-- Align with php-cs-fixer config -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected function isValidCode(string $providerName, object $user, string $code)
}

/**
* {@inheritdoc}
* {@inheritDoc}
*/
public static function getSubscribedEvents(): array
{
Expand Down
4 changes: 2 additions & 2 deletions src/bundle/Controller/FormController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
}
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function addConfiguration(NodeDefinition $builder): void
}

/**
* {@inheritdoc}
* {@inheritDoc}
*/
public function createAuthenticator(ContainerBuilder $container, string $firewallName, array $config, string $userProviderId): string
{
Expand All @@ -115,7 +115,7 @@ public function createAuthenticator(ContainerBuilder $container, string $firewal
$twoFactorFirewallConfigId,
$successHandlerId,
$failureHandlerId,
$authRequiredHandlerId
$authRequiredHandlerId,
);
}

Expand All @@ -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
Expand All @@ -149,7 +149,7 @@ private function createAuthenticationTokenCreatedListener(ContainerBuilder $cont
}

/**
* {@inheritdoc}
* {@inheritDoc}
*/
public function createListeners(ContainerBuilder $container, string $firewallName, array $config): array
{
Expand Down
2 changes: 1 addition & 1 deletion src/bundle/DependencyInjection/SchebTwoFactorExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
class SchebTwoFactorExtension extends Extension
{
/**
* {@inheritdoc}
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container): void
{
Expand Down
4 changes: 2 additions & 2 deletions src/bundle/Model/Persister/DoctrinePersisterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ';
Expand Down
2 changes: 1 addition & 1 deletion src/bundle/Model/PreferredProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -33,20 +33,20 @@ 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);
}

/**
* 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')) {
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -53,6 +53,7 @@ public function __serialize(): array
public function __unserialize(array $data): void
{
[$this->provider, $parentData] = $data;

parent::__unserialize($parentData);
}
}
25 changes: 8 additions & 17 deletions src/bundle/Security/Authentication/Token/TwoFactorToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,34 +21,26 @@
use function sprintf;
use function unserialize;

class TwoFactorToken implements TwoFactorTokenInterface, Stringable
class TwoFactorToken implements TwoFactorTokenInterface
{
private TokenInterface $authenticatedToken;

/** @var array<string,mixed> */
private array $attributes = [];

/** @var string[] */
private array $twoFactorProviders;

/** @var bool[] */
private array $preparedProviders = [];

/**
* @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
Expand Down Expand Up @@ -98,7 +89,7 @@ public function getRoles(): array
}

/**
* {@inheritdoc}
* {@inheritDoc}
*/
public function getRoleNames(): array
{
Expand All @@ -117,7 +108,7 @@ public function createWithCredentials(string $credentials): TwoFactorTokenInterf
return $credentialsToken;
}

public function getCredentials(): ?string
public function getCredentials(): string|null
{
return $this->credentials;
}
Expand All @@ -133,7 +124,7 @@ public function getAuthenticatedToken(): TokenInterface
}

/**
* {@inheritdoc}
* {@inheritDoc}
*/
public function getTwoFactorProviders(): array
{
Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/bundle/Security/Authorization/TwoFactorAccessDecider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class TwoFactorCodeCredentials implements CredentialsInterface

public function __construct(
private TwoFactorTokenInterface $twoFactorToken,
private ?string $code,
private string|null $code,
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class CheckTwoFactorCodeListener extends AbstractCheckCodeListener

public function __construct(
PreparationRecorderInterface $preparationRecorder,
private TwoFactorProviderRegistry $providerRegistry
private TwoFactorProviderRegistry $providerRegistry,
) {
parent::__construct($preparationRecorder);
}
Expand All @@ -44,7 +44,7 @@ protected function isValidCode(string $providerName, object $user, string $code)
}

/**
* {@inheritdoc}
* {@inheritDoc}
*/
public static function getSubscribedEvents(): array
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function onSuccessfulLogin(LoginSuccessEvent $event): void
}

/**
* {@inheritdoc}
* {@inheritDoc}
*/
public static function getSubscribedEvents(): array
{
Expand Down
Loading

0 comments on commit 51f8ec3

Please sign in to comment.