Remove deprecated getTimestamp*() methods

This commit is contained in:
Ben Ramsey
2022-03-27 20:05:08 -05:00
parent b0b5c12bac
commit 23d54b85cb
8 changed files with 13 additions and 109 deletions
+2
View File
@@ -34,6 +34,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
* `getTimeLowHex()`
* `getTimeMid()`
* `getTimeMidHex()`
* `getTimestamp()`
* `getTimestampHex()`
* Remove dependency on ramsey/collection package.
+1 -1
View File
@@ -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: 6
count: 4
path: ./src/Lazy/LazyUuidFromString.php
-
message: '#^Result of \|\| is always false\.$#'
-8
View File
@@ -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::getTimestamp()}.
*/
public function getTimestampHex(): 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()}.
-30
View File
@@ -164,36 +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::getTimestamp()}
* and use the arbitrary-precision math library of your choice to
* convert it to a string integer.
*/
public function getTimestamp(): string
{
if ($this->fields->getVersion() !== 1) {
throw new UnsupportedOperationException('Not a time-based UUID');
}
return $this->numberConverter->fromHex($this->fields->getTimestamp()->toString());
}
/**
* @deprecated Use {@see UuidInterface::getFields()} to get a
* {@see FieldsInterface} instance. If it is a {@see Rfc4122FieldsInterface}
* instance, you may call {@see Rfc4122FieldsInterface::getTimestamp()}.
*/
public function getTimestampHex(): string
{
if ($this->fields->getVersion() !== 1) {
throw new UnsupportedOperationException('Not a time-based UUID');
}
return $this->fields->getTimestamp()->toString();
}
/**
* @deprecated This has moved to {@see Rfc4122FieldsInterface::getUrn()} and
* is available on {@see \Ramsey\Uuid\Rfc4122\UuidV1},
-33
View File
@@ -16,7 +16,6 @@ namespace Ramsey\Uuid\Lazy;
use DateTimeInterface;
use Ramsey\Uuid\Converter\NumberConverterInterface;
use Ramsey\Uuid\Exception\UnsupportedOperationException;
use Ramsey\Uuid\Fields\FieldsInterface;
use Ramsey\Uuid\Nonstandard\UuidV6;
use Ramsey\Uuid\Rfc4122\UuidV1;
@@ -162,13 +161,6 @@ final class LazyUuidFromString implements UuidInterface
->getNodeHex();
}
/** @psalm-suppress DeprecatedMethod */
public function getTimestampHex(): string
{
return ($this->unwrapped ?? $this->unwrap())
->getTimestampHex();
}
/** @psalm-suppress DeprecatedMethod */
public function getUrn(): string
{
@@ -347,31 +339,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::getTimestamp()}
* 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 getTimestamp(): string
{
$instance = ($this->unwrapped ?? $this->unwrap());
$fields = $instance->getFields();
if ($fields->getVersion() !== 1) {
throw new UnsupportedOperationException('Not a time-based UUID');
}
return $instance->getNumberConverter()
->fromHex($fields->getTimestamp()->toString());
}
public function toUuidV1(): UuidV1
{
$instance = ($this->unwrapped ?? $this->unwrap());
-1
View File
@@ -156,7 +156,6 @@ class ExpectedBehaviorTest extends TestCase
$this->assertSame('281474976710655', (string) $uuid->getNode());
$this->assertSame('3fff', $uuid->getFields()->getClockSeq()->toString());
$this->assertSame('16383', (string) $uuid->getClockSequence());
$this->assertTrue(ctype_digit((string) $uuid->getTimestamp()));
}
/**
+10 -35
View File
@@ -338,51 +338,28 @@ class UuidTest extends TestCase
$this->assertSame('c57d', $uuid->getFields()->getTimeMid()->toString());
}
public function testGetTimestamp(): void
{
// Check for a recent date
/** @var Uuid $uuid */
$uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66');
$this->assertSame('135606608744910000', $uuid->getTimestamp());
// Check for an old date
/** @var Uuid $uuid */
$uuid = Uuid::fromString('0901e600-0154-1000-9b21-0800200c9a66');
$this->assertSame('1460440000000', $uuid->getTimestamp());
}
public function testGetTimestampHex(): void
{
// Check for a recent date
/** @var \Ramsey\Uuid\Rfc4122\UuidInterface $uuid */
$uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66');
$this->assertSame('1e1c57dff6f8cb0', $uuid->getTimestampHex());
$this->assertSame('1e1c57dff6f8cb0', $uuid->getFields()->getTimestamp()->toString());
// Check for an old date
/** @var \Ramsey\Uuid\Rfc4122\UuidInterface $uuid */
$uuid = Uuid::fromString('0901e600-0154-1000-9b21-0800200c9a66');
$this->assertSame('00001540901e600', $uuid->getTimestampHex());
}
public function testGetTimestampFromNonVersion1Uuid(): void
{
// Using a version 4 UUID to test
/** @var Uuid $uuid */
$uuid = Uuid::fromString('bf17b594-41f2-474f-bf70-4c90220f75de');
$this->expectException(UnsupportedOperationException::class);
$this->expectExceptionMessage('Not a time-based UUID');
$uuid->getTimestamp();
$this->assertSame('00001540901e600', $uuid->getFields()->getTimestamp()->toString());
}
public function testGetTimestampHexFromNonVersion1Uuid(): void
{
// Using a version 4 UUID to test
/** @var \Ramsey\Uuid\Rfc4122\UuidInterface $uuid */
$uuid = Uuid::fromString('bf17b594-41f2-474f-bf70-4c90220f75de');
$this->expectException(UnsupportedOperationException::class);
$this->expectExceptionMessage('Not a time-based UUID');
$uuid->getTimestampHex();
// This threw an exception in versions of ramsey/uuid earlier than 5.0.0.
// The test is here now to ensure we don't throw an exception.
$this->assertSame('74f41f2bf17b594', $uuid->getFields()->getTimestamp()->toString());
}
public function testGetUrn(): void
@@ -1188,9 +1165,7 @@ class UuidTest extends TestCase
);
$this->assertSame($fields['node'], $uuid->getNodeHex());
$this->assertSame($urn, $uuid->getUrn());
if ($uuid->getVersion() === 1) {
$this->assertSame($time, $uuid->getTimestampHex());
}
$this->assertSame($time, $uuid->getFields()->getTimestamp()->toString());
$this->assertSame($clockSeq, $uuid->getFields()->getClockSeq()->toString());
$this->assertSame($variant, $uuid->getVariant());
$this->assertSame($version, $uuid->getVersion());
@@ -1222,7 +1197,7 @@ class UuidTest extends TestCase
'node' => '000000000000',
],
'urn' => 'urn:uuid:00000000-0000-0000-0000-000000000000',
'time' => '0',
'time' => '000000000000000',
'clock_seq' => '0000',
'variant' => Uuid::RESERVED_NCS,
'version' => null,
@@ -57,7 +57,6 @@ final class UuidIsImmutable
$a->getDateTime(),
$a->getInteger(),
$a->getNodeHex(),
$a->getTimestampHex(),
$a->getUrn(),
$a->getVariant(),
$a->getVersion(),