minor #36058 [Uid] make Uuid::equals
method accept any types of argument for more flexibility (hhamon)
This PR was merged into the 5.1-dev branch.
Discussion
----------
[Uid] make `Uuid::equals` method accept any types of argument for more flexibility
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | no
| Deprecations? | no
| Tickets | ~
| License | MIT
| Doc PR | ~
I suggest to weaken the `Uuid:equals` method argument type to accept any types of value to compare against. This makes one able to compare the `Uuid` instance with any values.
Commits
-------
46721c19f9
[Uid] make `Uuid::equals()` accept any types of argument for more flexibility
This commit is contained in:
commit
cc73b1eafa
@ -94,6 +94,22 @@ class UuidTest extends TestCase
|
||||
$this->assertFalse($uuid1->equals($uuid2));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideInvalidEqualType
|
||||
*/
|
||||
public function testEqualsAgainstOtherType($other)
|
||||
{
|
||||
$this->assertFalse((new Uuid(self::A_UUID_V4))->equals($other));
|
||||
}
|
||||
|
||||
public function provideInvalidEqualType()
|
||||
{
|
||||
yield [null];
|
||||
yield [self::A_UUID_V1];
|
||||
yield [self::A_UUID_V4];
|
||||
yield [new \stdClass()];
|
||||
}
|
||||
|
||||
public function testCompare()
|
||||
{
|
||||
$uuids = [];
|
||||
|
@ -48,7 +48,7 @@ class Uuid implements \JsonSerializable
|
||||
throw new \InvalidArgumentException(sprintf('Invalid UUID: "%s".', $uuid));
|
||||
}
|
||||
|
||||
$this->uuid = $uuid;
|
||||
$this->uuid = strtr($uuid, 'ABCDEF', 'abcdef');
|
||||
}
|
||||
|
||||
public static function v1(): self
|
||||
@ -91,8 +91,15 @@ class Uuid implements \JsonSerializable
|
||||
return uuid_is_null($this->uuid);
|
||||
}
|
||||
|
||||
public function equals(self $other): bool
|
||||
/**
|
||||
* Returns whether the argument is of class Uuid and contains the same value as the current instance.
|
||||
*/
|
||||
public function equals($other): bool
|
||||
{
|
||||
if (!$other instanceof self) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return 0 === uuid_compare($this->uuid, $other->uuid);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user