diff --git a/src/Detectors/Languages.php b/src/Detectors/Languages.php index 54780bc4..6fbe4e33 100644 --- a/src/Detectors/Languages.php +++ b/src/Detectors/Languages.php @@ -3,6 +3,8 @@ namespace Embed\Detectors; +use function Embed\isEmpty; + class Languages extends Detector { /** @@ -17,7 +19,7 @@ public function detect(): array $language = $node->getAttribute('hreflang'); $href = $node->getAttribute('href'); - if (!$language || !$href) { + if (isEmpty($language, $href)) { continue; } diff --git a/src/functions.php b/src/functions.php index 66edc09f..626833b5 100644 --- a/src/functions.php +++ b/src/functions.php @@ -132,3 +132,25 @@ function getDirectory(string $path, int $position): ?string $dirs = explode('/', $path); return $dirs[$position + 1] ?? null; } + +/** + * Determine whether at least one of the supplied variables is empty. + * + * @param mixed ...$values The values to check. + * + * @return boolean + */ +function isEmpty(mixed ...$values): bool +{ + $skipValues = array( + 'undefined', + ); + + foreach ($values as $value) { + if (empty($value) || in_array($value, $skipValues)) { + return true; + } + } + + return false; +}