diff --git a/CHANGELOG.md b/CHANGELOG.md index 3893d89..6e1488e 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()` + * `getTimeHiAndVersion()` + * `getTimeHiAndVersionHex()` * Remove dependency on ramsey/collection package. diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 8b57bf0..f4c391c 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: 9 + count: 8 path: ./src/Lazy/LazyUuidFromString.php - message: '#^Result of \|\| is always false\.$#' diff --git a/src/DeprecatedUuidInterface.php b/src/DeprecatedUuidInterface.php index 49d2a4b..1820029 100644 --- a/src/DeprecatedUuidInterface.php +++ b/src/DeprecatedUuidInterface.php @@ -53,14 +53,6 @@ interface DeprecatedUuidInterface */ public function getNodeHex(): string; - /** - * @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::getTimeHiAndVersion()}. - */ - public function getTimeHiAndVersionHex(): 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 0946476..8e16b35 100644 --- a/src/DeprecatedUuidMethodsTrait.php +++ b/src/DeprecatedUuidMethodsTrait.php @@ -164,28 +164,6 @@ trait DeprecatedUuidMethodsTrait return $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::getTimeHiAndVersion()} - * and use the arbitrary-precision math library of your choice to - * convert it to a string integer. - */ - public function getTimeHiAndVersion(): string - { - return $this->numberConverter->fromHex($this->fields->getTimeHiAndVersion()->toString()); - } - - /** - * @deprecated Use {@see UuidInterface::getFields()} to get a - * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} - * instance, you may call {@see Rfc4122FieldsInterface::getTimeHiAndVersion()}. - */ - public function getTimeHiAndVersionHex(): string - { - return $this->fields->getTimeHiAndVersion()->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 b884188..aeda1bc 100644 --- a/src/Lazy/LazyUuidFromString.php +++ b/src/Lazy/LazyUuidFromString.php @@ -162,13 +162,6 @@ final class LazyUuidFromString implements UuidInterface ->getNodeHex(); } - /** @psalm-suppress DeprecatedMethod */ - public function getTimeHiAndVersionHex(): string - { - return ($this->unwrapped ?? $this->unwrap()) - ->getTimeHiAndVersionHex(); - } - /** @psalm-suppress DeprecatedMethod */ public function getTimeLowHex(): string { @@ -368,30 +361,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::getTimeHiAndVersion()} - * 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 getTimeHiAndVersion(): string - { - $instance = ($this->unwrapped ?? $this->unwrap()); - - return $instance->getNumberConverter() - ->fromHex( - $instance->getFields() - ->getTimeHiAndVersion() - ->toString() - ); - } - /** * @deprecated Use {@see UuidInterface::getFields()} to get a * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} diff --git a/tests/ExpectedBehaviorTest.php b/tests/ExpectedBehaviorTest.php index ee98b47..9999277 100644 --- a/tests/ExpectedBehaviorTest.php +++ b/tests/ExpectedBehaviorTest.php @@ -55,11 +55,14 @@ class ExpectedBehaviorTest extends TestCase $this->assertArrayHasKey('node', $uuid->getFieldsHex()); $this->assertIsString($uuid->getTimeLowHex()); $this->assertIsString($uuid->getTimeMidHex()); - $this->assertIsString($uuid->getTimeHiAndVersionHex()); + $this->assertIsString($uuid->getFields()->getTimeHiAndVersion()->toString()); $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()['time_hi_and_version'], + $uuid->getFields()->getTimeHiAndVersion()->toString(), + ); $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()); @@ -68,7 +71,7 @@ class ExpectedBehaviorTest extends TestCase (string) $uuid->getHex(), $uuid->getTimeLowHex() . $uuid->getTimeMidHex() - . $uuid->getTimeHiAndVersionHex() + . $uuid->getFields()->getTimeHiAndVersion()->toString() . $uuid->getFields()->getClockSeqHiAndReserved()->toString() . $uuid->getFields()->getClockSeqLow()->toString() . $uuid->getNodeHex() @@ -94,7 +97,7 @@ class ExpectedBehaviorTest extends TestCase $uuid->toString(), $uuid->getTimeLowHex() . '-' . $uuid->getTimeMidHex() . '-' - . $uuid->getTimeHiAndVersionHex() . '-' + . $uuid->getFields()->getTimeHiAndVersion()->toString() . '-' . $uuid->getFields()->getClockSeqHiAndReserved()->toString() . $uuid->getFields()->getClockSeqLow()->toString() . '-' . $uuid->getNodeHex() @@ -104,7 +107,7 @@ class ExpectedBehaviorTest extends TestCase (string) $uuid, $uuid->getTimeLowHex() . '-' . $uuid->getTimeMidHex() . '-' - . $uuid->getTimeHiAndVersionHex() . '-' + . $uuid->getFields()->getTimeHiAndVersion()->toString() . '-' . $uuid->getFields()->getClockSeqHiAndReserved()->toString() . $uuid->getFields()->getClockSeqLow()->toString() . '-' . $uuid->getNodeHex() @@ -253,7 +256,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[2], $uuid->getFields()->getTimeHiAndVersion()->toString()); $this->assertSame( $components[3], $uuid->getFields()->getClockSeqHiAndReserved()->toString() @@ -283,7 +286,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[2], $uuid->getFields()->getTimeHiAndVersion()->toString()); $this->assertSame( $components[3], $uuid->getFields()->getClockSeqHiAndReserved()->toString() @@ -313,7 +316,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[2], $uuid->getFields()->getTimeHiAndVersion()->toString()); $this->assertSame( $components[3], $uuid->getFields()->getClockSeqHiAndReserved()->toString() diff --git a/tests/UuidTest.php b/tests/UuidTest.php index 21dec03..83934ee 100644 --- a/tests/UuidTest.php +++ b/tests/UuidTest.php @@ -317,17 +317,11 @@ class UuidTest extends TestCase $this->assertSame('0800200c9a66', $uuid->getNodeHex()); } - public function testGetTimeHiAndVersion(): void - { - /** @var Uuid $uuid */ - $uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66'); - $this->assertSame('4577', $uuid->getTimeHiAndVersion()); - } - public function testGetTimeHiAndVersionHex(): void { + /** @var \Ramsey\Uuid\Rfc4122\UuidInterface $uuid */ $uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66'); - $this->assertSame('11e1', $uuid->getTimeHiAndVersionHex()); + $this->assertSame('11e1', $uuid->getFields()->getTimeHiAndVersion()->toString()); } public function testGetTimeLow(): void @@ -927,30 +921,36 @@ class UuidTest extends TestCase // For usec = 277885 Uuid::setFactory(new UuidFactory($featureSet)); + + /** @var \Ramsey\Uuid\Rfc4122\UuidInterface $uuidA */ $uuidA = Uuid::uuid1(0x00007ffffffe, 0x1669); $this->assertSame('c4dbe7e2-097f-11e2-9669-00007ffffffe', (string) $uuidA); $this->assertSame('c4dbe7e2', $uuidA->getTimeLowHex()); $this->assertSame('097f', $uuidA->getTimeMidHex()); - $this->assertSame('11e2', $uuidA->getTimeHiAndVersionHex()); + $this->assertSame('11e2', $uuidA->getFields()->getTimeHiAndVersion()->toString()); // For usec = 0 $timeOfDay->setUsec(0); + + /** @var \Ramsey\Uuid\Rfc4122\UuidInterface $uuidB */ $uuidB = Uuid::uuid1(0x00007ffffffe, 0x1669); $this->assertSame('c4b18100-097f-11e2-9669-00007ffffffe', (string) $uuidB); $this->assertSame('c4b18100', $uuidB->getTimeLowHex()); $this->assertSame('097f', $uuidB->getTimeMidHex()); - $this->assertSame('11e2', $uuidB->getTimeHiAndVersionHex()); + $this->assertSame('11e2', $uuidB->getFields()->getTimeHiAndVersion()->toString()); // For usec = 999999 $timeOfDay->setUsec(999999); + + /** @var \Ramsey\Uuid\Rfc4122\UuidInterface $uuidC */ $uuidC = Uuid::uuid1(0x00007ffffffe, 0x1669); $this->assertSame('c54a1776-097f-11e2-9669-00007ffffffe', (string) $uuidC); $this->assertSame('c54a1776', $uuidC->getTimeLowHex()); $this->assertSame('097f', $uuidC->getTimeMidHex()); - $this->assertSame('11e2', $uuidC->getTimeHiAndVersionHex()); + $this->assertSame('11e2', $uuidC->getFields()->getTimeHiAndVersion()->toString()); } public function testCalculateUuidTimeUpperLowerBounds(): void @@ -962,12 +962,14 @@ class UuidTest extends TestCase $featureSet->setTimeProvider($timeOfDay); Uuid::setFactory(new UuidFactory($featureSet)); + + /** @var \Ramsey\Uuid\Rfc4122\UuidInterface $uuidA */ $uuidA = Uuid::uuid1(0x00007ffffffe, 0x1669); $this->assertSame('ff9785f6-ffff-1fff-9669-00007ffffffe', (string) $uuidA); $this->assertSame('ff9785f6', $uuidA->getTimeLowHex()); $this->assertSame('ffff', $uuidA->getTimeMidHex()); - $this->assertSame('1fff', $uuidA->getTimeHiAndVersionHex()); + $this->assertSame('1fff', $uuidA->getFields()->getTimeHiAndVersion()->toString()); // 1582-10-15T00:00:00+00:00 $timeOfDay = new FixedTimeProvider(new Time('-12219292800', '0')); @@ -975,12 +977,14 @@ class UuidTest extends TestCase $featureSet->setTimeProvider($timeOfDay); Uuid::setFactory(new UuidFactory($featureSet)); + + /** @var \Ramsey\Uuid\Rfc4122\UuidInterface $uuidB */ $uuidB = Uuid::uuid1(0x00007ffffffe, 0x1669); $this->assertSame('00000000-0000-1000-9669-00007ffffffe', (string) $uuidB); $this->assertSame('00000000', $uuidB->getTimeLowHex()); $this->assertSame('0000', $uuidB->getTimeMidHex()); - $this->assertSame('1000', $uuidB->getTimeHiAndVersionHex()); + $this->assertSame('1000', $uuidB->getFields()->getTimeHiAndVersion()->toString()); } /** @@ -1185,7 +1189,7 @@ class UuidTest extends TestCase $this->assertSame($fields, $uuid->getFieldsHex()); $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['time_hi_and_version'], $uuid->getFields()->getTimeHiAndVersion()->toString()); $this->assertSame( $fields['clock_seq_hi_and_reserved'], $uuid->getFields()->getClockSeqHiAndReserved()->toString(), diff --git a/tests/static-analysis/UuidIsImmutable.php b/tests/static-analysis/UuidIsImmutable.php index 80d2f24..4717d15 100644 --- a/tests/static-analysis/UuidIsImmutable.php +++ b/tests/static-analysis/UuidIsImmutable.php @@ -57,7 +57,6 @@ final class UuidIsImmutable $a->getDateTime(), $a->getInteger(), $a->getNodeHex(), - $a->getTimeHiAndVersionHex(), $a->getTimeLowHex(), $a->getTimeMidHex(), $a->getTimestampHex(),