| Conditions | 3 |
| Paths | 3 |
| Total Lines | 19 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 10 |
| CRAP Score | 3 |
| Changes | 0 | ||
| 1 | <?php |
||
| 25 | 9 | public function hydrate(ResponseInterface $response) |
|
| 26 | { |
||
| 27 | 9 | $body = $response->getBody()->__toString(); |
|
| 28 | |||
| 29 | 9 | $contentType = $response->getHeaderLine('Content-Type'); |
|
| 30 | 9 | if (strpos($contentType, 'application/json') !== 0) { |
|
| 31 | 3 | throw new HydrationException('The ArrayHydrator cannot hydrate response with Content-Type:'.$contentType); |
|
| 32 | } |
||
| 33 | |||
| 34 | 6 | $content = json_decode($body, true); |
|
| 35 | |||
| 36 | 6 | if (JSON_ERROR_NONE !== json_last_error()) { |
|
| 37 | 3 | throw new HydrationException( |
|
| 38 | 3 | sprintf('Error (%d) when trying to json_decode response', json_last_error()) |
|
| 39 | ); |
||
| 40 | } |
||
| 41 | |||
| 42 | 3 | return $content; |
|
| 43 | } |
||
| 44 | } |
||
| 45 |