diff --git a/CHANGELOG.md b/CHANGELOG.md index baf8bad..7efa7da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. * `getLeastSignificantBitsHex()` * `getMostSignificantBits()` * `getMostSignificantBitsHex()` + * `getNode()` + * `getNodeHex()` * `getTimeHiAndVersion()` * `getTimeHiAndVersionHex()` * `getTimeLow()` diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 777e304..21f2850 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -14,7 +14,7 @@ parameters: - # Legacy methods of `Ramsey\Uuid` use interface methods that are NOT defined on `FieldsInterface` message: '#^Call to an undefined method Ramsey\\Uuid\\Fields\\FieldsInterface::get.*$#' - count: 4 + count: 3 path: ./src/Lazy/LazyUuidFromString.php - message: '#^Result of \|\| is always false\.$#' diff --git a/src/DeprecatedUuidInterface.php b/src/DeprecatedUuidInterface.php index a3469df..3779b6c 100644 --- a/src/DeprecatedUuidInterface.php +++ b/src/DeprecatedUuidInterface.php @@ -45,14 +45,6 @@ interface DeprecatedUuidInterface */ public function getDateTime(): DateTimeInterface; - /** - * @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::getNode()}. - */ - public function getNodeHex(): string; - /** * @deprecated In ramsey/uuid version 5.0.0, this will be removed from this * interface. It has moved to {@see \Ramsey\Uuid\Rfc4122\UuidInterface::getUrn()}. diff --git a/src/DeprecatedUuidMethodsTrait.php b/src/DeprecatedUuidMethodsTrait.php index 72fbaf3..356221a 100644 --- a/src/DeprecatedUuidMethodsTrait.php +++ b/src/DeprecatedUuidMethodsTrait.php @@ -142,28 +142,6 @@ trait DeprecatedUuidMethodsTrait ]; } - /** - * @deprecated Use {@see UuidInterface::getFields()} to get a - * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} - * instance, you may call {@see Rfc4122FieldsInterface::getNode()} - * and use the arbitrary-precision math library of your choice to - * convert it to a string integer. - */ - public function getNode(): string - { - return $this->numberConverter->fromHex($this->fields->getNode()->toString()); - } - - /** - * @deprecated Use {@see UuidInterface::getFields()} to get a - * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} - * instance, you may call {@see Rfc4122FieldsInterface::getNode()}. - */ - public function getNodeHex(): string - { - return $this->fields->getNode()->toString(); - } - /** * @deprecated This has moved to {@see Rfc4122FieldsInterface::getUrn()} and * is available on {@see \Ramsey\Uuid\Rfc4122\UuidV1}, diff --git a/src/Lazy/LazyUuidFromString.php b/src/Lazy/LazyUuidFromString.php index 92f724b..f5fa150 100644 --- a/src/Lazy/LazyUuidFromString.php +++ b/src/Lazy/LazyUuidFromString.php @@ -154,13 +154,6 @@ final class LazyUuidFromString implements UuidInterface ->getDateTime(); } - /** @psalm-suppress DeprecatedMethod */ - public function getNodeHex(): string - { - return ($this->unwrapped ?? $this->unwrap()) - ->getNodeHex(); - } - /** @psalm-suppress DeprecatedMethod */ public function getUrn(): string { @@ -315,30 +308,6 @@ final class LazyUuidFromString implements UuidInterface ); } - /** - * @deprecated Use {@see UuidInterface::getFields()} to get a - * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} - * instance, you may call {@see Rfc4122FieldsInterface::getNode()} - * and use the arbitrary-precision math library of your choice to - * convert it to a string integer. - * - * @psalm-suppress UndefinedInterfaceMethod - * @psalm-suppress DeprecatedMethod - * @psalm-suppress MixedArgument - * @psalm-suppress MixedMethodCall - */ - public function getNode(): string - { - $instance = ($this->unwrapped ?? $this->unwrap()); - - return $instance->getNumberConverter() - ->fromHex( - $instance->getFields() - ->getNode() - ->toString() - ); - } - public function toUuidV1(): UuidV1 { $instance = ($this->unwrapped ?? $this->unwrap()); diff --git a/tests/ExpectedBehaviorTest.php b/tests/ExpectedBehaviorTest.php index 1e5d91b..a798820 100644 --- a/tests/ExpectedBehaviorTest.php +++ b/tests/ExpectedBehaviorTest.php @@ -53,10 +53,6 @@ class ExpectedBehaviorTest extends TestCase $this->assertArrayHasKey('clock_seq_hi_and_reserved', $uuid->getFieldsHex()); $this->assertArrayHasKey('clock_seq_low', $uuid->getFieldsHex()); $this->assertArrayHasKey('node', $uuid->getFieldsHex()); - $this->assertIsString($uuid->getFields()->getTimeLow()->toString()); - $this->assertIsString($uuid->getFields()->getTimeMid()->toString()); - $this->assertIsString($uuid->getFields()->getTimeHiAndVersion()->toString()); - $this->assertIsString($uuid->getNodeHex()); $this->assertSame($uuid->getFieldsHex()['time_low'], $uuid->getFields()->getTimeLow()->toString()); $this->assertSame($uuid->getFieldsHex()['time_mid'], $uuid->getFields()->getTimeMid()->toString()); $this->assertSame( @@ -65,7 +61,7 @@ class ExpectedBehaviorTest extends TestCase ); $this->assertSame($uuid->getFieldsHex()['clock_seq_hi_and_reserved'], $uuid->getFields()->getClockSeqHiAndReserved()->toString()); $this->assertSame($uuid->getFieldsHex()['clock_seq_low'], $uuid->getFields()->getClockSeqLow()->toString()); - $this->assertSame($uuid->getFieldsHex()['node'], $uuid->getNodeHex()); + $this->assertSame($uuid->getFieldsHex()['node'], $uuid->getFields()->getNode()->toString()); $this->assertSame( (string) $uuid->getHex(), @@ -74,7 +70,7 @@ class ExpectedBehaviorTest extends TestCase . $uuid->getFields()->getTimeHiAndVersion()->toString() . $uuid->getFields()->getClockSeqHiAndReserved()->toString() . $uuid->getFields()->getClockSeqLow()->toString() - . $uuid->getNodeHex() + . $uuid->getFields()->getNode()->toString() ); $this->assertSame( @@ -100,7 +96,7 @@ class ExpectedBehaviorTest extends TestCase . $uuid->getFields()->getTimeHiAndVersion()->toString() . '-' . $uuid->getFields()->getClockSeqHiAndReserved()->toString() . $uuid->getFields()->getClockSeqLow()->toString() . '-' - . $uuid->getNodeHex() + . $uuid->getFields()->getNode()->toString() ); $this->assertSame( @@ -110,7 +106,7 @@ class ExpectedBehaviorTest extends TestCase . $uuid->getFields()->getTimeHiAndVersion()->toString() . '-' . $uuid->getFields()->getClockSeqHiAndReserved()->toString() . $uuid->getFields()->getClockSeqLow()->toString() . '-' - . $uuid->getNodeHex() + . $uuid->getFields()->getNode()->toString() ); $this->assertSame(2, $uuid->getVariant()); @@ -141,19 +137,7 @@ class ExpectedBehaviorTest extends TestCase $uuid = Uuid::uuid1('00000fffffff', 0xffff); $this->assertInstanceOf('DateTimeInterface', $uuid->getDateTime()); - $this->assertSame('00000fffffff', $uuid->getNodeHex()); - $this->assertSame('3fff', $uuid->getFields()->getClockSeq()->toString()); - $this->assertSame('16383', (string) $uuid->getClockSequence()); - } - - public function testUuidVersion1MethodBehavior64Bit() - { - /** @var UuidV1 $uuid */ - $uuid = Uuid::uuid1('ffffffffffff', 0xffff); - - $this->assertInstanceOf('DateTimeInterface', $uuid->getDateTime()); - $this->assertSame('ffffffffffff', $uuid->getNodeHex()); - $this->assertSame('281474976710655', (string) $uuid->getNode()); + $this->assertSame('00000fffffff', $uuid->getFields()->getNode()->toString()); $this->assertSame('3fff', $uuid->getFields()->getClockSeq()->toString()); $this->assertSame('16383', (string) $uuid->getClockSequence()); } @@ -261,7 +245,7 @@ class ExpectedBehaviorTest extends TestCase $uuid->getFields()->getClockSeqHiAndReserved()->toString() . $uuid->getFields()->getClockSeqLow()->toString(), ); - $this->assertSame($components[4], $uuid->getNodeHex()); + $this->assertSame($components[4], $uuid->getFields()->getNode()->toString()); $this->assertSame($integer, (string) $uuid->getInteger()); $this->assertSame($bytes, $uuid->getBytes()); } @@ -291,7 +275,7 @@ class ExpectedBehaviorTest extends TestCase $uuid->getFields()->getClockSeqHiAndReserved()->toString() . $uuid->getFields()->getClockSeqLow()->toString(), ); - $this->assertSame($components[4], $uuid->getNodeHex()); + $this->assertSame($components[4], $uuid->getFields()->getNode()->toString()); $this->assertSame($integer, (string) $uuid->getInteger()); $this->assertSame($bytes, $uuid->getBytes()); } @@ -321,7 +305,7 @@ class ExpectedBehaviorTest extends TestCase $uuid->getFields()->getClockSeqHiAndReserved()->toString() . $uuid->getFields()->getClockSeqLow()->toString(), ); - $this->assertSame($components[4], $uuid->getNodeHex()); + $this->assertSame($components[4], $uuid->getFields()->getNode()->toString()); $this->assertSame($integer, (string) $uuid->getInteger()); $this->assertSame($bytes, $uuid->getBytes()); } diff --git a/tests/UuidTest.php b/tests/UuidTest.php index 25c32f4..f52a03e 100644 --- a/tests/UuidTest.php +++ b/tests/UuidTest.php @@ -304,17 +304,11 @@ class UuidTest extends TestCase $this->assertSame($fields, $uuid->getFieldsHex()); } - public function testGetNode(): void - { - /** @var Uuid $uuid */ - $uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66'); - $this->assertSame('8796630719078', $uuid->getNode()); - } - public function testGetNodeHex(): void { + /** @var \Ramsey\Uuid\Rfc4122\UuidInterface $uuid */ $uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66'); - $this->assertSame('0800200c9a66', $uuid->getNodeHex()); + $this->assertSame('0800200c9a66', $uuid->getFields()->getNode()->toString()); } public function testGetTimeHiAndVersionHex(): void @@ -463,7 +457,7 @@ class UuidTest extends TestCase $this->assertSame(2, $uuid->getVariant()); $this->assertSame(1, $uuid->getVersion()); $this->assertSame('5737', $uuid->getClockSequence()); - $this->assertSame('8796630719078', $uuid->getNode()); + $this->assertSame('0800200c9a66', $uuid->getFields()->getNode()->toString()); $this->assertSame('9669-0800200c9a66', substr($uuid->toString(), 19)); } @@ -475,7 +469,7 @@ class UuidTest extends TestCase $this->assertSame(2, $uuid->getVariant()); $this->assertSame(1, $uuid->getVersion()); $this->assertSame('5737', $uuid->getClockSequence()); - $this->assertSame('8796630719078', $uuid->getNode()); + $this->assertSame('0800200c9a66', $uuid->getFields()->getNode()->toString()); $this->assertSame('9669-0800200c9a66', substr($uuid->toString(), 19)); } @@ -487,8 +481,7 @@ class UuidTest extends TestCase $this->assertInstanceOf(DateTimeInterface::class, $uuid->getDateTime()); $this->assertSame(2, $uuid->getVariant()); $this->assertSame(1, $uuid->getVersion()); - $this->assertSame('00007160355e', $uuid->getNodeHex()); - $this->assertSame('1902130526', $uuid->getNode()); + $this->assertSame('00007160355e', $uuid->getFields()->getNode()->toString()); } public function testUuid1WithHexadecimalObjectNode(): void @@ -499,8 +492,7 @@ class UuidTest extends TestCase $this->assertInstanceOf(DateTimeInterface::class, $uuid->getDateTime()); $this->assertSame(2, $uuid->getVariant()); $this->assertSame(1, $uuid->getVersion()); - $this->assertSame('00007160355e', $uuid->getNodeHex()); - $this->assertSame('1902130526', $uuid->getNode()); + $this->assertSame('00007160355e', $uuid->getFields()->getNode()->toString()); } public function testUuid1WithMixedCaseHexadecimalNode(): void @@ -511,8 +503,7 @@ class UuidTest extends TestCase $this->assertInstanceOf(DateTimeInterface::class, $uuid->getDateTime()); $this->assertSame(2, $uuid->getVariant()); $this->assertSame(1, $uuid->getVersion()); - $this->assertSame('000071b0ad5e', $uuid->getNodeHex()); - $this->assertSame('1907404126', $uuid->getNode()); + $this->assertSame('000071b0ad5e', $uuid->getFields()->getNode()->toString()); } public function testUuid1WithOutOfBoundsNode(): void @@ -573,28 +564,30 @@ class UuidTest extends TestCase $this->assertSame(2, $uuid->getVariant()); $this->assertSame(6, $uuid->getVersion()); $this->assertSame('1669', $uuid->getFields()->getClockSeq()->toString()); - $this->assertSame('0800200c9a66', $uuid->getNodeHex()); + $this->assertSame('0800200c9a66', $uuid->getFields()->getNode()->toString()); $this->assertSame('9669-0800200c9a66', substr($uuid->toString(), 19)); } public function testUuid6WithHexadecimalNode(): void { + /** @var UuidV6 $uuid */ $uuid = Uuid::uuid6(new Hexadecimal('7160355e')); $this->assertInstanceOf(DateTimeInterface::class, $uuid->getDateTime()); $this->assertSame(2, $uuid->getVariant()); $this->assertSame(6, $uuid->getVersion()); - $this->assertSame('00007160355e', $uuid->getNodeHex()); + $this->assertSame('00007160355e', $uuid->getFields()->getNode()->toString()); } public function testUuid6WithMixedCaseHexadecimalNode(): void { + /** @var UuidV6 $uuid */ $uuid = Uuid::uuid6(new Hexadecimal('71B0aD5e')); $this->assertInstanceOf(DateTimeInterface::class, $uuid->getDateTime()); $this->assertSame(2, $uuid->getVariant()); $this->assertSame(6, $uuid->getVersion()); - $this->assertSame('000071b0ad5e', $uuid->getNodeHex()); + $this->assertSame('000071b0ad5e', $uuid->getFields()->getNode()->toString()); } public function testUuid6WithOutOfBoundsNode(): void @@ -1163,7 +1156,7 @@ class UuidTest extends TestCase $fields['clock_seq_low'], $uuid->getFields()->getClockSeqLow()->toString(), ); - $this->assertSame($fields['node'], $uuid->getNodeHex()); + $this->assertSame($fields['node'], $uuid->getFields()->getNode()->toString()); $this->assertSame($urn, $uuid->getUrn()); $this->assertSame($time, $uuid->getFields()->getTimestamp()->toString()); $this->assertSame($clockSeq, $uuid->getFields()->getClockSeq()->toString()); diff --git a/tests/static-analysis/UuidIsImmutable.php b/tests/static-analysis/UuidIsImmutable.php index b53982f..54ac0b0 100644 --- a/tests/static-analysis/UuidIsImmutable.php +++ b/tests/static-analysis/UuidIsImmutable.php @@ -56,7 +56,6 @@ final class UuidIsImmutable $a->getFieldsHex(), $a->getDateTime(), $a->getInteger(), - $a->getNodeHex(), $a->getUrn(), $a->getVariant(), $a->getVersion(),