JwtParser   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 5
c 1
b 0
f 0
dl 0
loc 26
ccs 6
cts 6
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 2
A parse() 0 5 2
1
<?php
2
3
namespace Parroauth2\Client\Extension\JwtAccessToken;
4
5
use Jose\Component\Core\JWKSet;
6
use Parroauth2\Client\Client;
7
use Parroauth2\Client\ClientInterface;
8
use Parroauth2\Client\Jwt\JwtDecoder;
9
10
/**
11
 * Simple parser using JwtDecoder
12
 * The key use for decode the JWT are stored into the 'access_token_jwk' option, or on the jwks
13
 *
14
 * @see JwtDecoder
15
 */
16
final class JwtParser implements JwtParserInterface
17
{
18
    /**
19
     * @var JwtDecoder
20
     */
21
    private $decoder;
22
23
24
    /**
25
     * JwtParser constructor.
26
     *
27
     * @param JwtDecoder|null $decoder
28
     */
29 23
    public function __construct(JwtDecoder $decoder = null)
30
    {
31 23
        $this->decoder = $decoder ?: new JwtDecoder();
32 23
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37 12
    public function parse(string $jwt, ClientInterface $client): array
38
    {
39 12
        $keys = ($jwk = $client->option('access_token_jwk')) ? new JWKSet([$jwk]) : $client->keySet();
40
41 12
        return $this->decoder->decode($jwt, $keys)->payload();
42
    }
43
}
44