From d11af7e93ff810dab4d354a117cbe16124cab2eb Mon Sep 17 00:00:00 2001 From: Ben Ramsey Date: Sat, 13 Dec 2025 21:52:15 -0600 Subject: [PATCH] Remove checks for methods, since the interface now has them --- src/Uuid.php | 22 ++-------------------- src/UuidFactoryInterface.php | 2 ++ tests/UuidTest.php | 15 --------------- 3 files changed, 4 insertions(+), 35 deletions(-) diff --git a/src/Uuid.php b/src/Uuid.php index ce71fe7..e018e88 100644 --- a/src/Uuid.php +++ b/src/Uuid.php @@ -20,7 +20,6 @@ use Ramsey\Uuid\Codec\CodecInterface; use Ramsey\Uuid\Converter\NumberConverterInterface; use Ramsey\Uuid\Converter\TimeConverterInterface; use Ramsey\Uuid\Exception\InvalidArgumentException; -use Ramsey\Uuid\Exception\UnsupportedOperationException; use Ramsey\Uuid\Lazy\LazyUuidFromString; use Ramsey\Uuid\Rfc4122\FieldsInterface as Rfc4122FieldsInterface; use Ramsey\Uuid\Rfc4122\UuidInterface as Rfc4122UuidInterface; @@ -564,14 +563,7 @@ class Uuid implements Rfc4122UuidInterface */ public static function uuid7(?DateTimeInterface $dateTime = null): UuidInterface { - $factory = self::getFactory(); - - if (method_exists($factory, 'uuid7')) { - /** @var UuidInterface */ - return $factory->uuid7($dateTime); - } - - throw new UnsupportedOperationException('The provided factory does not support the uuid7() method'); + return self::getFactory()->uuid7($dateTime); } /** @@ -591,16 +583,6 @@ class Uuid implements Rfc4122UuidInterface public static function uuid8(string $bytes): UuidInterface { /** @phpstan-ignore possiblyImpure.methodCall */ - $factory = self::getFactory(); - - if (method_exists($factory, 'uuid8')) { - /** - * @var UuidInterface - * @phpstan-ignore possiblyImpure.methodCall - */ - return $factory->uuid8($bytes); - } - - throw new UnsupportedOperationException('The provided factory does not support the uuid8() method'); + return self::getFactory()->uuid8($bytes); } } diff --git a/src/UuidFactoryInterface.php b/src/UuidFactoryInterface.php index b3d6f2f..7344676 100644 --- a/src/UuidFactoryInterface.php +++ b/src/UuidFactoryInterface.php @@ -182,6 +182,8 @@ interface UuidFactoryInterface * * @return UuidInterface A UuidInterface instance that represents a * version 8 UUID + * + * @pure */ public function uuid8(string $bytes): UuidInterface; } diff --git a/tests/UuidTest.php b/tests/UuidTest.php index 4cf166d..f83e163 100644 --- a/tests/UuidTest.php +++ b/tests/UuidTest.php @@ -10,7 +10,6 @@ use Brick\Math\RoundingMode; use DateTimeImmutable; use DateTimeInterface; use Mockery; -use Mockery\MockInterface; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\MockObject\MockObject; use Ramsey\Uuid\Codec\StringCodec; @@ -763,20 +762,6 @@ class UuidTest extends TestCase $this->assertSame(Version::Custom, $uuid->getFields()->getVersion()); } - public function testUuid8ThrowsExceptionForUnsupportedFactory(): void - { - /** @var UuidFactoryInterface&MockInterface $factory */ - $factory = Mockery::mock(UuidFactoryInterface::class); - - Uuid::setFactory($factory); - - $this->expectException(UnsupportedOperationException::class); - $this->expectExceptionMessage('The provided factory does not support the uuid8() method'); - - /** @phpstan-ignore staticMethod.resultUnused */ - Uuid::uuid8("\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99\xaa\xbb\xcc\xdd\xee\xff"); - } - /** * Tests known version-3 UUIDs *