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

parse_metadata_response()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 2
dl 0
loc 12
ccs 5
cts 5
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Facile\OpenIDClient;
6
7
use Facile\OpenIDClient\Exception\InvalidArgumentException;
8
use function is_array;
9
use function json_decode;
10
use Psr\Http\Message\ResponseInterface;
11
12
/**
13
 * @param ResponseInterface $response
14
 * @param int|null $expectedCode
15
 *
16
 * @return array<string, mixed>
17
 *
18
 * @template P as array{error?: string, error_description?: string, error_uri?: string, response?: string}&array<string, mixed>
19
 * @psalm-return array<string, mixed>
20
 */
21
function parse_metadata_response(ResponseInterface $response, ?int $expectedCode = null): array
22
{
23 10
    check_server_response($response, $expectedCode);
24
25
    /** @var bool|P $data */
26 8
    $data = json_decode((string) $response->getBody(), true);
27
28 8
    if (! is_array($data)) {
0 ignored issues
show
introduced by
The condition is_array($data) is always false.
Loading history...
29 1
        throw new InvalidArgumentException('Invalid metadata content');
30
    }
31
32 7
    return $data;
33
}
34