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