Skip to content

Commit

Permalink
TranslatorFilter: Use mixed annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Barášek committed Mar 4, 2021
1 parent f324072 commit 0869156
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/Translator/TranslatorFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@ public function __construct(
}


/**
* @param string|object $haystack
*/
public function __invoke(FilterInfo $info, $haystack): string
public function __invoke(FilterInfo $info, mixed $haystack): string
{
if (is_object($haystack)) {
if (method_exists($haystack, '__toString')) {
$haystack = (string) $haystack;
} else {
throw new \InvalidArgumentException('Object "' . \get_class($haystack) . '" can not be serialized to string, because do not implement "__toString" method.');
throw new \InvalidArgumentException(
'Object "' . \get_debug_type($haystack) . '" can not be serialized to string, '
. 'because do not implement "__toString" method.',
);
}
} elseif (is_scalar($haystack)) {
$haystack = (string) $haystack;
}

return ($this->translator ?? $this->getDefaultTranslator())->translate($haystack);
Expand Down

0 comments on commit 0869156

Please sign in to comment.