Skip to content

Commit

Permalink
Address Plsam errors
Browse files Browse the repository at this point in the history
  • Loading branch information
scheb committed Apr 19, 2024
1 parent 00567fa commit c9bf792
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 8 deletions.
Expand Up @@ -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';
Expand Down
Expand Up @@ -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.');
}

Expand Down
Expand Up @@ -62,7 +62,7 @@ private function setPreferredProvider(TwoFactorTokenInterface $token, object $us
}

$preferredProvider = $user->getPreferredTwoFactorProvider();
if (!$preferredProvider) {
if (null === $preferredProvider || !$preferredProvider) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/email/Mailer/SymfonyAuthCodeMailer.php
Expand Up @@ -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;
}
}
Expand Down
Expand Up @@ -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,
) {
}

Expand Down
Expand Up @@ -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);
}

Expand Down
Expand Up @@ -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,
) {
}

Expand Down
3 changes: 2 additions & 1 deletion src/totp/Security/TwoFactor/Provider/Totp/TotpFactory.php
Expand Up @@ -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);
}

Expand Down
Expand Up @@ -118,7 +118,7 @@ private function getTrustedTokenList(): array
private function readTrustedTokenList(): array
{
$cookie = $this->readCookieValue();
if (!$cookie) {
if (null === $cookie || !$cookie) {
return [];
}

Expand Down

0 comments on commit c9bf792

Please sign in to comment.