From c9bf79259840953eaa90f9806d937f1f4002b967 Mon Sep 17 00:00:00 2001 From: Christian Scheb Date: Fri, 19 Apr 2024 22:27:52 +0200 Subject: [PATCH] Address Plsam errors --- .../Factory/Security/TwoFactorServicesFactory.php | 1 + .../Security/Http/EventListener/AbstractCheckCodeListener.php | 2 +- .../Security/TwoFactor/Provider/TwoFactorProviderInitiator.php | 2 +- src/email/Mailer/SymfonyAuthCodeMailer.php | 2 +- .../Security/TwoFactor/Provider/Google/GoogleAuthenticator.php | 2 +- .../Security/TwoFactor/Provider/Google/GoogleTotpFactory.php | 3 ++- .../Security/TwoFactor/Provider/Totp/TotpAuthenticator.php | 2 +- src/totp/Security/TwoFactor/Provider/Totp/TotpFactory.php | 3 ++- .../Security/TwoFactor/Trusted/TrustedDeviceTokenStorage.php | 2 +- 9 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/bundle/DependencyInjection/Factory/Security/TwoFactorServicesFactory.php b/src/bundle/DependencyInjection/Factory/Security/TwoFactorServicesFactory.php index 4f8939a6..5088b4db 100644 --- a/src/bundle/DependencyInjection/Factory/Security/TwoFactorServicesFactory.php +++ b/src/bundle/DependencyInjection/Factory/Security/TwoFactorServicesFactory.php @@ -71,6 +71,7 @@ public function createAuthenticationRequiredHandler(ContainerBuilder $container, */ public function getCsrfTokenManagerId(array $config): string { + /** @psalm-suppress RiskyTruthyFalsyComparison */ return $config['enable_csrf'] ?? false ? 'scheb_two_factor.csrf_token_manager' : 'scheb_two_factor.null_csrf_token_manager'; diff --git a/src/bundle/Security/Http/EventListener/AbstractCheckCodeListener.php b/src/bundle/Security/Http/EventListener/AbstractCheckCodeListener.php index 7adf931f..26b19f6f 100644 --- a/src/bundle/Security/Http/EventListener/AbstractCheckCodeListener.php +++ b/src/bundle/Security/Http/EventListener/AbstractCheckCodeListener.php @@ -38,7 +38,7 @@ public function checkPassport(CheckPassportEvent $event): void assert($credentialsBadge instanceof TwoFactorCodeCredentials); $token = $credentialsBadge->getTwoFactorToken(); $providerName = $token->getCurrentTwoFactorProvider(); - if (!$providerName) { + if (null === $providerName || !$providerName) { throw new AuthenticationException('There is no active two-factor provider.'); } diff --git a/src/bundle/Security/TwoFactor/Provider/TwoFactorProviderInitiator.php b/src/bundle/Security/TwoFactor/Provider/TwoFactorProviderInitiator.php index aa1555aa..fca75bf4 100644 --- a/src/bundle/Security/TwoFactor/Provider/TwoFactorProviderInitiator.php +++ b/src/bundle/Security/TwoFactor/Provider/TwoFactorProviderInitiator.php @@ -62,7 +62,7 @@ private function setPreferredProvider(TwoFactorTokenInterface $token, object $us } $preferredProvider = $user->getPreferredTwoFactorProvider(); - if (!$preferredProvider) { + if (null === $preferredProvider || !$preferredProvider) { return; } diff --git a/src/email/Mailer/SymfonyAuthCodeMailer.php b/src/email/Mailer/SymfonyAuthCodeMailer.php index c6d0e6ba..9ab7dd1f 100644 --- a/src/email/Mailer/SymfonyAuthCodeMailer.php +++ b/src/email/Mailer/SymfonyAuthCodeMailer.php @@ -23,7 +23,7 @@ public function __construct( ) { if (null !== $senderEmail && null !== $senderName) { $this->senderAddress = new Address($senderEmail, $senderName); - } elseif ($senderEmail) { + } elseif (null !== $senderEmail && $senderEmail) { $this->senderAddress = $senderEmail; } } diff --git a/src/google-authenticator/Security/TwoFactor/Provider/Google/GoogleAuthenticator.php b/src/google-authenticator/Security/TwoFactor/Provider/Google/GoogleAuthenticator.php index 0c8eaa42..983c87de 100644 --- a/src/google-authenticator/Security/TwoFactor/Provider/Google/GoogleAuthenticator.php +++ b/src/google-authenticator/Security/TwoFactor/Provider/Google/GoogleAuthenticator.php @@ -20,7 +20,7 @@ public function __construct( /** @var 0|positive-int */ private int $window, /** @var 0|positive-int|null */ - private null|int $leeway, + private int|null $leeway, ) { } diff --git a/src/google-authenticator/Security/TwoFactor/Provider/Google/GoogleTotpFactory.php b/src/google-authenticator/Security/TwoFactor/Provider/Google/GoogleTotpFactory.php index 5ad9f51d..18299e74 100644 --- a/src/google-authenticator/Security/TwoFactor/Provider/Google/GoogleTotpFactory.php +++ b/src/google-authenticator/Security/TwoFactor/Provider/Google/GoogleTotpFactory.php @@ -32,10 +32,11 @@ public function createTotpForUser(TwoFactorInterface $user): TOTPInterface /** @psalm-suppress ArgumentTypeCoercion */ $totp = TOTP::create($secret, 30, 'sha1', $this->digits); + /** @psalm-suppress RiskyTruthyFalsyComparison */ $userAndHost = $user->getGoogleAuthenticatorUsername().($this->server ? '@'.$this->server : ''); $totp->setLabel($userAndHost); - if ($this->issuer) { + if (null !== $this->issuer && $this->issuer) { $totp->setIssuer($this->issuer); } diff --git a/src/totp/Security/TwoFactor/Provider/Totp/TotpAuthenticator.php b/src/totp/Security/TwoFactor/Provider/Totp/TotpAuthenticator.php index 93f55784..c6d7ae6f 100644 --- a/src/totp/Security/TwoFactor/Provider/Totp/TotpAuthenticator.php +++ b/src/totp/Security/TwoFactor/Provider/Totp/TotpAuthenticator.php @@ -20,7 +20,7 @@ public function __construct( /** @var 0|positive-int */ private int $window, /** @var 0|positive-int|null */ - private null|int $leeway, + private int|null $leeway, ) { } diff --git a/src/totp/Security/TwoFactor/Provider/Totp/TotpFactory.php b/src/totp/Security/TwoFactor/Provider/Totp/TotpFactory.php index c07bef15..b4c9a185 100644 --- a/src/totp/Security/TwoFactor/Provider/Totp/TotpFactory.php +++ b/src/totp/Security/TwoFactor/Provider/Totp/TotpFactory.php @@ -45,10 +45,11 @@ public function createTotpForUser(TwoFactorInterface $user): TOTPInterface $totpConfiguration->getDigits() ); + /** @psalm-suppress RiskyTruthyFalsyComparison */ $userAndHost = $user->getTotpAuthenticationUsername().($this->server ? '@'.$this->server : ''); $totp->setLabel($userAndHost); - if ($this->issuer) { + if (null !== $this->issuer && $this->issuer) { $totp->setIssuer($this->issuer); } diff --git a/src/trusted-device/Security/TwoFactor/Trusted/TrustedDeviceTokenStorage.php b/src/trusted-device/Security/TwoFactor/Trusted/TrustedDeviceTokenStorage.php index 4d9128ef..7473855e 100644 --- a/src/trusted-device/Security/TwoFactor/Trusted/TrustedDeviceTokenStorage.php +++ b/src/trusted-device/Security/TwoFactor/Trusted/TrustedDeviceTokenStorage.php @@ -118,7 +118,7 @@ private function getTrustedTokenList(): array private function readTrustedTokenList(): array { $cookie = $this->readCookieValue(); - if (!$cookie) { + if (null === $cookie || !$cookie) { return []; }