From b0b5c12bac26a08efd539e832ef362338a110159 Mon Sep 17 00:00:00 2001 From: Ben Ramsey Date: Sun, 27 Mar 2022 19:45:17 -0500 Subject: [PATCH] Remove deprecated getTimeMid*() methods --- CHANGELOG.md | 2 ++ phpstan.neon.dist | 2 +- src/DeprecatedUuidInterface.php | 8 ------ src/DeprecatedUuidMethodsTrait.php | 22 ---------------- src/Lazy/LazyUuidFromString.php | 31 ----------------------- tests/ExpectedBehaviorTest.php | 16 ++++++------ tests/UuidTest.php | 22 ++++++---------- tests/static-analysis/UuidIsImmutable.php | 1 - 8 files changed, 19 insertions(+), 85 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f0e88d2..afb5669 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. * `getTimeHiAndVersionHex()` * `getTimeLow()` * `getTimeLowHex()` + * `getTimeMid()` + * `getTimeMidHex()` * Remove dependency on ramsey/collection package. diff --git a/phpstan.neon.dist b/phpstan.neon.dist index ba132b2..aec6144 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: 7 + count: 6 path: ./src/Lazy/LazyUuidFromString.php - message: '#^Result of \|\| is always false\.$#' diff --git a/src/DeprecatedUuidInterface.php b/src/DeprecatedUuidInterface.php index 90c21cf..5a1c710 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::getTimeMid()}. - */ - public function getTimeMidHex(): 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 3e02b1b..75df242 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::getTimeMid()} - * and use the arbitrary-precision math library of your choice to - * convert it to a string integer. - */ - public function getTimeMid(): string - { - return $this->numberConverter->fromHex($this->fields->getTimeMid()->toString()); - } - - /** - * @deprecated Use {@see UuidInterface::getFields()} to get a - * {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface} - * instance, you may call {@see Rfc4122FieldsInterface::getTimeMid()}. - */ - public function getTimeMidHex(): string - { - return $this->fields->getTimeMid()->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 cbf92f4..45a9733 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 getTimeMidHex(): string - { - return ($this->unwrapped ?? $this->unwrap()) - ->getTimeMidHex(); - } - /** @psalm-suppress DeprecatedMethod */ public function getTimestampHex(): string { @@ -354,30 +347,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::getTimeMid()} - * 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 getTimeMid(): string - { - $instance = ($this->unwrapped ?? $this->unwrap()); - - return $instance->getNumberConverter() - ->fromHex( - $instance->getFields() - ->getTimeMid() - ->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 0a08d0f..6ebede2 100644 --- a/tests/ExpectedBehaviorTest.php +++ b/tests/ExpectedBehaviorTest.php @@ -54,11 +54,11 @@ class ExpectedBehaviorTest extends TestCase $this->assertArrayHasKey('clock_seq_low', $uuid->getFieldsHex()); $this->assertArrayHasKey('node', $uuid->getFieldsHex()); $this->assertIsString($uuid->getFields()->getTimeLow()->toString()); - $this->assertIsString($uuid->getTimeMidHex()); + $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->getTimeMidHex()); + $this->assertSame($uuid->getFieldsHex()['time_mid'], $uuid->getFields()->getTimeMid()->toString()); $this->assertSame( $uuid->getFieldsHex()['time_hi_and_version'], $uuid->getFields()->getTimeHiAndVersion()->toString(), @@ -70,7 +70,7 @@ class ExpectedBehaviorTest extends TestCase $this->assertSame( (string) $uuid->getHex(), $uuid->getFields()->getTimeLow()->toString() - . $uuid->getTimeMidHex() + . $uuid->getFields()->getTimeMid()->toString() . $uuid->getFields()->getTimeHiAndVersion()->toString() . $uuid->getFields()->getClockSeqHiAndReserved()->toString() . $uuid->getFields()->getClockSeqLow()->toString() @@ -96,7 +96,7 @@ class ExpectedBehaviorTest extends TestCase $this->assertSame( $uuid->toString(), $uuid->getFields()->getTimeLow()->toString() . '-' - . $uuid->getTimeMidHex() . '-' + . $uuid->getFields()->getTimeMid()->toString() . '-' . $uuid->getFields()->getTimeHiAndVersion()->toString() . '-' . $uuid->getFields()->getClockSeqHiAndReserved()->toString() . $uuid->getFields()->getClockSeqLow()->toString() . '-' @@ -106,7 +106,7 @@ class ExpectedBehaviorTest extends TestCase $this->assertSame( (string) $uuid, $uuid->getFields()->getTimeLow()->toString() . '-' - . $uuid->getTimeMidHex() . '-' + . $uuid->getFields()->getTimeMid()->toString() . '-' . $uuid->getFields()->getTimeHiAndVersion()->toString() . '-' . $uuid->getFields()->getClockSeqHiAndReserved()->toString() . $uuid->getFields()->getClockSeqLow()->toString() . '-' @@ -255,7 +255,7 @@ class ExpectedBehaviorTest extends TestCase $components = explode('-', $string); $this->assertSame($components[0], $uuid->getFields()->getTimeLow()->toString()); - $this->assertSame($components[1], $uuid->getTimeMidHex()); + $this->assertSame($components[1], $uuid->getFields()->getTimeMid()->toString()); $this->assertSame($components[2], $uuid->getFields()->getTimeHiAndVersion()->toString()); $this->assertSame( $components[3], @@ -285,7 +285,7 @@ class ExpectedBehaviorTest extends TestCase $components = explode('-', $string); $this->assertSame($components[0], $uuid->getFields()->getTimeLow()->toString()); - $this->assertSame($components[1], $uuid->getTimeMidHex()); + $this->assertSame($components[1], $uuid->getFields()->getTimeMid()->toString()); $this->assertSame($components[2], $uuid->getFields()->getTimeHiAndVersion()->toString()); $this->assertSame( $components[3], @@ -315,7 +315,7 @@ class ExpectedBehaviorTest extends TestCase $components = explode('-', $string); $this->assertSame($components[0], $uuid->getFields()->getTimeLow()->toString()); - $this->assertSame($components[1], $uuid->getTimeMidHex()); + $this->assertSame($components[1], $uuid->getFields()->getTimeMid()->toString()); $this->assertSame($components[2], $uuid->getFields()->getTimeHiAndVersion()->toString()); $this->assertSame( $components[3], diff --git a/tests/UuidTest.php b/tests/UuidTest.php index a852528..518fb1d 100644 --- a/tests/UuidTest.php +++ b/tests/UuidTest.php @@ -331,17 +331,11 @@ class UuidTest extends TestCase $this->assertSame('ff6f8cb0', $uuid->getFields()->getTimeLow()->toString()); } - public function testGetTimeMid(): void - { - /** @var Uuid $uuid */ - $uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66'); - $this->assertSame('50557', $uuid->getTimeMid()); - } - public function testGetTimeMidHex(): void { + /** @var \Ramsey\Uuid\Rfc4122\UuidInterface $uuid */ $uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66'); - $this->assertSame('c57d', $uuid->getTimeMidHex()); + $this->assertSame('c57d', $uuid->getFields()->getTimeMid()->toString()); } public function testGetTimestamp(): void @@ -921,7 +915,7 @@ class UuidTest extends TestCase $this->assertSame('c4dbe7e2-097f-11e2-9669-00007ffffffe', (string) $uuidA); $this->assertSame('c4dbe7e2', $uuidA->getFields()->getTimeLow()->toString()); - $this->assertSame('097f', $uuidA->getTimeMidHex()); + $this->assertSame('097f', $uuidA->getFields()->getTimeMid()->toString()); $this->assertSame('11e2', $uuidA->getFields()->getTimeHiAndVersion()->toString()); // For usec = 0 @@ -932,7 +926,7 @@ class UuidTest extends TestCase $this->assertSame('c4b18100-097f-11e2-9669-00007ffffffe', (string) $uuidB); $this->assertSame('c4b18100', $uuidB->getFields()->getTimeLow()->toString()); - $this->assertSame('097f', $uuidB->getTimeMidHex()); + $this->assertSame('097f', $uuidB->getFields()->getTimeMid()->toString()); $this->assertSame('11e2', $uuidB->getFields()->getTimeHiAndVersion()->toString()); // For usec = 999999 @@ -943,7 +937,7 @@ class UuidTest extends TestCase $this->assertSame('c54a1776-097f-11e2-9669-00007ffffffe', (string) $uuidC); $this->assertSame('c54a1776', $uuidC->getFields()->getTimeLow()->toString()); - $this->assertSame('097f', $uuidC->getTimeMidHex()); + $this->assertSame('097f', $uuidC->getFields()->getTimeMid()->toString()); $this->assertSame('11e2', $uuidC->getFields()->getTimeHiAndVersion()->toString()); } @@ -962,7 +956,7 @@ class UuidTest extends TestCase $this->assertSame('ff9785f6-ffff-1fff-9669-00007ffffffe', (string) $uuidA); $this->assertSame('ff9785f6', $uuidA->getFields()->getTimeLow()->toString()); - $this->assertSame('ffff', $uuidA->getTimeMidHex()); + $this->assertSame('ffff', $uuidA->getFields()->getTimeMid()->toString()); $this->assertSame('1fff', $uuidA->getFields()->getTimeHiAndVersion()->toString()); // 1582-10-15T00:00:00+00:00 @@ -977,7 +971,7 @@ class UuidTest extends TestCase $this->assertSame('00000000-0000-1000-9669-00007ffffffe', (string) $uuidB); $this->assertSame('00000000', $uuidB->getFields()->getTimeLow()->toString()); - $this->assertSame('0000', $uuidB->getTimeMidHex()); + $this->assertSame('0000', $uuidB->getFields()->getTimeMid()->toString()); $this->assertSame('1000', $uuidB->getFields()->getTimeHiAndVersion()->toString()); } @@ -1182,7 +1176,7 @@ class UuidTest extends TestCase $this->assertSame($int, $uuid->getInteger()->toString()); $this->assertSame($fields, $uuid->getFieldsHex()); $this->assertSame($fields['time_low'], $uuid->getFields()->getTimeLow()->toString()); - $this->assertSame($fields['time_mid'], $uuid->getTimeMidHex()); + $this->assertSame($fields['time_mid'], $uuid->getFields()->getTimeMid()->toString()); $this->assertSame($fields['time_hi_and_version'], $uuid->getFields()->getTimeHiAndVersion()->toString()); $this->assertSame( $fields['clock_seq_hi_and_reserved'], diff --git a/tests/static-analysis/UuidIsImmutable.php b/tests/static-analysis/UuidIsImmutable.php index ae97863..6d421b5 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->getTimeMidHex(), $a->getTimestampHex(), $a->getUrn(), $a->getVariant(),