Passed
Push — master ( 898cc7...450add )
by Thomas Mauro
03:07
created

parse_callback_params()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 25
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
cc 5
eloc 12
nc 5
nop 1
dl 0
loc 25
ccs 0
cts 12
cp 0
crap 30
rs 9.5555
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TMV\OpenIdClient;
6
7
use Psr\Http\Message\ServerRequestInterface;
8
use TMV\OpenIdClient\Exception\RuntimeException;
9
10
/**
11
 * @param ServerRequestInterface $serverRequest
12
 *
13
 * @return array<string, mixed>
14
 */
15
function parse_callback_params(ServerRequestInterface $serverRequest): array
16
{
17
    $method = \strtoupper($serverRequest->getMethod());
18
19
    if ('POST' === $method) {
20
        $params = $serverRequest->getParsedBody();
21
22
        if (! \is_array($params)) {
23
            throw new RuntimeException('Invalid parsed body');
24
        }
25
26
        return $params;
27
    }
28
29
    if ('GET' !== $method) {
30
        throw new RuntimeException('Invalid callback method');
31
    }
32
33
    if ($serverRequest->getUri()->getFragment()) {
34
        \parse_str($serverRequest->getUri()->getFragment(), $params);
35
36
        return $params;
37
    }
38
39
    return $serverRequest->getQueryParams();
40
}
41