Passed
Push — master ( f80f70...56399a )
by Thomas Mauro
03:05 queued 10s
created

AggregateParser   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 88.24%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
dl 0
loc 31
ccs 15
cts 17
cp 0.8824
rs 10
c 1
b 0
f 0
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A unpack() 0 29 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Facile\OpenIDClient\Claims;
6
7
use function array_filter;
8
use Facile\OpenIDClient\Client\ClientInterface;
9
use function is_array;
10
use Throwable;
11
12
/**
13
 * @psalm-import-type TokenSetClaimsType from \Facile\OpenIDClient\Token\TokenSetInterface
14
 */
15
final class AggregateParser extends AbstractClaims implements AggregatedParserInterface
16
{
17 4
    public function unpack(ClientInterface $client, array $claims): array
18
    {
19 4
        $claimSources = $claims['_claim_sources'] ?? null;
20 4
        $claimNames = $claims['_claim_names'] ?? null;
21
22 4
        if (! is_array($claimSources)) {
23 1
            return $claims;
24
        }
25
26 3
        if (! is_array($claimNames)) {
27 1
            return $claims;
28
        }
29
30
        /** @var array<string, array{JWT: string}> $aggregatedSources */
31 2
        $aggregatedSources = array_filter($claimSources, static function ($value): bool {
32 2
            return is_string($value['JWT'] ?? null);
33 2
        });
34
35 2
        $claimPayloads = [];
36 2
        foreach ($aggregatedSources as $sourceName => $source) {
37
            try {
38 2
                $claimPayloads[$sourceName] = $this->claimJWT($client, $source['JWT']);
39 2
                unset($claims['_claim_sources'][$sourceName]);
40
            } catch (Throwable $e) {
41
                throw $e;
42
            }
43
        }
44
45 2
        return $this->cleanClaims($this->assignClaims($claims, $claimNames, $claimPayloads));
46
    }
47
}
48