Completed
Push — master ( 79d24d...ad8160 )
by Thomas Mauro
03:36
created

TokenSet::getAttributes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Facile\OpenIDClient\Token;
6
7
use function array_key_exists;
8
use JsonSerializable;
9
10
final class TokenSet implements TokenSetInterface, JsonSerializable
11
{
12
    /** @var array<string, mixed> */
13
    private $attributes = [];
14
15
    /** @var array<string, mixed> */
16
    private $claims;
17
18
    /**
19
     * @param array<string, mixed> $data
20
     *
21
     * @return TokenSetInterface
22
     */
23 8
    public static function fromParams(array $data): TokenSetInterface
24
    {
25 8
        $token = new static();
26
27 8
        if (array_key_exists('claims', $data)) {
28
            $token->claims = $data['claims'];
29
            unset($data['claims']);
30
        }
31
32 8
        $token->attributes = $data;
33
34 8
        return $token;
35
    }
36
37
    /**
38
     * Get all attributes
39
     *
40
     * @return array<string, mixed>
0 ignored issues
show
Documentation introduced by
The doc-type array<string, could not be parsed: Expected ">" at position 5, but found "end of type". (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
41
     */
42
    public function getAttributes(): array
43
    {
44
        return $this->attributes;
45
    }
46
47
    /**
48
     * @return string|null
49
     */
50 1
    public function getCode(): ?string
51
    {
52 1
        return $this->attributes['code'] ?? null;
53
    }
54
55
    /**
56
     * @return string|null
57
     */
58 1
    public function getState(): ?string
59
    {
60 1
        return $this->attributes['state'] ?? null;
61
    }
62
63
    /**
64
     * @return string|null
65
     */
66 1
    public function getTokenType(): ?string
67
    {
68 1
        return $this->attributes['token_type'] ?? null;
69
    }
70
71
    /**
72
     * @return string|null
73
     */
74 1
    public function getAccessToken(): ?string
75
    {
76 1
        return $this->attributes['access_token'] ?? null;
77
    }
78
79
    /**
80
     * @return string|null
81
     */
82 1
    public function getIdToken(): ?string
83
    {
84 1
        return $this->attributes['id_token'] ?? null;
85
    }
86
87
    /**
88
     * @return string|null
89
     */
90 1
    public function getRefreshToken(): ?string
91
    {
92 1
        return $this->attributes['refresh_token'] ?? null;
93
    }
94
95
    /**
96
     * @return int|null
97
     */
98 1
    public function getExpiresIn(): ?int
99
    {
100 1
        return array_key_exists('expires_in', $this->attributes) ? (int) $this->attributes['expires_in'] : null;
101
    }
102
103
    /**
104
     * @return string|null
105
     */
106 1
    public function getCodeVerifier(): ?string
107
    {
108 1
        return $this->attributes['code_verifier'] ?? null;
109
    }
110
111
    public function withIdToken(string $idToken): TokenSetInterface
112
    {
113
        $clone = clone $this;
114
        $clone->attributes['id_token'] = $idToken;
115
116
        return $clone;
117
    }
118
119
    public function withClaims(array $claims): TokenSetInterface
120
    {
121
        $clone = clone $this;
122
        $clone->claims = $claims;
123
124
        return $clone;
125
    }
126
127
    /**
128
     * @return array<string, mixed>
0 ignored issues
show
Documentation introduced by
The doc-type array<string, could not be parsed: Expected ">" at position 5, but found "end of type". (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
129
     * @phpstan-return array{code?: string, state?: string, token_type?: string, access_token?: string, id_token?: string, refresh_token?: string, expires_in?: int, code_verifier?: string}
130
     */
131
    public function jsonSerialize(): array
132
    {
133
        return $this->attributes;
134
    }
135
136
    /**
137
     * @return array<string, mixed>
0 ignored issues
show
Documentation introduced by
The doc-type array<string, could not be parsed: Expected ">" at position 5, but found "end of type". (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
138
     */
139
    public function claims(): array
140
    {
141
        return $this->claims;
142
    }
143
}
144