thomasvargiu /
php-openid-client
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace TMV\OpenIdClient\Claims; |
||
| 6 | |||
| 7 | use function array_filter; |
||
| 8 | use function is_array; |
||
| 9 | use Throwable; |
||
| 10 | use TMV\OpenIdClient\Client\ClientInterface; |
||
| 11 | |||
| 12 | final class AggregateParser extends AbstractClaims implements AggregatedParserInterface |
||
| 13 | { |
||
| 14 | 4 | public function unpack(ClientInterface $client, array $claims): array |
|
| 15 | { |
||
| 16 | 4 | $claimSources = $claims['_claim_sources'] ?? null; |
|
| 17 | 4 | $claimNames = $claims['_claim_names'] ?? null; |
|
| 18 | |||
| 19 | 4 | if (! is_array($claimSources)) { |
|
| 20 | 1 | return $claims; |
|
| 21 | } |
||
| 22 | |||
| 23 | 3 | if (! is_array($claimNames)) { |
|
| 24 | 1 | return $claims; |
|
| 25 | } |
||
| 26 | |||
| 27 | $aggregatedSources = array_filter($claimSources, static function ($value) { |
||
| 28 | 2 | return null !== ($value['JWT'] ?? null); |
|
| 29 | 2 | }); |
|
| 30 | |||
| 31 | 2 | $claimPayloads = []; |
|
| 32 | 2 | foreach ($aggregatedSources as $sourceName => $source) { |
|
| 33 | try { |
||
| 34 | 2 | $claimPayloads[$sourceName] = $this->claimJWT($client, (string) $source['JWT']); |
|
| 35 | 2 | unset($claims['_claim_sources'][$sourceName]); |
|
| 36 | } catch (Throwable $e) { |
||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
Loading history...
|
|||
| 37 | } |
||
| 38 | } |
||
| 39 | |||
| 40 | 2 | return $this->cleanClaims($this->assignClaims($claims, $claimNames, $claimPayloads)); |
|
| 41 | } |
||
| 42 | } |
||
| 43 |