diff --git a/src/Html.php b/src/Html.php index 958ebed..2c91e35 100644 --- a/src/Html.php +++ b/src/Html.php @@ -62,8 +62,11 @@ public function hasAnyClassOf(string ...$class): bool } + /** + * @param Stringable|scalar|null $content + */ public static function highlight( - Stringable|string|null $content, + mixed $content, Color $color = Color::Primary, bool $translate = true, ): self { @@ -73,8 +76,11 @@ public static function highlight( } + /** + * @param Stringable|scalar|null $content + */ public static function subtext( - Stringable|string|null $content, + mixed $content, Color $color = Color::Secondary, bool $translate = true, ): self { @@ -180,7 +186,7 @@ public static function option( ): self { $content = static::translate($content, $translate); $labelHtml = static::translate($label, $translate); - $label = Strings::stripHtml($labelHtml); + $label = Strings::stripHtml($labelHtml ?? ''); if (!$content && $label <> $labelHtml) { $content = $labelHtml; @@ -283,18 +289,21 @@ public static function progressBar(float $percent, Color $color): self } - private static function translate(Stringable|string|null $text, bool $translate = true): Stringable|string + /** + * @param Stringable|scalar|null $value + */ + private static function translate(mixed $value, bool $translate = true): null|string|Stringable { - $text ??= ''; + $value = strval($value) ?: null; if (!$translate || static::$disableTranslation || !static::$translator) { - return $text; + return $value; } - if (!$text || !Strings::match((string) $text, static::TranslationRegEx)) { - return $text; + if (!$value || !Strings::match($value, static::TranslationRegEx)) { + return $value; } - return static::$translator->translate($text); + return static::$translator->translate($value); } }