Debian Codegraph @

lib/3rdParty/composer/facile-it/php-openid-client/src/functions/parse_metadata_response.php

raw symbols SCIP
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Facile\OpenIDClient;
6
7 use Facile\OpenIDClient\Exception\InvalidArgumentException;
8 use JsonException;
9 use Psr\Http\Message\ResponseInterface;
10
11 use function is_array;
12 use function json_decode;
13
14 /**
15 * @internal
16 *
17 * @return array<string, mixed>
18 *
19 * @psalm-return array<string, mixed>
20 */
21 function parse_metadata_response(ResponseInterface $response, ?int $expectedCode = null): array
22 {
23 check_server_response($response, $expectedCode);
24
25 try {
26 /** @var null|(array{}&array{error?: string, error_description?: string, error_uri?: string, response?: string}) $data */
27 $data = json_decode((string) $response->getBody(), true, 512, JSON_THROW_ON_ERROR);
28 } catch (JsonException $e) {
29 throw new InvalidArgumentException('Invalid metadata content', 0, $e);
30 }
31
32 if (! is_array($data)) {
33 throw new InvalidArgumentException('Invalid metadata content');
34 }
35
36 return $data;
37 }