TokenEndPoint   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 9
c 1
b 0
f 0
dl 0
loc 43
ccs 9
cts 9
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A parseResponse() 0 7 2
1
<?php
2
3
namespace Parroauth2\Client\OpenID\EndPoint\Token;
4
5
use Parroauth2\Client\Client;
6
use Parroauth2\Client\ClientInterface;
7
use Parroauth2\Client\EndPoint\Token\TokenEndPoint as BaseTokenEndPoint;
8
use Parroauth2\Client\OpenID\IdToken\IdTokenParserInterface;
9
10
/**
11
 * Token endpoint for OpenID Connect provider
12
 *
13
 * @see https://openid.net/specs/openid-connect-core-1_0.html#TokenEndpoint
14
 */
15
class TokenEndPoint extends BaseTokenEndPoint
16
{
17
    /**
18
     * @var ClientInterface
19
     * @readonly
20
     */
21
    private $client;
22
23
    /**
24
     * @var IdTokenParserInterface
25
     * @readonly
26
     */
27
    private $idTokenParser;
28
29
30
    /**
31
     * TokenEndPoint constructor.
32
     *
33
     * @param ClientInterface $client
34
     * @param IdTokenParserInterface $idTokenParser
35
     */
36 117
    public function __construct(ClientInterface $client, IdTokenParserInterface $idTokenParser)
37
    {
38 117
        parent::__construct($client, [$this, 'parseResponse']);
39
40 117
        $this->client = $client;
41 117
        $this->idTokenParser = $idTokenParser;
42 117
    }
43
44
    /**
45
     * Parse the response and set the ID Token
46
     *
47
     * @param array<string, mixed> $response
48
     *
49
     * @return TokenResponse
50
     */
51 23
    public function parseResponse(array $response): TokenResponse
52
    {
53 23
        if (!isset($response['id_token'])) {
54 8
            return new TokenResponse($response, null);
55
        }
56
57 15
        return new TokenResponse($response, $this->idTokenParser->parse($this->client, $response['id_token']));
58
    }
59
}
60