| Conditions | 5 |
| Paths | 4 |
| Total Lines | 21 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 11 |
| CRAP Score | 5 |
| Changes | 0 | ||
| 1 | <?php |
||
| 22 | 5 | public function detect($content) |
|
| 23 | { |
||
| 24 | 5 | if ($content == '') { |
|
| 25 | 1 | return []; |
|
| 26 | } |
||
| 27 | |||
| 28 | 4 | $data = json_decode($content, true); |
|
| 29 | |||
| 30 | 4 | if (json_last_error() !== JSON_ERROR_NONE) { |
|
| 31 | 1 | throw ErrorException::invalidResponse(json_last_error_msg(), json_last_error()); |
|
| 32 | } |
||
| 33 | |||
| 34 | 3 | if (!empty($data['code'])) { |
|
| 35 | 2 | throw ErrorException::failed( |
|
| 36 | 2 | isset($data['message']) ? $data['message'] : '', |
|
| 37 | 2 | $data['code'] |
|
| 38 | ); |
||
| 39 | } |
||
| 40 | |||
| 41 | 1 | return (array) $data; |
|
| 42 | } |
||
| 43 | } |
||
| 44 |