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