From 1d4077d213ffa6ebba1305ffac5d5cbd3d2530a3 Mon Sep 17 00:00:00 2001 From: Ben Ramsey Date: Sun, 27 Mar 2022 16:37:53 -0500 Subject: [PATCH] Remove deprecated getClockSeqHiAndReservedHex() method --- CHANGELOG.md | 2 ++ src/DeprecatedUuidInterface.php | 8 ------ src/DeprecatedUuidMethodsTrait.php | 10 -------- src/Lazy/LazyUuidFromString.php | 7 ------ src/Rfc4122/UuidInterface.php | 2 ++ src/Rfc4122/UuidV2.php | 2 -- src/Uuid.php | 6 ++--- tests/ExpectedBehaviorTest.php | 30 +++++++++++++---------- tests/UuidTest.php | 13 ++++++---- tests/static-analysis/UuidIsImmutable.php | 4 +-- 10 files changed, 34 insertions(+), 50 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ce057a..fd07660 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. * `Ramsey\Uuid\DegradedUuid` * `Ramsey\Uuid\Generator\RandomLibAdapter` * `Ramsey\Uuid\Provider\Node\NodeProviderCollection` +* Remove the following deprecated methods from Uuid classes: + * `getClockSeqHiAndReservedHex()` * Remove dependency on ramsey/collection package. ### Deprecated diff --git a/src/DeprecatedUuidInterface.php b/src/DeprecatedUuidInterface.php index ed6d9de..3c502c2 100644 --- a/src/DeprecatedUuidInterface.php +++ b/src/DeprecatedUuidInterface.php @@ -39,14 +39,6 @@ interface DeprecatedUuidInterface */ public function getFieldsHex(): array; - /** - * @deprecated Use {@see UuidInterface::getFields()} to get a - * {@see FieldsInterface} instance. If it is a - * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface} instance, you may call - * {@see \Ramsey\Uuid\Rfc4122\FieldsInterface::getClockSeqHiAndReserved()}. - */ - public function getClockSeqHiAndReservedHex(): string; - /** * @deprecated Use {@see UuidInterface::getFields()} to get a * {@see FieldsInterface} instance. If it is a diff --git a/src/DeprecatedUuidMethodsTrait.php b/src/DeprecatedUuidMethodsTrait.php index 3428295..470b666 100644 --- a/src/DeprecatedUuidMethodsTrait.php +++ b/src/DeprecatedUuidMethodsTrait.php @@ -63,16 +63,6 @@ trait DeprecatedUuidMethodsTrait return $this->numberConverter->fromHex($this->fields->getClockSeqHiAndReserved()->toString()); } - /** - * @deprecated Use {@see UuidInterface::getFields()} to get a - * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} - * instance, you may call {@see Rfc4122FieldsInterface::getClockSeqHiAndReserved()}. - */ - public function getClockSeqHiAndReservedHex(): string - { - return $this->fields->getClockSeqHiAndReserved()->toString(); - } - /** * @deprecated Use {@see UuidInterface::getFields()} to get a * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} diff --git a/src/Lazy/LazyUuidFromString.php b/src/Lazy/LazyUuidFromString.php index 8ba7579..cddabbc 100644 --- a/src/Lazy/LazyUuidFromString.php +++ b/src/Lazy/LazyUuidFromString.php @@ -148,13 +148,6 @@ final class LazyUuidFromString implements UuidInterface ->getFieldsHex(); } - /** @psalm-suppress DeprecatedMethod */ - public function getClockSeqHiAndReservedHex(): string - { - return ($this->unwrapped ?? $this->unwrap()) - ->getClockSeqHiAndReservedHex(); - } - /** @psalm-suppress DeprecatedMethod */ public function getClockSeqLowHex(): string { diff --git a/src/Rfc4122/UuidInterface.php b/src/Rfc4122/UuidInterface.php index 3e4d9fa..97d93bf 100644 --- a/src/Rfc4122/UuidInterface.php +++ b/src/Rfc4122/UuidInterface.php @@ -33,4 +33,6 @@ interface UuidInterface extends BaseUuidInterface * @link https://tools.ietf.org/html/rfc4122#section-3 RFC 4122, ยง 3: Namespace Registration Template */ public function getUrn(): string; + + public function getFields(): FieldsInterface; } diff --git a/src/Rfc4122/UuidV2.php b/src/Rfc4122/UuidV2.php index 74906f0..18fc36f 100644 --- a/src/Rfc4122/UuidV2.php +++ b/src/Rfc4122/UuidV2.php @@ -114,7 +114,6 @@ final class UuidV2 extends Uuid implements UuidInterface */ public function getLocalDomain(): int { - /** @var Rfc4122FieldsInterface $fields */ $fields = $this->getFields(); return (int) hexdec($fields->getClockSeqLow()->toString()); @@ -133,7 +132,6 @@ final class UuidV2 extends Uuid implements UuidInterface */ public function getLocalIdentifier(): IntegerObject { - /** @var Rfc4122FieldsInterface $fields */ $fields = $this->getFields(); return new IntegerObject( diff --git a/src/Uuid.php b/src/Uuid.php index 5f0922b..1d7249e 100644 --- a/src/Uuid.php +++ b/src/Uuid.php @@ -18,9 +18,9 @@ use DateTimeInterface; use Ramsey\Uuid\Codec\CodecInterface; use Ramsey\Uuid\Converter\NumberConverterInterface; use Ramsey\Uuid\Converter\TimeConverterInterface; -use Ramsey\Uuid\Fields\FieldsInterface; use Ramsey\Uuid\Lazy\LazyUuidFromString; use Ramsey\Uuid\Rfc4122\FieldsInterface as Rfc4122FieldsInterface; +use Ramsey\Uuid\Rfc4122\UuidInterface as Rfc4122UuidInterface; use Ramsey\Uuid\Type\Hexadecimal; use Ramsey\Uuid\Type\Integer as IntegerObject; use ValueError; @@ -40,7 +40,7 @@ use function substr; * * @psalm-immutable */ -class Uuid implements UuidInterface +class Uuid implements Rfc4122UuidInterface { use DeprecatedUuidMethodsTrait; @@ -369,7 +369,7 @@ class Uuid implements UuidInterface return $this->codec->encodeBinary($this); } - public function getFields(): FieldsInterface + public function getFields(): Rfc4122FieldsInterface { return $this->fields; } diff --git a/tests/ExpectedBehaviorTest.php b/tests/ExpectedBehaviorTest.php index d813632..c2d8696 100644 --- a/tests/ExpectedBehaviorTest.php +++ b/tests/ExpectedBehaviorTest.php @@ -8,6 +8,7 @@ use Ramsey\Uuid\Converter\TimeConverterInterface; use Ramsey\Uuid\Generator\CombGenerator; use Ramsey\Uuid\Generator\DefaultTimeGenerator; use Ramsey\Uuid\Math\BrickMathCalculator; +use Ramsey\Uuid\Rfc4122\UuidInterface; use Ramsey\Uuid\Type\Hexadecimal; use Ramsey\Uuid\Type\Time; use Ramsey\Uuid\Uuid; @@ -33,9 +34,9 @@ class ExpectedBehaviorTest extends TestCase */ public function testStaticCreationMethodsAndStandardBehavior($method, $args) { + /** @var UuidInterface $uuid */ $uuid = call_user_func_array(['Ramsey\Uuid\Uuid', $method], $args); - $this->assertInstanceOf('Ramsey\Uuid\UuidInterface', $uuid); $this->assertIsInt($uuid->compareTo(Uuid::uuid1())); $this->assertNotSame(0, $uuid->compareTo(Uuid::uuid4())); $this->assertSame(0, $uuid->compareTo(clone $uuid)); @@ -54,13 +55,13 @@ class ExpectedBehaviorTest extends TestCase $this->assertIsString($uuid->getTimeLowHex()); $this->assertIsString($uuid->getTimeMidHex()); $this->assertIsString($uuid->getTimeHiAndVersionHex()); - $this->assertIsString($uuid->getClockSeqHiAndReservedHex()); + $this->assertIsString($uuid->getFields()->getClockSeqHiAndReserved()->toString()); $this->assertIsString($uuid->getClockSeqLowHex()); $this->assertIsString($uuid->getNodeHex()); $this->assertSame($uuid->getFieldsHex()['time_low'], $uuid->getTimeLowHex()); $this->assertSame($uuid->getFieldsHex()['time_mid'], $uuid->getTimeMidHex()); $this->assertSame($uuid->getFieldsHex()['time_hi_and_version'], $uuid->getTimeHiAndVersionHex()); - $this->assertSame($uuid->getFieldsHex()['clock_seq_hi_and_reserved'], $uuid->getClockSeqHiAndReservedHex()); + $this->assertSame($uuid->getFieldsHex()['clock_seq_hi_and_reserved'], $uuid->getFields()->getClockSeqHiAndReserved()->toString()); $this->assertSame($uuid->getFieldsHex()['clock_seq_low'], $uuid->getClockSeqLowHex()); $this->assertSame($uuid->getFieldsHex()['node'], $uuid->getNodeHex()); $this->assertSame(substr((string) $uuid->getHex(), 16), $uuid->getLeastSignificantBitsHex()); @@ -71,7 +72,7 @@ class ExpectedBehaviorTest extends TestCase $uuid->getTimeLowHex() . $uuid->getTimeMidHex() . $uuid->getTimeHiAndVersionHex() - . $uuid->getClockSeqHiAndReservedHex() + . $uuid->getFields()->getClockSeqHiAndReserved()->toString() . $uuid->getClockSeqLowHex() . $uuid->getNodeHex() ); @@ -97,7 +98,7 @@ class ExpectedBehaviorTest extends TestCase $uuid->getTimeLowHex() . '-' . $uuid->getTimeMidHex() . '-' . $uuid->getTimeHiAndVersionHex() . '-' - . $uuid->getClockSeqHiAndReservedHex() + . $uuid->getFields()->getClockSeqHiAndReserved()->toString() . $uuid->getClockSeqLowHex() . '-' . $uuid->getNodeHex() ); @@ -107,7 +108,7 @@ class ExpectedBehaviorTest extends TestCase $uuid->getTimeLowHex() . '-' . $uuid->getTimeMidHex() . '-' . $uuid->getTimeHiAndVersionHex() . '-' - . $uuid->getClockSeqHiAndReservedHex() + . $uuid->getFields()->getClockSeqHiAndReserved()->toString() . $uuid->getClockSeqLowHex() . '-' . $uuid->getNodeHex() ); @@ -237,11 +238,12 @@ class ExpectedBehaviorTest extends TestCase /** * @dataProvider provideFromStringInteger */ - public function testFromBytes($string, $version, $variant, $integer) + public function testFromBytes(string $string, ?int $version, int $variant, string $integer): void { $bytes = hex2bin(str_replace('-', '', $string)); - $uuid = Uuid::fromBytes($bytes); + /** @var UuidInterface $uuid */ + $uuid = Uuid::fromBytes((string) $bytes); $this->assertInstanceOf('Ramsey\Uuid\UuidInterface', $uuid); $this->assertSame($string, $uuid->toString()); @@ -253,7 +255,7 @@ class ExpectedBehaviorTest extends TestCase $this->assertSame($components[0], $uuid->getTimeLowHex()); $this->assertSame($components[1], $uuid->getTimeMidHex()); $this->assertSame($components[2], $uuid->getTimeHiAndVersionHex()); - $this->assertSame($components[3], $uuid->getClockSeqHiAndReservedHex() . $uuid->getClockSeqLowHex()); + $this->assertSame($components[3], $uuid->getFields()->getClockSeqHiAndReserved()->toString() . $uuid->getClockSeqLowHex()); $this->assertSame($components[4], $uuid->getNodeHex()); $this->assertSame($integer, (string) $uuid->getInteger()); $this->assertSame($bytes, $uuid->getBytes()); @@ -262,10 +264,11 @@ class ExpectedBehaviorTest extends TestCase /** * @dataProvider provideFromStringInteger */ - public function testFromInteger($string, $version, $variant, $integer) + public function testFromInteger(string $string, ?int $version, int $variant, string $integer): void { $bytes = hex2bin(str_replace('-', '', $string)); + /** @var UuidInterface $uuid */ $uuid = Uuid::fromInteger($integer); $this->assertInstanceOf('Ramsey\Uuid\UuidInterface', $uuid); @@ -278,7 +281,7 @@ class ExpectedBehaviorTest extends TestCase $this->assertSame($components[0], $uuid->getTimeLowHex()); $this->assertSame($components[1], $uuid->getTimeMidHex()); $this->assertSame($components[2], $uuid->getTimeHiAndVersionHex()); - $this->assertSame($components[3], $uuid->getClockSeqHiAndReservedHex() . $uuid->getClockSeqLowHex()); + $this->assertSame($components[3], $uuid->getFields()->getClockSeqHiAndReserved()->toString() . $uuid->getClockSeqLowHex()); $this->assertSame($components[4], $uuid->getNodeHex()); $this->assertSame($integer, (string) $uuid->getInteger()); $this->assertSame($bytes, $uuid->getBytes()); @@ -287,10 +290,11 @@ class ExpectedBehaviorTest extends TestCase /** * @dataProvider provideFromStringInteger */ - public function testFromString($string, $version, $variant, $integer) + public function testFromString(string $string, ?int $version, int $variant, string $integer): void { $bytes = hex2bin(str_replace('-', '', $string)); + /** @var UuidInterface $uuid */ $uuid = Uuid::fromString($string); $this->assertInstanceOf('Ramsey\Uuid\UuidInterface', $uuid); @@ -303,7 +307,7 @@ class ExpectedBehaviorTest extends TestCase $this->assertSame($components[0], $uuid->getTimeLowHex()); $this->assertSame($components[1], $uuid->getTimeMidHex()); $this->assertSame($components[2], $uuid->getTimeHiAndVersionHex()); - $this->assertSame($components[3], $uuid->getClockSeqHiAndReservedHex() . $uuid->getClockSeqLowHex()); + $this->assertSame($components[3], $uuid->getFields()->getClockSeqHiAndReserved()->toString() . $uuid->getClockSeqLowHex()); $this->assertSame($components[4], $uuid->getNodeHex()); $this->assertSame($integer, (string) $uuid->getInteger()); $this->assertSame($bytes, $uuid->getBytes()); diff --git a/tests/UuidTest.php b/tests/UuidTest.php index 9045d3c..c884f7d 100644 --- a/tests/UuidTest.php +++ b/tests/UuidTest.php @@ -153,9 +153,9 @@ class UuidTest extends TestCase public function testGetClockSeqHiAndReservedHex(): void { - /** @var Uuid $uuid */ + /** @var \Ramsey\Uuid\Rfc4122\UuidInterface $uuid */ $uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66'); - $this->assertSame('9b', $uuid->getClockSeqHiAndReservedHex()); + $this->assertSame('9b', $uuid->getFields()->getClockSeqHiAndReserved()->toString()); } public function testGetClockSeqLow(): void @@ -1203,7 +1203,7 @@ class UuidTest extends TestCase Uuid::fromInteger($int), ]; - /** @var UuidInterface $uuid */ + /** @var \Ramsey\Uuid\Rfc4122\UuidInterface $uuid */ foreach ($uuids as $uuid) { $this->assertSame($string, $uuid->toString()); $this->assertSame($hex, $uuid->getHex()->toString()); @@ -1213,7 +1213,10 @@ class UuidTest extends TestCase $this->assertSame($fields['time_low'], $uuid->getTimeLowHex()); $this->assertSame($fields['time_mid'], $uuid->getTimeMidHex()); $this->assertSame($fields['time_hi_and_version'], $uuid->getTimeHiAndVersionHex()); - $this->assertSame($fields['clock_seq_hi_and_reserved'], $uuid->getClockSeqHiAndReservedHex()); + $this->assertSame( + $fields['clock_seq_hi_and_reserved'], + $uuid->getFields()->getClockSeqHiAndReserved()->toString(), + ); $this->assertSame($fields['clock_seq_low'], $uuid->getClockSeqLowHex()); $this->assertSame($fields['node'], $uuid->getNodeHex()); $this->assertSame($urn, $uuid->getUrn()); @@ -1520,7 +1523,7 @@ class UuidTest extends TestCase } /** - * @covers Ramsey\Uuid\Uuid::jsonSerialize + * @covers \Ramsey\Uuid\Uuid::jsonSerialize */ public function testJsonSerialize(): void { diff --git a/tests/static-analysis/UuidIsImmutable.php b/tests/static-analysis/UuidIsImmutable.php index 6c17348..9245eb9 100644 --- a/tests/static-analysis/UuidIsImmutable.php +++ b/tests/static-analysis/UuidIsImmutable.php @@ -54,7 +54,6 @@ final class UuidIsImmutable $a->getNumberConverter(), $a->getHex(), $a->getFieldsHex(), - $a->getClockSeqHiAndReservedHex(), $a->getClockSeqLowHex(), $a->getClockSequenceHex(), $a->getDateTime(), @@ -71,11 +70,12 @@ final class UuidIsImmutable $a->getVersion(), $a->toString(), $a->__toString(), + $a->getFields(), ]; } /** - * @return UuidInterface[]|bool[] + * @return array{UuidInterface, UuidInterface, bool} * * @psalm-pure */