From 2a39b0a67413e902274b09f640c6b68ffbd199fa Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Thu, 29 Oct 2020 16:34:55 +0100 Subject: [PATCH 1/2] catch ValueError raised by PHP 8 --- src/Generator/DefaultNameGenerator.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Generator/DefaultNameGenerator.php b/src/Generator/DefaultNameGenerator.php index 270e8fbe..be552b91 100644 --- a/src/Generator/DefaultNameGenerator.php +++ b/src/Generator/DefaultNameGenerator.php @@ -29,7 +29,11 @@ class DefaultNameGenerator implements NameGeneratorInterface public function generate(UuidInterface $ns, string $name, string $hashAlgorithm): string { /** @var string|bool $bytes */ - $bytes = @hash($hashAlgorithm, $ns->getBytes() . $name, true); + try { + $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( From 3a488f24e05e711809f61626aeb8740d53e56feb Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Thu, 29 Oct 2020 16:40:08 +0100 Subject: [PATCH 2/2] CS --- src/Generator/DefaultNameGenerator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Generator/DefaultNameGenerator.php b/src/Generator/DefaultNameGenerator.php index be552b91..1c0b0048 100644 --- a/src/Generator/DefaultNameGenerator.php +++ b/src/Generator/DefaultNameGenerator.php @@ -28,11 +28,11 @@ class DefaultNameGenerator implements NameGeneratorInterface /** @psalm-pure */ public function generate(UuidInterface $ns, string $name, string $hashAlgorithm): string { - /** @var string|bool $bytes */ try { + /** @var string|bool $bytes */ $bytes = @hash($hashAlgorithm, $ns->getBytes() . $name, true); } catch (\ValueError $e) { - $bytes = false; // keep same behavior than PHP 7 */ + $bytes = false; // keep same behavior than PHP 7 } if ($bytes === false) {