Skip to content

Commit

Permalink
Fixing type warnings form phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
JimTools committed Dec 17, 2023
1 parent 2c25fc2 commit 3e9924b
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/JwtAuthentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ final class JwtAuthentication implements MiddlewareInterface
* secret?: string|array<string>|array<string,string>,
* secure: bool,
* relaxed: array<string>,
* algorithm: array<string>,
* algorithm: array<string>|array<string,string>,
* header: string,
* regexp: string,
* cookie: string,
Expand Down Expand Up @@ -322,7 +322,6 @@ private function decodeToken(string $token): array
$decoded = JWT::decode(
$token,
$keys,
$this->options['algorithm']
);
return (array) $decoded;
} catch (Exception $exception) {
Expand All @@ -342,7 +341,7 @@ private function hydrate(array $data = []): void
if ((is_array($data['secret']) || $data['secret'] instanceof ArrayAccess)
&& is_array($data['algorithm'])
&& count($data['algorithm']) === 1
&& count($data['secret']) > count($data['algorithm'])
&& count((array) $data['secret']) > count($data['algorithm'])
) {
$secretIndex = array_keys((array) $data['secret']);
$data['algorithm'] = array_fill_keys($secretIndex, $data['algorithm'][0]);
Expand Down Expand Up @@ -528,17 +527,23 @@ private function rules(array $rules): void
}

/**
* @return array<int|string,Key>
* @return array<string,Key>
*/
private function createKeysFromAlgorithms(): array
{
if (!isset($this->options["secret"])) {
throw new InvalidArgumentException(
'Secret must be either a string or an array of "kid" => "secret" pairs'
);
}

$keyObjects = [];
foreach ($this->options["algorithm"] as $kid => $algorithm) {
$keyId = !is_numeric($kid) ? $kid : $algorithm;

$secret = $this->options["secret"];

if (is_array($this->options["secret"]) || $secret instanceof ArrayAccess) {
if (is_array($secret) || $secret instanceof ArrayAccess) {
$secret = $this->options["secret"][$kid];
}

Expand Down

0 comments on commit 3e9924b

Please sign in to comment.