Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for PHP 8.1 #388

Merged
merged 3 commits into from
Sep 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ jobs:
- "7.3"
- "7.4"
- "8.0"
include:
- php-version: "8.1"
composer-options: "--ignore-platform-req=php"

steps:
- name: "Checkout repository"
Expand All @@ -88,6 +91,14 @@ jobs:
code-coverage:
name: "Code coverage"
runs-on: "ubuntu-latest"

strategy:
fail-fast: false
matrix:
php-version:
- "7.2"
- "8.0"

steps:
- name: "Checkout repository"
uses: "actions/checkout@v2"
Expand All @@ -114,7 +125,6 @@ jobs:
unit-tests:
name: "Unit Tests"
runs-on: "ubuntu-latest"
continue-on-error: ${{ matrix.experimental }}

strategy:
fail-fast: false
Expand All @@ -124,11 +134,8 @@ jobs:
- "7.3"
- "7.4"
- "8.0"
experimental:
- false
include:
- php-version: "8.1"
experimental: true
composer-options: "--ignore-platform-req=php"

steps:
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"ext-json": "*",
"brick/math": "^0.8 || ^0.9",
"ramsey/collection": "^1.0",
"symfony/polyfill-ctype": "^1.8"
"symfony/polyfill-ctype": "^1.8",
"symfony/polyfill-php80": "^1.14"
},
"replace": {
"rhumsaa/uuid": "self.version"
Expand Down
4 changes: 4 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ parameters:
message: '#^Call to an undefined method Ramsey\\Uuid\\Fields\\FieldsInterface::get.*$#'
count: 9
path: ./src/Lazy/LazyUuidFromString.php
-
message: '#^Result of \|\| is always false\.$#'
count: 1
path: ./src/Type/Time.php
35 changes: 34 additions & 1 deletion psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="3.18.2@19aa905f7c3c7350569999a93c40ae91ae4e1626">
<files psalm-version="4.10.0@916b098b008f6de4543892b1e0651c1c3b92cbfa">
<file src="src/Builder/DegradedUuidBuilder.php">
<DeprecatedClass occurrences="3">
<code>DegradedUuid</code>
Expand Down Expand Up @@ -48,6 +48,11 @@
<code>$timeProvider</code>
</PropertyNotSetInConstructor>
</file>
<file src="src/Fields/SerializableFieldsTrait.php">
<UnusedMethodCall occurrences="1">
<code>unserialize</code>
</UnusedMethodCall>
</file>
<file src="src/Generator/PeclUuidNameGenerator.php">
<ImpureFunctionCall occurrences="3">
<code>uuid_generate_md5</code>
Expand All @@ -62,6 +67,11 @@
<code>$this</code>
</ImpureVariable>
</file>
<file src="src/Lazy/LazyUuidFromString.php">
<UnusedMethodCall occurrences="1">
<code>unserialize</code>
</UnusedMethodCall>
</file>
<file src="src/Nonstandard/UuidBuilder.php">
<ImpureVariable occurrences="3">
<code>$this</code>
Expand Down Expand Up @@ -108,6 +118,26 @@
<code>$this</code>
</ImpureVariable>
</file>
<file src="src/Type/Decimal.php">
<UnusedMethodCall occurrences="1">
<code>unserialize</code>
</UnusedMethodCall>
</file>
<file src="src/Type/Hexadecimal.php">
<UnusedMethodCall occurrences="1">
<code>unserialize</code>
</UnusedMethodCall>
</file>
<file src="src/Type/Integer.php">
<UnusedMethodCall occurrences="1">
<code>unserialize</code>
</UnusedMethodCall>
</file>
<file src="src/Type/Time.php">
<UnusedMethodCall occurrences="1">
<code>__construct</code>
</UnusedMethodCall>
</file>
<file src="src/Uuid.php">
<ImpureMethodCall occurrences="6">
<code>getFactory</code>
Expand All @@ -117,6 +147,9 @@
<code>getFactory</code>
<code>getFactory</code>
</ImpureMethodCall>
<UnusedMethodCall occurrences="1">
<code>unserialize</code>
</UnusedMethodCall>
</file>
<file src="src/UuidFactory.php">
<ImpurePropertyFetch occurrences="7">
Expand Down
25 changes: 25 additions & 0 deletions src/Fields/SerializableFieldsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@

namespace Ramsey\Uuid\Fields;

use ValueError;

use function base64_decode;
use function sprintf;
use function strlen;

/**
Expand Down Expand Up @@ -42,6 +45,14 @@ public function serialize(): string
return $this->getBytes();
}

/**
* @return array{bytes: string}
*/
public function __serialize(): array
{
return ['bytes' => $this->getBytes()];
}

/**
* Constructs the object from a serialized string representation
*
Expand All @@ -58,4 +69,18 @@ public function unserialize($serialized): void
$this->__construct(base64_decode($serialized));
}
}

/**
* @param array{bytes: string} $data
*/
public function __unserialize(array $data): void
{
// @codeCoverageIgnoreStart
if (!isset($data['bytes'])) {
throw new ValueError(sprintf('%s(): Argument #1 ($data) is invalid', __METHOD__));
}
// @codeCoverageIgnoreEnd

$this->unserialize($data['bytes']);
}
}
28 changes: 28 additions & 0 deletions src/Lazy/LazyUuidFromString.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
use Ramsey\Uuid\Type\Integer as IntegerObject;
use Ramsey\Uuid\UuidFactory;
use Ramsey\Uuid\UuidInterface;
use ValueError;

