Marking Uuid::uuid5() as pure: same input leads to same output, and no I/O under normal operational constraints

This commit is contained in:
Marco Pivetta
2020-03-19 15:11:47 +01:00
parent 2c9644b1d0
commit e830b23d77
2 changed files with 12 additions and 0 deletions
+3
View File
@@ -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
{
@@ -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!'
);
}
}