From 8e79ff851a776b3e0fbf2014209812d1d15ef25e Mon Sep 17 00:00:00 2001 From: Ben Ramsey Date: Fri, 3 Jan 2020 11:29:41 -0600 Subject: [PATCH] Address Psalm errors --- .travis.yml | 2 +- phpstan-tests.neon | 4 ++++ src/BinaryUtils.php | 4 ++++ src/Builder/DefaultUuidBuilder.php | 2 ++ src/Builder/DegradedUuidBuilder.php | 2 ++ src/Builder/UuidBuilderInterface.php | 2 ++ src/Codec/CodecInterface.php | 8 +++++++ src/Codec/GuidStringCodec.php | 24 ++++++++++++++++--- src/Codec/OrderedTimeCodec.php | 3 +++ src/Codec/StringCodec.php | 16 ++++++++++++- src/Codec/TimestampFirstCombCodec.php | 22 ++++++++++++++--- src/Converter/DependencyCheckTrait.php | 2 ++ src/Converter/Number/BigNumberConverter.php | 6 +++++ .../Number/DegradedNumberConverter.php | 4 ++++ src/Converter/Number/GmpConverter.php | 4 ++++ src/Converter/NumberConverterInterface.php | 4 ++++ src/Converter/NumberStringTrait.php | 2 ++ src/Converter/Time/BigNumberTimeConverter.php | 8 +++++++ src/Converter/Time/DegradedTimeConverter.php | 4 ++++ src/Converter/Time/GmpTimeConverter.php | 4 ++++ src/Converter/Time/PhpTimeConverter.php | 6 ++++- src/Converter/TimeConverterInterface.php | 4 ++++ src/DegradedUuid.php | 2 +- src/UuidFactory.php | 14 ++++++++++- src/UuidFactoryInterface.php | 8 +++++++ src/UuidInterface.php | 4 ++++ src/Validator/Validator.php | 3 +++ src/Validator/ValidatorInterface.php | 2 ++ 28 files changed, 159 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index 09d308f..ff7410c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -54,7 +54,7 @@ script: - ./resources/scripts/cmd-proxy.sh composer run lint - ./resources/scripts/cmd-proxy.sh composer run phpcs - ./resources/scripts/cmd-proxy.sh composer run phpstan - - ./resources/scripts/cmd-proxy.sh composer run psalm + - ./resources/scripts/cmd-proxy.sh ./vendor/bin/psalm --show-info=false - travis_wait ./resources/scripts/cmd-proxy.sh ./vendor/bin/phpunit --verbose --coverage-clover build/logs/clover.xml after_success: diff --git a/phpstan-tests.neon b/phpstan-tests.neon index 8bf714d..5d582f1 100644 --- a/phpstan-tests.neon +++ b/phpstan-tests.neon @@ -20,3 +20,7 @@ parameters: message: "#^Function uuid_parse\\(\\) has parameter \\$uuid with no typehint specified\\.$#" count: 1 path: tests/phpstan-bootstrap.php + - + message: "#^Unreachable statement - code above always terminates\\.$#" + count: 3 + path: tests/UuidTest.php diff --git a/src/BinaryUtils.php b/src/BinaryUtils.php index 12cbe0b..0c8608f 100644 --- a/src/BinaryUtils.php +++ b/src/BinaryUtils.php @@ -30,6 +30,8 @@ class BinaryUtils * before the RFC 4122 variant is applied * * @return int The high field of the clock sequence multiplexed with the variant + * + * @psalm-pure */ public static function applyVariant(int $clockSeqHi): int { @@ -50,6 +52,8 @@ class BinaryUtils * @param int $version The RFC 4122 version to apply to the `time_hi` field * * @return int The high field of the timestamp multiplexed with the version number + * + * @psalm-pure */ public static function applyVersion(string $timeHi, int $version): int { diff --git a/src/Builder/DefaultUuidBuilder.php b/src/Builder/DefaultUuidBuilder.php index 67c98f2..dd4135c 100644 --- a/src/Builder/DefaultUuidBuilder.php +++ b/src/Builder/DefaultUuidBuilder.php @@ -22,6 +22,8 @@ use Ramsey\Uuid\UuidInterface; /** * DefaultUuidBuilder builds instances of Uuid + * + * @psalm-immutable */ class DefaultUuidBuilder implements UuidBuilderInterface { diff --git a/src/Builder/DegradedUuidBuilder.php b/src/Builder/DegradedUuidBuilder.php index f1aa9c2..d577f2d 100644 --- a/src/Builder/DegradedUuidBuilder.php +++ b/src/Builder/DegradedUuidBuilder.php @@ -22,6 +22,8 @@ use Ramsey\Uuid\UuidInterface; /** * DegradedUuidBuilder builds instances of DegradedUuid + * + * @psalm-immutable */ class DegradedUuidBuilder implements UuidBuilderInterface { diff --git a/src/Builder/UuidBuilderInterface.php b/src/Builder/UuidBuilderInterface.php index 7c1225b..06df7ec 100644 --- a/src/Builder/UuidBuilderInterface.php +++ b/src/Builder/UuidBuilderInterface.php @@ -19,6 +19,8 @@ use Ramsey\Uuid\UuidInterface; /** * A UUID builder builds instances of UuidInterface + * + * @psalm-immutable */ interface UuidBuilderInterface { diff --git a/src/Codec/CodecInterface.php b/src/Codec/CodecInterface.php index 041a996..45b3250 100644 --- a/src/Codec/CodecInterface.php +++ b/src/Codec/CodecInterface.php @@ -28,6 +28,8 @@ interface CodecInterface * string representation * * @return string Hexadecimal string representation of a UUID + * + * @psalm-pure */ public function encode(UuidInterface $uuid): string; @@ -38,6 +40,8 @@ interface CodecInterface * representation * * @return string Binary string representation of a UUID + * + * @psalm-pure */ public function encodeBinary(UuidInterface $uuid): string; @@ -49,6 +53,8 @@ interface CodecInterface * * @return UuidInterface An instance of a UUID decoded from a hexadecimal * string representation + * + * @psalm-pure */ public function decode(string $encodedUuid): UuidInterface; @@ -60,6 +66,8 @@ interface CodecInterface * * @return UuidInterface An instance of a UUID decoded from a binary string * representation + * + * @psalm-pure */ public function decodeBytes(string $bytes): UuidInterface; } diff --git a/src/Codec/GuidStringCodec.php b/src/Codec/GuidStringCodec.php index ea51128..24e8689 100644 --- a/src/Codec/GuidStringCodec.php +++ b/src/Codec/GuidStringCodec.php @@ -25,12 +25,16 @@ use Ramsey\Uuid\UuidInterface; */ class GuidStringCodec extends StringCodec { + /** + * @psalm-pure + */ public function encode(UuidInterface $uuid): string { + /** @var string[] $components */ $components = array_values($uuid->getFieldsHex()); // Swap byte-order on the first three fields. - $this->swapFields($components); + $components = $this->swapFields($components); return vsprintf( '%08s-%04s-%04s-%02s%02s-%012s', @@ -38,6 +42,9 @@ class GuidStringCodec extends StringCodec ); } + /** + * @psalm-pure + */ public function encodeBinary(UuidInterface $uuid): string { $components = array_values($uuid->getFieldsHex()); @@ -49,12 +56,15 @@ class GuidStringCodec extends StringCodec * @throws InvalidUuidStringException * * @inheritDoc + * + * @psalm-pure */ public function decode(string $encodedUuid): UuidInterface { $components = $this->extractComponents($encodedUuid); - $this->swapFields($components); + /** @var string[] $components */ + $components = $this->swapFields($components); return $this->getBuilder()->build($this, $this->getFields($components)); } @@ -63,6 +73,8 @@ class GuidStringCodec extends StringCodec * @throws InvalidArgumentException if $bytes is an invalid length * * @inheritDoc + * + * @psalm-pure */ public function decodeBytes(string $bytes): UuidInterface { @@ -74,8 +86,12 @@ class GuidStringCodec extends StringCodec * Swap fields to support GUID byte order * * @param string[] $components An array of UUID components (the UUID exploded on its dashes) + * + * @return string[] + * + * @psalm-pure */ - private function swapFields(array &$components): void + private function swapFields(array $components): array { $hex = unpack('H*', pack('L', hexdec($components[0]))); assert(is_string($hex[1])); @@ -88,5 +104,7 @@ class GuidStringCodec extends StringCodec $hex = unpack('H*', pack('S', hexdec($components[2]))); assert(is_string($hex[1])); $components[2] = $hex[1]; + + return $components; } } diff --git a/src/Codec/OrderedTimeCodec.php b/src/Codec/OrderedTimeCodec.php index 6878a58..f1cc997 100644 --- a/src/Codec/OrderedTimeCodec.php +++ b/src/Codec/OrderedTimeCodec.php @@ -44,6 +44,7 @@ class OrderedTimeCodec extends StringCodec * fields rearranged for optimized storage * * @inheritDoc + * @psalm-pure */ public function encodeBinary(UuidInterface $uuid): string { @@ -78,6 +79,8 @@ class OrderedTimeCodec extends StringCodec * @throws InvalidArgumentException if $bytes is an invalid length * * @inheritDoc + * + * @psalm-pure */ public function decodeBytes(string $bytes): UuidInterface { diff --git a/src/Codec/StringCodec.php b/src/Codec/StringCodec.php index 2b45a72..be63516 100644 --- a/src/Codec/StringCodec.php +++ b/src/Codec/StringCodec.php @@ -42,6 +42,9 @@ class StringCodec implements CodecInterface $this->builder = $builder; } + /** + * @psalm-pure + */ public function encode(UuidInterface $uuid): string { $fields = array_values($uuid->getFieldsHex()); @@ -52,6 +55,9 @@ class StringCodec implements CodecInterface ); } + /** + * @psalm-pure + */ public function encodeBinary(UuidInterface $uuid): string { return (string) hex2bin($uuid->getHex()); @@ -61,6 +67,8 @@ class StringCodec implements CodecInterface * @throws InvalidUuidStringException * * @inheritDoc + * + * @psalm-pure */ public function decode(string $encodedUuid): UuidInterface { @@ -74,6 +82,8 @@ class StringCodec implements CodecInterface * @throws InvalidArgumentException if $bytes is an invalid length * * @inheritDoc + * + * @psalm-pure */ public function decodeBytes(string $bytes): UuidInterface { @@ -85,7 +95,7 @@ class StringCodec implements CodecInterface $hexUuid = unpack('H*', $bytes); - return $this->decode($hexUuid[1]); + return $this->decode((string) $hexUuid[1]); } /** @@ -104,6 +114,8 @@ class StringCodec implements CodecInterface * @return string[] * * @throws InvalidUuidStringException + * + * @psalm-pure */ protected function extractComponents(string $encodedUuid): array { @@ -146,6 +158,8 @@ class StringCodec implements CodecInterface * the fields of an RFC 4122 UUID * * @return string[] + * + * @psalm-pure */ protected function getFields(array $components): array { diff --git a/src/Codec/TimestampFirstCombCodec.php b/src/Codec/TimestampFirstCombCodec.php index 13fab58..f040b3c 100644 --- a/src/Codec/TimestampFirstCombCodec.php +++ b/src/Codec/TimestampFirstCombCodec.php @@ -44,11 +44,14 @@ use Ramsey\Uuid\UuidInterface; */ class TimestampFirstCombCodec extends StringCodec { + /** + * @psalm-pure + */ public function encode(UuidInterface $uuid): string { $sixPieceComponents = array_values($uuid->getFieldsHex()); - $this->swapTimestampAndRandomBits($sixPieceComponents); + $sixPieceComponents = $this->swapTimestampAndRandomBits($sixPieceComponents); return vsprintf( '%08s-%04s-%04s-%02s%02s-%012s', @@ -56,6 +59,9 @@ class TimestampFirstCombCodec extends StringCodec ); } + /** + * @psalm-pure + */ public function encodeBinary(UuidInterface $uuid): string { $stringEncoding = $this->encode($uuid); @@ -67,12 +73,14 @@ class TimestampFirstCombCodec extends StringCodec * @throws InvalidUuidStringException * * @inheritDoc + * + * @psalm-pure */ public function decode(string $encodedUuid): UuidInterface { $fivePieceComponents = $this->extractComponents($encodedUuid); - $this->swapTimestampAndRandomBits($fivePieceComponents); + $fivePieceComponents = $this->swapTimestampAndRandomBits($fivePieceComponents); return $this->getBuilder()->build($this, $this->getFields($fivePieceComponents)); } @@ -81,6 +89,8 @@ class TimestampFirstCombCodec extends StringCodec * @throws InvalidArgumentException if $bytes is an invalid length * * @inheritDoc + * + * @psalm-pure */ public function decodeBytes(string $bytes): UuidInterface { @@ -91,8 +101,12 @@ class TimestampFirstCombCodec extends StringCodec * Swaps the first 48 bits with the last 48 bits * * @param string[] $components An array of UUID components (the UUID exploded on its dashes) + * + * @return string[] The adjusted components + * + * @psalm-pure */ - private function swapTimestampAndRandomBits(array &$components): void + private function swapTimestampAndRandomBits(array $components): array { $last48Bits = $components[4]; @@ -105,5 +119,7 @@ class TimestampFirstCombCodec extends StringCodec $components[0] = substr($last48Bits, 0, 8); $components[1] = substr($last48Bits, 8, 4); + + return $components; } } diff --git a/src/Converter/DependencyCheckTrait.php b/src/Converter/DependencyCheckTrait.php index a4e4a90..2c574d8 100644 --- a/src/Converter/DependencyCheckTrait.php +++ b/src/Converter/DependencyCheckTrait.php @@ -18,6 +18,8 @@ use Ramsey\Uuid\Exception\UnsatisfiedDependencyException; /** * Provides methods to check dependencies for various converters + * + * @psalm-immutable */ trait DependencyCheckTrait { diff --git a/src/Converter/Number/BigNumberConverter.php b/src/Converter/Number/BigNumberConverter.php index b049199..313ebbb 100644 --- a/src/Converter/Number/BigNumberConverter.php +++ b/src/Converter/Number/BigNumberConverter.php @@ -35,12 +35,15 @@ class BigNumberConverter implements NumberConverterInterface * @throws UnsatisfiedDependencyException if the chosen converter is not present * * @inheritDoc + * + * @psalm-pure */ public function fromHex(string $hex): string { $this->checkMoontoastMathLibrary(); $this->checkHexadecimalString($hex, 'hex'); + /** @psalm-suppress ImpureMethodCall */ return BigNumber::convertToBase10($hex, 16); } @@ -49,12 +52,15 @@ class BigNumberConverter implements NumberConverterInterface * @throws UnsatisfiedDependencyException if the chosen converter is not present * * @inheritDoc + * + * @psalm-pure */ public function toHex(string $number): string { $this->checkMoontoastMathLibrary(); $this->checkIntegerString($number, 'number'); + /** @psalm-suppress ImpureMethodCall */ return BigNumber::convertFromBase10($number, 16); } } diff --git a/src/Converter/Number/DegradedNumberConverter.php b/src/Converter/Number/DegradedNumberConverter.php index 7f9973d..fe19f4a 100644 --- a/src/Converter/Number/DegradedNumberConverter.php +++ b/src/Converter/Number/DegradedNumberConverter.php @@ -28,6 +28,8 @@ class DegradedNumberConverter implements NumberConverterInterface * @throws UnsatisfiedDependencyException if the chosen converter is not present * * @inheritDoc + * + * @psalm-pure */ public function fromHex(string $hex): string { @@ -43,6 +45,8 @@ class DegradedNumberConverter implements NumberConverterInterface * @throws UnsatisfiedDependencyException if the chosen converter is not present * * @inheritDoc + * + * @psalm-pure */ public function toHex(string $number): string { diff --git a/src/Converter/Number/GmpConverter.php b/src/Converter/Number/GmpConverter.php index 2c95a27..24d65ed 100644 --- a/src/Converter/Number/GmpConverter.php +++ b/src/Converter/Number/GmpConverter.php @@ -35,6 +35,8 @@ class GmpConverter implements NumberConverterInterface * @throws UnsatisfiedDependencyException if the chosen converter is not present * * @inheritDoc + * + * @psalm-pure */ public function fromHex(string $hex): string { @@ -51,6 +53,8 @@ class GmpConverter implements NumberConverterInterface * @throws UnsatisfiedDependencyException if the chosen converter is not present * * @inheritDoc + * + * @psalm-pure */ public function toHex(string $number): string { diff --git a/src/Converter/NumberConverterInterface.php b/src/Converter/NumberConverterInterface.php index 8f0d587..9ecea88 100644 --- a/src/Converter/NumberConverterInterface.php +++ b/src/Converter/NumberConverterInterface.php @@ -30,6 +30,8 @@ interface NumberConverterInterface * @param string $hex The hexadecimal string representation to convert * * @return string String representation of an integer + * + * @psalm-pure */ public function fromHex(string $hex): string; @@ -42,6 +44,8 @@ interface NumberConverterInterface * than PHP_INT_MAX. * * @return string Hexadecimal string + * + * @psalm-pure */ public function toHex(string $number): string; } diff --git a/src/Converter/NumberStringTrait.php b/src/Converter/NumberStringTrait.php index faf9217..fa825d5 100644 --- a/src/Converter/NumberStringTrait.php +++ b/src/Converter/NumberStringTrait.php @@ -19,6 +19,8 @@ use Ramsey\Uuid\Exception\InvalidArgumentException; /** * Provides shared functionality to check the values of string numbers for * conversion + * + * @psalm-immutable */ trait NumberStringTrait { diff --git a/src/Converter/Time/BigNumberTimeConverter.php b/src/Converter/Time/BigNumberTimeConverter.php index 9b153ee..dafc471 100644 --- a/src/Converter/Time/BigNumberTimeConverter.php +++ b/src/Converter/Time/BigNumberTimeConverter.php @@ -36,6 +36,10 @@ class BigNumberTimeConverter implements TimeConverterInterface * @throws UnsatisfiedDependencyException if the chosen converter is not present * * @inheritDoc + * + * @psalm-pure + * @psalm-suppress ImpureMethodCall The use of the external moontoast/math + * library causes Psalm to complain about impure method calls. */ public function calculateTime(string $seconds, string $microSeconds): array { @@ -70,6 +74,10 @@ class BigNumberTimeConverter implements TimeConverterInterface * @throws UnsatisfiedDependencyException if the chosen converter is not present * * @inheritDoc + * + * @psalm-pure + * @psalm-suppress ImpureMethodCall The use of the external moontoast/math + * library causes Psalm to complain about impure method calls. */ public function convertTime(string $timestamp): string { diff --git a/src/Converter/Time/DegradedTimeConverter.php b/src/Converter/Time/DegradedTimeConverter.php index 53dff3b..edd1c93 100644 --- a/src/Converter/Time/DegradedTimeConverter.php +++ b/src/Converter/Time/DegradedTimeConverter.php @@ -28,6 +28,8 @@ class DegradedTimeConverter implements TimeConverterInterface * @throws UnsatisfiedDependencyException if the chosen converter is not present * * @inheritDoc + * + * @psalm-pure */ public function calculateTime(string $seconds, string $microSeconds): array { @@ -43,6 +45,8 @@ class DegradedTimeConverter implements TimeConverterInterface * @throws UnsatisfiedDependencyException if the chosen converter is not present * * @inheritDoc + * + * @psalm-pure */ public function convertTime(string $timestamp): string { diff --git a/src/Converter/Time/GmpTimeConverter.php b/src/Converter/Time/GmpTimeConverter.php index 1224c0a..94f912c 100644 --- a/src/Converter/Time/GmpTimeConverter.php +++ b/src/Converter/Time/GmpTimeConverter.php @@ -34,6 +34,8 @@ class GmpTimeConverter implements TimeConverterInterface * @throws UnsatisfiedDependencyException if the chosen converter is not present * * @inheritDoc + * + * @psalm-pure */ public function calculateTime(string $seconds, string $microSeconds): array { @@ -64,6 +66,8 @@ class GmpTimeConverter implements TimeConverterInterface * @throws UnsatisfiedDependencyException if the chosen converter is not present * * @inheritDoc + * + * @psalm-pure */ public function convertTime(string $timestamp): string { diff --git a/src/Converter/Time/PhpTimeConverter.php b/src/Converter/Time/PhpTimeConverter.php index f92ae82..0f0d7f5 100644 --- a/src/Converter/Time/PhpTimeConverter.php +++ b/src/Converter/Time/PhpTimeConverter.php @@ -35,6 +35,8 @@ class PhpTimeConverter implements TimeConverterInterface * @throws UnsatisfiedDependencyException if the chosen converter is not present * * @inheritDoc + * + * @psalm-pure */ public function calculateTime(string $seconds, string $microSeconds): array { @@ -46,7 +48,7 @@ class PhpTimeConverter implements TimeConverterInterface // UUID epoch 1582-10-15 00:00:00 and the Unix epoch 1970-01-01 00:00:00. $uuidTime = ((int) $seconds * 10000000) + ((int) $microSeconds * 10) + 0x01b21dd213814000; - /** @psalm-suppress MixedArgument*/ + /** @psalm-suppress MixedArgument */ return [ 'low' => sprintf('%08x', $uuidTime & 0xffffffff), 'mid' => sprintf('%04x', ($uuidTime >> 32) & 0xffff), @@ -59,6 +61,8 @@ class PhpTimeConverter implements TimeConverterInterface * @throws UnsatisfiedDependencyException if the chosen converter is not present * * @inheritDoc + * + * @psalm-pure */ public function convertTime(string $timestamp): string { diff --git a/src/Converter/TimeConverterInterface.php b/src/Converter/TimeConverterInterface.php index c089538..ee4d99b 100644 --- a/src/Converter/TimeConverterInterface.php +++ b/src/Converter/TimeConverterInterface.php @@ -32,6 +32,8 @@ interface TimeConverterInterface * associated with the time to calculate * * @return string[] An array guaranteed to contain `low`, `mid`, and `hi` keys + * + * @psalm-pure */ public function calculateTime(string $seconds, string $microSeconds): array; @@ -43,6 +45,8 @@ interface TimeConverterInterface * greater than PHP_INT_MAX. * * @return string String representation of an integer + * + * @psalm-pure */ public function convertTime(string $timestamp): string; } diff --git a/src/DegradedUuid.php b/src/DegradedUuid.php index d82ad0c..be8efc0 100644 --- a/src/DegradedUuid.php +++ b/src/DegradedUuid.php @@ -29,7 +29,7 @@ use Ramsey\Uuid\Exception\UnsupportedOperationException; * * @psalm-immutable */ -class DegradedUuid extends Uuid +class DegradedUuid extends Uuid implements UuidInterface { /** * @return DateTimeImmutable An immutable instance of DateTimeInterface diff --git a/src/UuidFactory.php b/src/UuidFactory.php index 725c3f6..19bcad4 100644 --- a/src/UuidFactory.php +++ b/src/UuidFactory.php @@ -177,6 +177,9 @@ class UuidFactory implements UuidFactoryInterface $this->uuidBuilder = $builder; } + /** + * @psalm-mutation-free + */ public function getValidator(): ValidatorInterface { return $this->validator; @@ -193,11 +196,17 @@ class UuidFactory implements UuidFactoryInterface $this->validator = $validator; } + /** + * @psalm-pure + */ public function fromBytes(string $bytes): UuidInterface { return $this->codec->decodeBytes($bytes); } + /** + * @psalm-pure + */ public function fromString(string $uuid): UuidInterface { $uuid = strtolower($uuid); @@ -205,6 +214,9 @@ class UuidFactory implements UuidFactoryInterface return $this->codec->decode($uuid); } + /** + * @psalm-pure + */ public function fromInteger(string $integer): UuidInterface { $hex = $this->numberConverter->toHex($integer); @@ -287,7 +299,7 @@ class UuidFactory implements UuidFactoryInterface $ns = $this->codec->decode($ns); } - $hash = call_user_func($hashFunction, $ns->getBytes() . $name); + $hash = (string) call_user_func($hashFunction, $ns->getBytes() . $name); return $this->uuidFromHashedName($hash, $version); } diff --git a/src/UuidFactoryInterface.php b/src/UuidFactoryInterface.php index d6bbc83..9552261 100644 --- a/src/UuidFactoryInterface.php +++ b/src/UuidFactoryInterface.php @@ -24,6 +24,8 @@ interface UuidFactoryInterface { /** * Returns the validator to use for the factory + * + * @psalm-mutation-free */ public function getValidator(): ValidatorInterface; @@ -81,6 +83,8 @@ interface UuidFactoryInterface * * @return UuidInterface A UuidInterface instance created from a binary * string representation + * + * @psalm-pure */ public function fromBytes(string $bytes): UuidInterface; @@ -91,6 +95,8 @@ interface UuidFactoryInterface * * @return UuidInterface A UuidInterface instance created from a hexadecimal * string representation + * + * @psalm-pure */ public function fromString(string $uuid): UuidInterface; @@ -101,6 +107,8 @@ interface UuidFactoryInterface * * @return UuidInterface A UuidInterface instance created from the string * representation of a 128-bit integer + * + * @psalm-pure */ public function fromInteger(string $integer): UuidInterface; } diff --git a/src/UuidInterface.php b/src/UuidInterface.php index 39fec65..ea2b919 100644 --- a/src/UuidInterface.php +++ b/src/UuidInterface.php @@ -50,6 +50,10 @@ interface UuidInterface extends JsonSerializable, Serializable * The result is true if and only if the argument is not null, is a UUID * object, has the same variant, and contains the same value, bit for bit, * as the UUID. + * + * @param object|null $other An object to test for equality with this UUID + * + * @return bool True if the other object is equal to this UUID */ public function equals(?object $other): bool; diff --git a/src/Validator/Validator.php b/src/Validator/Validator.php index 9d20636..d1830e6 100644 --- a/src/Validator/Validator.php +++ b/src/Validator/Validator.php @@ -26,6 +26,9 @@ class Validator implements ValidatorInterface */ public const VALID_PATTERN = '^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$'; + /** + * @psalm-pure + */ public function validate(string $uuid): bool { $uuid = str_replace(['urn:', 'uuid:', 'URN:', 'UUID:', '{', '}'], '', $uuid); diff --git a/src/Validator/ValidatorInterface.php b/src/Validator/ValidatorInterface.php index 58a413b..61cfda8 100644 --- a/src/Validator/ValidatorInterface.php +++ b/src/Validator/ValidatorInterface.php @@ -25,6 +25,8 @@ interface ValidatorInterface * @param string $uuid The string to validate as a UUID * * @return bool True if the string is a valid UUID, false otherwise + * + * @psalm-pure */ public function validate(string $uuid): bool; }