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.
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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.