Conditions | 7 |
Paths | 1 |
Total Lines | 28 |
Code Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Tests | 15 |
CRAP Score | 7.0119 |
Changes | 0 |
1 | <?php |
||
24 | 12 | public function detect(ResponseInterface $response) |
|
25 | { |
||
26 | 12 | if ($response->getStatusCode() == 404) { |
|
27 | 1 | throw NotFoundException::page(); |
|
28 | } |
||
29 | |||
30 | 11 | $content = $response->getBody()->getContents(); |
|
31 | |||
32 | // no warnings |
||
33 | 11 | if (strpos($content, '<ann><warning>') === false) { |
|
34 | 1 | return $content; |
|
35 | } |
||
36 | |||
37 | 10 | if (preg_match('/<warning>no result for (title|manga|anime)=([^<]*)<\/warning>/i', $content, $match)) { |
|
38 | 9 | switch ($match[1]) { |
|
39 | 9 | case 'title': |
|
40 | 3 | throw NotFoundException::title($match[2]); |
|
41 | break; |
||
42 | 6 | case 'manga': |
|
43 | 3 | throw NotFoundException::manga($match[2]); |
|
44 | break; |
||
45 | 3 | case 'anime': |
|
46 | 3 | throw NotFoundException::anime($match[2]); |
|
47 | break; |
||
48 | } |
||
49 | } |
||
50 | |||
51 | 1 | throw ErrorException::error(preg_replace('/.*<warning>(.*)<\/warning>.*/im', '$1', $content)); |
|
52 | } |
||
54 |