catch ValueError raised by PHP 8 (#352)

This commit is contained in:
Remi Collet
2020-10-29 17:57:41 +01:00
committed by GitHub
parent e20165e9dd
commit ae7df1ceb9
+6 -2
View File
@@ -28,8 +28,12 @@ class DefaultNameGenerator implements NameGeneratorInterface
/** @psalm-pure */
public function generate(UuidInterface $ns, string $name, string $hashAlgorithm): string
{
/** @var string|bool $bytes */
$bytes = @hash($hashAlgorithm, $ns->getBytes() . $name, true);
try {
/** @var string|bool $bytes */
$bytes = @hash($hashAlgorithm, $ns->getBytes() . $name, true);
} catch (\ValueError $e) {
$bytes = false; // keep same behavior than PHP 7
}
if ($bytes === false) {
throw new NameException(sprintf(