Skip to content

Commit

Permalink
Merge branch 'transition-words-in-content' of github.com:vormkracht10…
Browse files Browse the repository at this point in the history
…/laravel-seo-scanner into transition-words-in-content
  • Loading branch information
Baspa committed Aug 17, 2023
2 parents 94561dd + c6bddff commit ae948ce
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions src/Checks/Content/AltTagCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 [
Expand Down

0 comments on commit ae948ce

Please sign in to comment.