Conditions | 5 |
Paths | 7 |
Total Lines | 27 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
15 | public function validate(Response $response) |
||
16 | { |
||
17 | if ($response->getContentType() !== 'text/html') { |
||
18 | return; |
||
19 | } |
||
20 | |||
21 | $crawler = new Crawler($response->getBody()); |
||
22 | |||
23 | $idList = $crawler->filterXPath('//*[@id!=""]'); |
||
24 | |||
25 | $foundIds = array(); |
||
26 | $duplicatedIds = array(); |
||
27 | |||
28 | foreach ($idList as $idElement) { |
||
29 | $id = $idElement->getAttribute('id'); |
||
30 | if (array_key_exists($id, $foundIds)) { |
||
31 | $duplicatedIds[$id] = true; |
||
32 | } else { |
||
33 | $foundIds[$id] = true; |
||
34 | } |
||
35 | } |
||
36 | |||
37 | if (count($duplicatedIds) > 0) { |
||
38 | unset($duplicatedIds['']); |
||
39 | throw new ValidationFailedException('Duplicate ids found (' . implode(', ', array_keys($duplicatedIds)) . ')'); |
||
40 | } |
||
41 | } |
||
42 | } |
||
43 |