Skip to content

Commit

Permalink
Merge branch '4.x' into 5.x
Browse files Browse the repository at this point in the history
  • Loading branch information
ramsey committed Apr 15, 2023
2 parents 5f5aadc + 60a4c63 commit d04a1b4
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/merge-dependabot-upgrades.yml
Expand Up @@ -17,7 +17,7 @@ jobs:
steps:
- name: Auto-Merge
if: ${{ github.event.workflow_run.conclusion == 'success' }}
uses: ridedott/merge-me-action@v2.10.42
uses: ridedott/merge-me-action@v2.10.44
with:
# This must be used as GitHub Actions token does not support pushing
# to protected branches.
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Expand Up @@ -72,6 +72,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
* Remove dependency on ramsey/collection package.


## 4.7.4 - 2023-04-15

### Fixed

* Allow brick/math version `^0.11`.
* Add explicit `Stringable` interface to `UuidInterface`.
* Fix namespace conflict reported in [#490](https://github.com/ramsey/uuid/issues/490).
* Fix unserialize error with `OrderedTimeCodec` reported in
[#494](https://github.com/ramsey/uuid/issues/494).


## 4.7.3 - 2023-01-12

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -11,7 +11,7 @@
"require": {
"php": "^8.1",
"ext-json": "*",
"brick/math": "^0.8.8 || ^0.9 || ^0.10"
"brick/math": "^0.8.8 || ^0.9 || ^0.10 || ^0.11"
},
"require-dev": {
"captainhook/captainhook": "^5.10",
Expand Down
19 changes: 9 additions & 10 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Nonstandard/UuidV6.php
Expand Up @@ -25,7 +25,7 @@
use Ramsey\Uuid\Rfc4122\UuidV1;
use Ramsey\Uuid\Rfc4122\Version;
use Ramsey\Uuid\TimeBasedUuidInterface;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\Uuid as BaseUuid;

/**
* Reordered time, or version 6, UUIDs include timestamp, clock sequence, and
Expand All @@ -38,7 +38,7 @@
*
* @psalm-immutable
*/
class UuidV6 extends Uuid implements UuidInterface, TimeBasedUuidInterface
class UuidV6 extends BaseUuid implements UuidInterface, TimeBasedUuidInterface
{
use TimeTrait;

Expand Down
20 changes: 10 additions & 10 deletions src/Uuid.php
Expand Up @@ -332,20 +332,20 @@ public static function setFactory(UuidFactoryInterface $factory): void
*/
public static function fromBytes(string $bytes): UuidInterface
{
if (! self::$factoryReplaced && strlen($bytes) === 16) {
if (!self::$factoryReplaced && strlen($bytes) === 16) {
$base16Uuid = bin2hex($bytes);

// Note: we are calling `fromString` internally because we don't know if the given `$bytes` is a valid UUID
return self::fromString(
substr($base16Uuid, 0, 8)
. '-'
. substr($base16Uuid, 8, 4)
. '-'
. substr($base16Uuid, 12, 4)
. '-'
. substr($base16Uuid, 16, 4)
. '-'
. substr($base16Uuid, 20, 12)
. '-'
. substr($base16Uuid, 8, 4)
. '-'
. substr($base16Uuid, 12, 4)
. '-'
. substr($base16Uuid, 16, 4)
. '-'
. substr($base16Uuid, 20, 12)
);
}

Expand All @@ -371,7 +371,7 @@ public static function fromBytes(string $bytes): UuidInterface
public static function fromString(string $uuid): UuidInterface
{
$uuid = strtolower($uuid);
if (! self::$factoryReplaced && preg_match(LazyUuidFromString::VALID_REGEX, $uuid) === 1) {
if (!self::$factoryReplaced && preg_match(LazyUuidFromString::VALID_REGEX, $uuid) === 1) {
/** @psalm-suppress DocblockTypeContradiction */
assert($uuid !== '');

Expand Down
3 changes: 2 additions & 1 deletion src/UuidInterface.php
Expand Up @@ -18,14 +18,15 @@
use Ramsey\Uuid\Fields\FieldsInterface;
use Ramsey\Uuid\Type\Hexadecimal;
use Ramsey\Uuid\Type\Integer as IntegerObject;
use Stringable;

/**
* A UUID is a universally unique identifier adhering to an agreed-upon
* representation format and standard for generation
*
* @psalm-immutable
*/
interface UuidInterface extends JsonSerializable
interface UuidInterface extends JsonSerializable, Stringable
{
/**
* @return mixed[]
Expand Down
2 changes: 1 addition & 1 deletion src/functions.php
Expand Up @@ -152,7 +152,7 @@ function v7(?DateTimeInterface $dateTime = null): string
* field, and bits 64 and 65 will be replaced with the UUID variant. You
* MUST NOT rely on these bits for your application needs.
*
* @return non-empty-string Version 7 UUID as a string
* @return non-empty-string Version 8 UUID as a string
*/
function v8(string $bytes): string
{
Expand Down
30 changes: 15 additions & 15 deletions tests/ExpectedBehaviorTest.php
Expand Up @@ -48,11 +48,11 @@ public function testStaticCreationMethodsAndStandardBehavior(string $method, arr
$this->assertSame(
(string) $uuid->getHex(),
$uuid->getFields()->getTimeLow()->toString()
. $uuid->getFields()->getTimeMid()->toString()
. $uuid->getFields()->getTimeHiAndVersion()->toString()
. $uuid->getFields()->getClockSeqHiAndReserved()->toString()
. $uuid->getFields()->getClockSeqLow()->toString()
. $uuid->getFields()->getNode()->toString()
. $uuid->getFields()->getTimeMid()->toString()
. $uuid->getFields()->getTimeHiAndVersion()->toString()
. $uuid->getFields()->getClockSeqHiAndReserved()->toString()
. $uuid->getFields()->getClockSeqLow()->toString()
. $uuid->getFields()->getNode()->toString()
);

$this->assertStringStartsWith('urn:uuid:', $uuid->getUrn());
Expand All @@ -63,21 +63,21 @@ public function testStaticCreationMethodsAndStandardBehavior(string $method, arr
$this->assertSame(
$uuid->toString(),
$uuid->getFields()->getTimeLow()->toString() . '-'
. $uuid->getFields()->getTimeMid()->toString() . '-'
. $uuid->getFields()->getTimeHiAndVersion()->toString() . '-'
. $uuid->getFields()->getClockSeqHiAndReserved()->toString()
. $uuid->getFields()->getClockSeqLow()->toString() . '-'
. $uuid->getFields()->getNode()->toString()
. $uuid->getFields()->getTimeMid()->toString() . '-'
. $uuid->getFields()->getTimeHiAndVersion()->toString() . '-'
. $uuid->getFields()->getClockSeqHiAndReserved()->toString()
. $uuid->getFields()->getClockSeqLow()->toString() . '-'
. $uuid->getFields()->getNode()->toString()
);

$this->assertSame(
(string) $uuid,
$uuid->getFields()->getTimeLow()->toString() . '-'
. $uuid->getFields()->getTimeMid()->toString() . '-'
. $uuid->getFields()->getTimeHiAndVersion()->toString() . '-'
. $uuid->getFields()->getClockSeqHiAndReserved()->toString()
. $uuid->getFields()->getClockSeqLow()->toString() . '-'
. $uuid->getFields()->getNode()->toString()
. $uuid->getFields()->getTimeMid()->toString() . '-'
. $uuid->getFields()->getTimeHiAndVersion()->toString() . '-'
. $uuid->getFields()->getClockSeqHiAndReserved()->toString()
. $uuid->getFields()->getClockSeqLow()->toString() . '-'
. $uuid->getFields()->getNode()->toString()
);

$this->assertSame(Variant::Rfc4122, $uuid->getFields()->getVariant());
Expand Down
9 changes: 9 additions & 0 deletions tests/UuidTest.php
Expand Up @@ -47,6 +47,7 @@
use Ramsey\Uuid\Validator\GenericValidator;
use Ramsey\Uuid\Validator\ValidatorInterface;
use Ramsey\Uuid\Variant;
use Stringable;
use stdClass;

use function base64_decode;
Expand Down Expand Up @@ -489,11 +490,19 @@ public function testToString(): void
$uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-9b21-0800200c9a66');
$this->assertSame('ff6f8cb0-c57d-11e1-9b21-0800200c9a66', $uuid->toString());
$this->assertSame('ff6f8cb0-c57d-11e1-9b21-0800200c9a66', (string) $uuid);
$this->assertSame(
'ff6f8cb0-c57d-11e1-9b21-0800200c9a66',
(static fn (Stringable $uuid) => (string) $uuid)($uuid)
);

// Check with an old date
$uuid = Uuid::fromString('0901e600-0154-1000-9b21-0800200c9a66');
$this->assertSame('0901e600-0154-1000-9b21-0800200c9a66', $uuid->toString());
$this->assertSame('0901e600-0154-1000-9b21-0800200c9a66', (string) $uuid);
$this->assertSame(
'0901e600-0154-1000-9b21-0800200c9a66',
(static fn (Stringable $uuid) => (string) $uuid)($uuid)
);
}

public function testUuid1(): void
Expand Down

0 comments on commit d04a1b4

Please sign in to comment.