Passed
Push — next ( 737617...5ddafc )
by Bas
13:34 queued 11:32
created

HandlesResponses::decodeResponse()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 8
nc 2
nop 1
dl 0
loc 12
ccs 9
cts 9
cp 1
crap 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ArangoClient;
6
7
use ArangoClient\Prometheus\Prometheus;
8
use Psr\Http\Message\ResponseInterface;
9
use stdClass;
10
11
trait HandlesResponses
12
{
13
    use HandlesJson;
14
15
    /**
16
     * @SuppressWarnings(PHPMD.StaticAccess)
17
     */
18 117
    protected function decodeResponse(ResponseInterface $response): stdClass
19
    {
20 117
        $contentType = null;
21 117
        $rawContentType = $response->getHeader('Content-type');
22 117
        if (is_array($rawContentType) && sizeOf($rawContentType) > 0) {
23 117
            $contentType = $rawContentType[0];
24
        }
25
26 117
        return match ($contentType) {
27 117
            "application/json; charset=utf-8" => $this->decodeJsonResponse($response),
28 117
            "text/plain; charset=utf-8" => $this->decodeTextResponse($response),
29 117
            default => (object) $response->getBody()->getContents(),
30 117
        };
31
    }
32
33
    /**
34
     * @SuppressWarnings(PHPMD.StaticAccess)
35
     */
36 1
    protected function decodeTextResponse(ResponseInterface $response): stdClass
37
    {
38 1
        $prometheus = new Prometheus();
39 1
        return $prometheus->parseStream($response);
40
    }
41
}
42