Skip to content

Commit

Permalink
Remove deprecated getClockSeqHiAndReservedHex() method
Browse files Browse the repository at this point in the history
  • Loading branch information
ramsey committed Mar 27, 2022
1 parent eebc792 commit 1d4077d
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 50 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 0 additions & 8 deletions src/DeprecatedUuidInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,6 @@ public function getNumberConverter(): NumberConverterInterface;
*/
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
Expand Down
10 changes: 0 additions & 10 deletions src/DeprecatedUuidMethodsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,6 @@ public function getClockSeqHiAndReserved(): string
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}
Expand Down
7 changes: 0 additions & 7 deletions src/Lazy/LazyUuidFromString.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,6 @@ public function getFieldsHex(): array
->getFieldsHex();
}

/** @psalm-suppress DeprecatedMethod */
public function getClockSeqHiAndReservedHex(): string
{
return ($this->unwrapped ?? $this->unwrap())
->getClockSeqHiAndReservedHex();
}

/** @psalm-suppress DeprecatedMethod */
public function getClockSeqLowHex(): string
{
Expand Down
2 changes: 2 additions & 0 deletions src/Rfc4122/UuidInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 0 additions & 2 deletions src/Rfc4122/UuidV2.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ public function getDateTime(): DateTimeInterface
*/
public function getLocalDomain(): int
{
/** @var Rfc4122FieldsInterface $fields */
$fields = $this->getFields();

return (int) hexdec($fields->getClockSeqLow()->toString());
Expand All @@ -133,7 +132,6 @@ public function getLocalDomainName(): string
*/
public function getLocalIdentifier(): IntegerObject
{
/** @var Rfc4122FieldsInterface $fields */
$fields = $this->getFields();

return new IntegerObject(
Expand Down
6 changes: 3 additions & 3 deletions src/Uuid.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
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;
Expand All @@ -40,7 +40,7 @@
*
* @psalm-immutable
*/
class Uuid implements UuidInterface
class Uuid implements Rfc4122UuidInterface
{
use DeprecatedUuidMethodsTrait;

Expand Down Expand Up @@ -369,7 +369,7 @@ public function getBytes(): string
return $this->codec->encodeBinary($this);
}

public function getFields(): FieldsInterface
public function getFields(): Rfc4122FieldsInterface
{
return $this->fields;
}
Expand Down
30 changes: 17 additions & 13 deletions tests/ExpectedBehaviorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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;
Expand All @@ -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));
Expand All @@ -54,13 +55,13 @@ public function testStaticCreationMethodsAndStandardBehavior($method, $args)
$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());
Expand All @@ -71,7 +72,7 @@ public function testStaticCreationMethodsAndStandardBehavior($method, $args)
$uuid->getTimeLowHex()
. $uuid->getTimeMidHex()
. $uuid->getTimeHiAndVersionHex()
. $uuid->getClockSeqHiAndReservedHex()
. $uuid->getFields()->getClockSeqHiAndReserved()->toString()
. $uuid->getClockSeqLowHex()
. $uuid->getNodeHex()
);
Expand All @@ -97,7 +98,7 @@ public function testStaticCreationMethodsAndStandardBehavior($method, $args)
$uuid->getTimeLowHex() . '-'
. $uuid->getTimeMidHex() . '-'
. $uuid->getTimeHiAndVersionHex() . '-'
. $uuid->getClockSeqHiAndReservedHex()
. $uuid->getFields()->getClockSeqHiAndReserved()->toString()
. $uuid->getClockSeqLowHex() . '-'
. $uuid->getNodeHex()
);
Expand All @@ -107,7 +108,7 @@ public function testStaticCreationMethodsAndStandardBehavior($method, $args)
$uuid->getTimeLowHex() . '-'
. $uuid->getTimeMidHex() . '-'
. $uuid->getTimeHiAndVersionHex() . '-'
. $uuid->getClockSeqHiAndReservedHex()
. $uuid->getFields()->getClockSeqHiAndReserved()->toString()
. $uuid->getClockSeqLowHex() . '-'
. $uuid->getNodeHex()
);
Expand Down Expand Up @@ -237,11 +238,12 @@ public function testSerialization($string)
/**
* @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());
Expand All @@ -253,7 +255,7 @@ public function testFromBytes($string, $version, $variant, $integer)
$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());
Expand All @@ -262,10 +264,11 @@ public function testFromBytes($string, $version, $variant, $integer)
/**
* @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);
Expand All @@ -278,7 +281,7 @@ public function testFromInteger($string, $version, $variant, $integer)
$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());
Expand All @@ -287,10 +290,11 @@ public function testFromInteger($string, $version, $variant, $integer)
/**
* @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);
Expand All @@ -303,7 +307,7 @@ public function testFromString($string, $version, $variant, $integer)
$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());
Expand Down
13 changes: 8 additions & 5 deletions tests/UuidTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ public function testGetClockSeqHiAndReserved(): void

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
Expand Down Expand Up @@ -1203,7 +1203,7 @@ public function testUuidPassesPythonTests(
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());
Expand All @@ -1213,7 +1213,10 @@ public function testUuidPassesPythonTests(
$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());
Expand Down Expand Up @@ -1520,7 +1523,7 @@ public function providePythonTests(): array
}

/**
* @covers Ramsey\Uuid\Uuid::jsonSerialize
* @covers \Ramsey\Uuid\Uuid::jsonSerialize
*/
public function testJsonSerialize(): void
{
Expand Down
4 changes: 2 additions & 2 deletions tests/static-analysis/UuidIsImmutable.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public static function pureGetters(UuidInterface $a): array
$a->getNumberConverter(),
$a->getHex(),
$a->getFieldsHex(),
$a->getClockSeqHiAndReservedHex(),
$a->getClockSeqLowHex(),
$a->getClockSequenceHex(),
$a->getDateTime(),
Expand All @@ -71,11 +70,12 @@ public static function pureGetters(UuidInterface $a): array
$a->getVersion(),
$a->toString(),
$a->__toString(),
$a->getFields(),
];
}

/**
* @return UuidInterface[]|bool[]
* @return array{UuidInterface, UuidInterface, bool}
*
* @psalm-pure
*/
Expand Down

0 comments on commit 1d4077d

Please sign in to comment.