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