| Conditions | 7 |
| Paths | 6 |
| Total Lines | 18 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 11 |
| CRAP Score | 7.0283 |
| Changes | 0 | ||
| 1 | <?php |
||
| 23 | 27 | public function transform(ResponseInterface $response, ?bool $needHeader = null, ?bool $noBody = null): array |
|
| 24 | { |
||
| 25 | 27 | $content = []; |
|
| 26 | 27 | if (is_null($noBody) or !$noBody) { |
|
| 27 | 27 | $body = (string)$response->getBody(); |
|
| 28 | 27 | if (strpos($response->getHeaderLine('Content-Type'), 'application/json') === 0) |
|
| 29 | 26 | if (JSON_ERROR_NONE === json_last_error()) |
|
| 30 | 26 | $content = json_decode($body, true); |
|
| 31 | else |
||
| 32 | 26 | throw new TransformResponseException('Error transforming response to array. JSON_ERROR: ' . json_last_error()); |
|
| 33 | else |
||
| 34 | 1 | throw new TransformResponseException('Error transforming response to array. Content-Type is not application/json'); |
|
| 35 | } |
||
| 36 | 26 | if (!is_null($needHeader) and $needHeader) { |
|
| 37 | $content['responseHeaders'] = $response->getHeaders(); |
||
| 38 | } |
||
| 39 | 26 | return $content; |
|
| 40 | } |
||
| 41 | } |
||
| 42 |