Total Complexity | 7 |
Total Lines | 47 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
10 | class GuzzleResponse implements HttpClientResponse |
||
11 | { |
||
12 | use NeedsParseHeaders; |
||
13 | |||
14 | protected ResponseInterface $response; |
||
15 | |||
16 | 16 | public function __construct(ResponseInterface $response) |
|
17 | { |
||
18 | 16 | $this->response = $response; |
|
19 | } |
||
20 | |||
21 | 6 | public function getStatusCode(): int |
|
22 | { |
||
23 | 6 | return $this->response->getStatusCode(); |
|
24 | } |
||
25 | |||
26 | 1 | public function getHeaders(): array |
|
29 | } |
||
30 | |||
31 | 1 | public function getBody(): string |
|
34 | } |
||
35 | |||
36 | 14 | public function parseJson(): array |
|
37 | { |
||
38 | 14 | $response = $this->toString(); |
|
39 | 14 | $data = json_decode($response, true); |
|
40 | |||
41 | 14 | if (! $data) { |
|
42 | 2 | throw new ImpossibleToParseJsonException( |
|
43 | 2 | 'Service response could not be parsed to JSON, Response: ' . |
|
44 | 2 | $response . ', Reason: ' . json_last_error() |
|
45 | 2 | ); |
|
46 | } |
||
47 | |||
48 | 12 | return $data; |
|
49 | } |
||
50 | |||
51 | 15 | private function toString(): string |
|
57 | } |
||
58 | } |
||
59 |