Conditions | 3 |
Paths | 3 |
Total Lines | 14 |
Code Lines | 8 |
Lines | 3 |
Ratio | 21.43 % |
Tests | 0 |
CRAP Score | 12 |
Changes | 0 |
1 | <?php |
||
22 | public function hydrate(ResponseInterface $response, string $class): array |
||
23 | { |
||
24 | $body = $response->getBody()->__toString(); |
||
25 | View Code Duplication | if (strpos($response->getHeaderLine('Content-Type'), 'application/json') !== 0) { |
|
|
|||
26 | throw new HydrationException('The ArrayHydrator cannot hydrate response with Content-Type:'.$response->getHeaderLine('Content-Type')); |
||
27 | } |
||
28 | |||
29 | $content = json_decode($body, true); |
||
30 | if (JSON_ERROR_NONE !== json_last_error()) { |
||
31 | throw new HydrationException(sprintf('Error (%d) when trying to json_decode response', json_last_error())); |
||
32 | } |
||
33 | |||
34 | return $content; |
||
35 | } |
||
36 | } |
||
37 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.