AggregateParser   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 93.33%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
dl 0
loc 29
ccs 14
cts 15
cp 0.9333
rs 10
c 1
b 0
f 0
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A unpack() 0 27 5
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
Consider adding a comment why this CATCH block is empty.
Loading history...
37
            }
38
        }
39
40 2
        return $this->cleanClaims($this->assignClaims($claims, $claimNames, $claimPayloads));
41
    }
42
}
43