diff --git a/src/Checks/Content/AltTagCheck.php b/src/Checks/Content/AltTagCheck.php index ba5681dc..7eb9d5d2 100644 --- a/src/Checks/Content/AltTagCheck.php +++ b/src/Checks/Content/AltTagCheck.php @@ -39,27 +39,11 @@ public function check(Response $response, Crawler $crawler): bool public function validateContent(Crawler $crawler): bool { $imagesWithoutAlt = $crawler->filterXPath('//img[not(@alt)]')->each(function (Crawler $node, $i) { - $src = $node->attr('src'); - - $dimensions = $this->getImageDimensions($src, $node); - - if ($dimensions['width'] < 5 || $dimensions['height'] < 5) { - return null; - } - - return $src; + return $this->filterImage($node); }); - + $imagesWithEmptyAlt = $crawler->filterXPath('//img[@alt=""]')->each(function (Crawler $node, $i) { - $src = $node->attr('src'); - - $dimensions = $this->getImageDimensions($src, $node); - - if ($dimensions['width'] < 5 || $dimensions['height'] < 5) { - return null; - } - - return $src; + return $this->filterImage($node); }); // Remove null values from the arrays @@ -81,7 +65,24 @@ public function validateContent(Crawler $crawler): bool return true; } - public function getImageDimensions(string $src, Crawler $node): array + private function filterImage($node): ?string + { + $src = $node->attr('src'); + + if (str_contains($src, '.svg')) { + return $src; + } + + $dimensions = $this->getImageDimensions($src, $node); + + if ($dimensions['width'] < 5 || $dimensions['height'] < 5) { + return null; + } + + return $src; + } + + private function getImageDimensions(string $src, Crawler $node): array { if (app()->runningUnitTests()) { return [