Total Complexity | 4 |
Total Lines | 29 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
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 |
|
40 | } |
||
41 | } |
||
42 |