use function assert;
use function bin2hex;
use function hex2bin;
use function sprintf;
use function str_replace;
use function substr;

Expand Down Expand Up @@ -90,6 +92,16 @@ public function serialize(): string
return $this->uuid;
}

/**
* @return array{string: string}
*
* @psalm-return array{string: non-empty-string}
*/
public function __serialize(): array
{
return ['string' => $this->uuid];
}

/**
* {@inheritDoc}
*
Expand All @@ -102,6 +114,22 @@ public function unserialize($serialized): void
$this->uuid = $serialized;
}

/**
* @param array{string: string} $data
*
* @psalm-param array{string: non-empty-string} $data
*/
public function __unserialize(array $data): void
{
// @codeCoverageIgnoreStart
if (!isset($data['string'])) {
throw new ValueError(sprintf('%s(): Argument #1 ($data) is invalid', __METHOD__));
}
// @codeCoverageIgnoreEnd

$this->unserialize($data['string']);
}

/** @psalm-suppress DeprecatedMethod */
public function getNumberConverter(): NumberConverterInterface
{
Expand Down
24 changes: 24 additions & 0 deletions src/Type/Decimal.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
namespace Ramsey\Uuid\Type;

use Ramsey\Uuid\Exception\InvalidArgumentException;
use ValueError;

use function is_numeric;
use function sprintf;

/**
* A value object representing a decimal
Expand Down Expand Up @@ -98,6 +100,14 @@ public function serialize(): string
return $this->toString();
}

/**
* @return array{string: string}
*/
public function __serialize(): array
{
return ['string' => $this->toString()];
}

/**
* Constructs the object from a serialized string representation
*
Expand All @@ -110,4 +120,18 @@ public function unserialize($serialized): void
{
$this->__construct($serialized);
}

/**
* @param array{string: string} $data
*/
public function __unserialize(array $data): void
{
// @codeCoverageIgnoreStart
if (!isset($data['string'])) {
throw new ValueError(sprintf('%s(): Argument #1 ($data) is invalid', __METHOD__));
}
// @codeCoverageIgnoreEnd

$this->unserialize($data['string']);
}
}
24 changes: 24 additions & 0 deletions src/Type/Hexadecimal.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
namespace Ramsey\Uuid\Type;

use Ramsey\Uuid\Exception\InvalidArgumentException;
use ValueError;

use function ctype_xdigit;
use function sprintf;
use function strpos;
use function strtolower;
use function substr;
Expand Down Expand Up @@ -77,6 +79,14 @@ public function serialize(): string
return $this->toString();
}

/**
* @return array{string: string}
*/
public function __serialize(): array
{
return ['string' => $this->toString()];
}

/**
* Constructs the object from a serialized string representation
*
Expand All @@ -89,4 +99,18 @@ public function unserialize($serialized): void
{
$this->__construct($serialized);
}

/**
* @param array{string: string} $data
*/
public function __unserialize(array $data): void
{
// @codeCoverageIgnoreStart
if (!isset($data['string'])) {
throw new ValueError(sprintf('%s(): Argument #1 ($data) is invalid', __METHOD__));
}
// @codeCoverageIgnoreEnd

$this->unserialize($data['string']);
}
}
24 changes: 24 additions & 0 deletions src/Type/Integer.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
namespace Ramsey\Uuid\Type;

use Ramsey\Uuid\Exception\InvalidArgumentException;
use ValueError;

use function ctype_digit;
use function ltrim;
use function sprintf;
use function strpos;
use function substr;

Expand Down Expand Up @@ -114,6 +116,14 @@ public function serialize(): string
return $this->toString();
}

/**
* @return array{string: string}
*/
public function __serialize(): array
{
return ['string' => $this->toString()];
}

/**
* Constructs the object from a serialized string representation
*
Expand All @@ -126,4 +136,18 @@ public function unserialize($serialized): void
{
$this->__construct($serialized);
}

/**
* @param array{string: string} $data
*/
public function __unserialize(array $data): void
{
// @codeCoverageIgnoreStart
if (!isset($data['string'])) {
throw new ValueError(sprintf('%s(): Argument #1 ($data) is invalid', __METHOD__));
}
// @codeCoverageIgnoreEnd

$this->unserialize($data['string']);
}
}
Loading