Skip to content

Commit

Permalink
Make PHPStan happy.
Browse files Browse the repository at this point in the history
  • Loading branch information
jasny committed Feb 8, 2021
1 parent 37b03e7 commit 6b0f951
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
5 changes: 4 additions & 1 deletion src/Confirmation/HashidsConfirmation.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ public function __construct(string $secret, ?callable $createHashids = null)
? \Closure::fromCallable($createHashids)
: fn(string $salt) => new Hashids($salt);

$this->encodeUid = fn(string $uid) => unpack('H*', $uid)[1];
$this->encodeUid = function (string $uid) {
$unpacked = unpack('H*', $uid);
return $unpacked !== false ? $unpacked[1] : '';
};
$this->decodeUid = fn(string $hex) => pack('H*', $hex);

$this->logger = new NullLogger();
Expand Down
8 changes: 5 additions & 3 deletions src/Confirmation/TokenConfirmation.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class TokenConfirmation implements ConfirmationInterface

protected int $numberOfBytes;

/** @phpstan-param \Closure&callable(string):string */
protected \Closure $encode;

protected TokenStorageInterface $storage;
Expand All @@ -31,7 +30,7 @@ class TokenConfirmation implements ConfirmationInterface

/**
* Class constructor.
*
*
* @param int $numberOfBytes Number of bytes of the random string.
* @param callable|null $encode Method to encode random string.
*/
Expand All @@ -44,7 +43,10 @@ public function __construct(int $numberOfBytes = 16, ?callable $encode = null)
}

/**
* @inheritDoc
* Get copy with storage service.
*
* @param Storage $storage
* @return static
*/
public function withStorage(Storage $storage): self
{
Expand Down
8 changes: 6 additions & 2 deletions src/Session/Jwt.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@

namespace Jasny\Auth\Session;

use DateTimeImmutable;
use Jasny\Auth\Session\Jwt\Cookie;
use Jasny\Auth\Session\Jwt\CookieInterface;
use Jasny\Immutable;
use Lcobucci\JWT\Configuration;
use Lcobucci\JWT\Token;
use Lcobucci\JWT\UnencryptedToken;

/**
* Use JSON Web Token and JSON Web Signature (RFC 7519) to store auth session info.
Expand Down Expand Up @@ -55,14 +58,14 @@ public function getInfo(): array
{
$jwt = $this->cookie->get();

/** @var (Token&UnencryptedToken)|null $token */
$token = $jwt !== null && $jwt !== ''
? $this->jwtConfig->parser()->parse($jwt)
: null;

$constraints = $this->jwtConfig->validationConstraints();

if (
$token === null ||
if ($token === null ||
($constraints !== [] && !$this->jwtConfig->validator()->validate($token, ...$constraints))
) {
return ['user' => null, 'context' => null, 'checksum' => null, 'timestamp' => null];
Expand Down Expand Up @@ -91,6 +94,7 @@ public function persist($userId, $contextId, ?string $checksum, ?\DateTimeInterf
if ($timestamp instanceof \DateTime) {
$timestamp = \DateTimeImmutable::createFromMutable($timestamp);
}
/** @var DateTimeImmutable|null $timestamp */
$time = $timestamp ?? new \DateTimeImmutable();
$expire = $time->add(new \DateInterval("PT{$this->ttl}S"));

Expand Down
4 changes: 2 additions & 2 deletions src/User/BasicUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public function requiresMfa(): bool
/**
* Factory method; create object from data loaded from DB.
*
* @param array $data
* @return static
* @phpstan-param array<string,mixed> $data
* @phpstan-return self
*/
public static function fromData(array $data): self
{
Expand Down

0 comments on commit 6b0f951

Please sign in to comment.