Conditions | 6 |
Paths | 5 |
Total Lines | 27 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Tests | 14 |
CRAP Score | 6 |
Changes | 0 |
1 | <?php |
||
24 | 6 | public function detect(ResponseInterface $response) |
|
25 | { |
||
26 | 6 | if ($response->getStatusCode() == 404) { |
|
27 | 1 | throw NotFoundException::page(); |
|
28 | } |
||
29 | |||
30 | 5 | $content = $response->getBody()->getContents(); |
|
31 | |||
32 | 5 | if ($content == '') { |
|
33 | 1 | return []; |
|
34 | } |
||
35 | |||
36 | 4 | $data = json_decode($content, true); |
|
37 | |||
38 | 4 | if (json_last_error() !== JSON_ERROR_NONE) { |
|
39 | 1 | throw ErrorException::invalidResponse(json_last_error_msg(), json_last_error()); |
|
40 | } |
||
41 | |||
42 | 3 | if (!empty($data['code'])) { |
|
43 | 2 | throw ErrorException::failed( |
|
44 | 2 | isset($data['message']) ? $data['message'] : '', |
|
45 | 2 | $data['code'] |
|
46 | ); |
||
47 | } |
||
48 | |||
49 | 1 | return (array) $data; |
|
50 | } |
||
51 | } |
||
52 |