Conditions | 4 |
Paths | 1 |
Total Lines | 18 |
Code Lines | 8 |
Lines | 0 |
Ratio | 0 % |
Tests | 9 |
CRAP Score | 4 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
24 | 8 | public function detect(ResponseInterface $response) |
|
25 | { |
||
26 | 8 | if ($response->getStatusCode() == 404) { |
|
27 | 1 | throw NotFoundException::page(); |
|
28 | } |
||
29 | |||
30 | 7 | $content = $response->getBody()->getContents(); |
|
31 | |||
32 | // no warnings |
||
33 | 7 | if (strpos($content, '<ann><warning>') === false) { |
|
34 | 1 | return $content; |
|
35 | } |
||
36 | |||
37 | 6 | if (preg_match('/<warning>no result for (?<source>[a-z]+)=(?<id>[^<]*)<\/warning>/i', $content, $match)) { |
|
38 | 5 | throw NotFoundException::source($match['source'], $match['id']); |
|
39 | } |
||
40 | |||
41 | 1 | throw ErrorException::error(preg_replace('/.*<warning>(.*)<\/warning>.*/im', '$1', $content)); |
|
42 | } |
||
44 |