Debian Codegraph @

lib/3rdParty/composer/facile-it/php-openid-client/src/Token/TokenSet.php

raw symbols SCIP
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Facile\OpenIDClient\Token;
6
7 use JsonSerializable;
8 use Override;
9
10 use function array_key_exists;
11
12 /**
13 * @psalm-import-type TokenSetType from TokenSetInterface
14 * @psalm-import-type TokenSetAttributesType from TokenSetInterface
15 * @psalm-import-type TokenSetClaimsType from TokenSetInterface
16 * @psalm-import-type TokenSetMixedType from TokenSetInterface
17 */
18 final class TokenSet implements TokenSetInterface, JsonSerializable
19 {
20 /**
21 * @var array<string, mixed>
22 *
23 * @psalm-var TokenSetAttributesType
24 */
25 private array $attributes;
26
27 /**
28 * @var array<string, mixed>
29 *
30 * @psalm-var TokenSetClaimsType
31 */
32 private array $claims;
33
34 /**
35 * @psalm-param TokenSetAttributesType $attributes
36 * @psalm-param TokenSetClaimsType $claims
37 */
38 private function __construct(array $attributes, array $claims)
39 {
40 $this->attributes = $attributes;
41 $this->claims = $claims;
42 }
43
44 /**
45 * @param array<string, mixed> $data
46 *
47 * @psalm-param TokenSetMixedType $data
48 */
49 public static function fromParams(array $data): TokenSetInterface
50 {
51 $claims = [];
52 if (array_key_exists('claims', $data)) {
53 $claims = $data['claims'];
54 unset($data['claims']);
55 }
56
57 /** @psalm-var TokenSetAttributesType $data */
58
59 return new static($data, $claims);
60 }
61
62 #[Override]
63 public function getAttributes(): array
64 {
65 return $this->attributes;
66 }
67
68 #[Override]
69 public function getCode(): ?string
70 {
71 return $this->attributes['code'] ?? null;
72 }
73
74 #[Override]
75 public function getState(): ?string
76 {
77 return $this->attributes['state'] ?? null;
78 }
79
80 #[Override]
81 public function getTokenType(): ?string
82 {
83 return $this->attributes['token_type'] ?? null;
84 }
85
86 #[Override]
87 public function getAccessToken(): ?string
88 {
89 return $this->attributes['access_token'] ?? null;
90 }
91
92 #[Override]
93 public function getIdToken(): ?string
94 {
95 return $this->attributes['id_token'] ?? null;
96 }
97
98 #[Override]
99 public function getRefreshToken(): ?string
100 {
101 return $this->attributes['refresh_token'] ?? null;
102 }
103
104 #[Override]
105 public function getExpiresIn(): ?int
106 {
107 /** @var int|string|null $expiresIn */
108 $expiresIn = $this->attributes['expires_in'] ?? null;
109
110 return null !== $expiresIn ? (int) $expiresIn : null;
111 }
112
113 #[Override]
114 public function getCodeVerifier(): ?string
115 {
116 return $this->attributes['code_verifier'] ?? null;
117 }
118
119 #[Override]
120 public function withIdToken(string $idToken): TokenSetInterface
121 {
122 $clone = clone $this;
123 $clone->attributes['id_token'] = $idToken;
124
125 return $clone;
126 }
127
128 #[Override]
129 public function withClaims(array $claims): TokenSetInterface
130 {
131 $clone = clone $this;
132 $clone->claims = $claims;
133
134 return $clone;
135 }
136
137 /**
138 * @return array<string, mixed>
139 *
140 * @psalm-return TokenSetType
141 */
142 #[Override]
143 public function jsonSerialize(): array
144 {
145 return $this->attributes;
146 }
147
148 #[Override]
149 public function claims(): array
150 {
151 return $this->claims;
152 }
153 }