From e830b23d7745c051caca91008b0091cf8a1661ae Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Thu, 19 Mar 2020 15:11:47 +0100 Subject: [PATCH] Marking `Uuid::uuid5()` as pure: same input leads to same output, and no I/O under normal operational constraints --- src/Uuid.php | 3 +++ tests/static-analysis/UuidIsImmutable.php | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/src/Uuid.php b/src/Uuid.php index 4f4045b..3f7e394 100644 --- a/src/Uuid.php +++ b/src/Uuid.php @@ -538,6 +538,9 @@ class Uuid implements UuidInterface * * @return UuidInterface A UuidInterface instance that represents a * version 5 UUID + * + * @psalm-pure note: changing the internal factory is an edge case not covered by purity invariants, + * but under constant factory setups, this method operates in functionally pure manners */ public static function uuid5($ns, string $name): UuidInterface { diff --git a/tests/static-analysis/UuidIsImmutable.php b/tests/static-analysis/UuidIsImmutable.php index 6b5a246..4c827fd 100644 --- a/tests/static-analysis/UuidIsImmutable.php +++ b/tests/static-analysis/UuidIsImmutable.php @@ -89,4 +89,13 @@ final class UuidIsImmutable Uuid::isValid('ff6f8cb0-c57d-11e1-9b21-0800200c9a66'), ]; } + + /** @psalm-pure */ + public static function uuid5IsPure(): UuidInterface + { + return Uuid::uuid5( + Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66'), + 'Look ma! I am a pure function!' + ); + } }