Conditions | 5 |
Paths | 6 |
Total Lines | 30 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Tests | 12 |
CRAP Score | 5 |
Changes | 0 |
1 | <?php |
||
24 | 3 | public function check(Subject $subject): ResultCollection |
|
25 | { |
||
26 | 3 | $resultCollection = new ResultCollection(); |
|
27 | |||
28 | /** |
||
29 | * Check |
||
30 | */ |
||
31 | 3 | $contextDescription = $subject->getContextDescription(); |
|
32 | |||
33 | 3 | $imgTags = $subject->getDom()->getElementsByTagName('img'); |
|
34 | |||
35 | /** |
||
36 | * @var \DOMElement $imgTag |
||
37 | */ |
||
38 | 3 | $missingAltAttributes = 0; |
|
39 | |||
40 | 3 | foreach ($imgTags as $imgTag) { |
|
41 | 3 | $altAttribute = $imgTag->attributes->getNamedItem('alt'); |
|
42 | |||
43 | 3 | if (!$altAttribute || empty($altAttribute->nodeValue)) { |
|
44 | 3 | $missingAltAttributes++; |
|
45 | } |
||
46 | } |
||
47 | |||
48 | 3 | if ($missingAltAttributes > 0) { |
|
49 | 3 | $resultCollection->add(new Result($contextDescription, "$missingAltAttributes img tag is missing alt attribute")); |
|
50 | } |
||
51 | |||
52 | 3 | return $resultCollection; |
|
53 | } |
||
54 | } |