Add support for PHP 8.1

This commit is contained in:
Graham Campbell
2021-09-05 12:41:13 +01:00
parent fe665a03df
commit 0997de99a2
11 changed files with 203 additions and 6 deletions
+1 -4
View File
@@ -66,6 +66,7 @@ jobs:
- "7.3"
- "7.4"
- "8.0"
- "8.1"
steps:
- name: "Checkout repository"
@@ -114,7 +115,6 @@ jobs:
unit-tests:
name: "Unit Tests"
runs-on: "ubuntu-latest"
continue-on-error: ${{ matrix.experimental }}
strategy:
fail-fast: false
@@ -124,11 +124,8 @@ jobs:
- "7.3"
- "7.4"
- "8.0"
experimental:
- false
include:
- php-version: "8.1"
experimental: true
composer-options: "--ignore-platform-req=php"
steps:
+2 -1
View File
@@ -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"
+4
View File
@@ -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
+34 -1
View File
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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">
+23
View File
@@ -14,7 +14,10 @@ declare(strict_types=1);
namespace Ramsey\Uuid\Fields;
use ValueError;
use function base64_decode;
use function sprintf;
use function strlen;
/**
@@ -42,6 +45,14 @@ trait SerializableFieldsTrait
return $this->getBytes();
}
/**
* @return array{bytes: string}
*/
public function __serialize(): array
{
return ['bytes' => $this->getBytes()];
}
/**
* Constructs the object from a serialized string representation
*
@@ -58,4 +69,16 @@ trait SerializableFieldsTrait
$this->__construct(base64_decode($serialized));
}
}
/**
* @param array{bytes: string} $data
*/
public function __unserialize(array $data): void
{
if (!isset($data['bytes'])) {
throw new ValueError(sprintf('%s(): Argument #1 ($data) is invalid', __METHOD__));
}
$this->unserialize($data['bytes']);
}
}
+26
View File
@@ -24,10 +24,12 @@ use Ramsey\Uuid\Type\Hexadecimal;
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;
@@ -90,6 +92,16 @@ final class LazyUuidFromString implements UuidInterface
return $this->uuid;
}
/**
* @return array{string: string}
*
* @psalm-return array{string: non-empty-string}
*/
public function __serialize(): array
{
return ['string' => $this->uuid];
}
/**
* {@inheritDoc}
*
@@ -102,6 +114,20 @@ final class LazyUuidFromString implements UuidInterface
$this->uuid = $serialized;
}
/**
* @param array{string: string} $data
*
* @psalm-param array{string: non-empty-string} $data
*/
public function __unserialize(array $data): void
{
if (!isset($data['string'])) {
throw new ValueError(sprintf('%s(): Argument #1 ($data) is invalid', __METHOD__));
}
$this->unserialize($data['string']);
}
/** @psalm-suppress DeprecatedMethod */
public function getNumberConverter(): NumberConverterInterface
{
+22
View File
@@ -15,8 +15,10 @@ declare(strict_types=1);
namespace Ramsey\Uuid\Type;
use Ramsey\Uuid\Exception\InvalidArgumentException;
use ValueError;
use function is_numeric;
use function sprintf;
/**
* A value object representing a decimal
@@ -98,6 +100,14 @@ final class Decimal implements NumberInterface
return $this->toString();
}
/**
* @return array{string: string}
*/
public function __serialize(): array
{
return ['string' => $this->toString()];
}
/**
* Constructs the object from a serialized string representation
*
@@ -110,4 +120,16 @@ final class Decimal implements NumberInterface
{
$this->__construct($serialized);
}
/**
* @param array{string: string} $data
*/
public function __unserialize(array $data): void
{
if (!isset($data['string'])) {
throw new ValueError(sprintf('%s(): Argument #1 ($data) is invalid', __METHOD__));
}
$this->unserialize($data['string']);
}
}
+22
View File
@@ -15,8 +15,10 @@ declare(strict_types=1);
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;
@@ -77,6 +79,14 @@ final class Hexadecimal implements TypeInterface
return $this->toString();
}
/**
* @return array{string: string}
*/
public function __serialize(): array
{
return ['string' => $this->toString()];
}
/**
* Constructs the object from a serialized string representation
*
@@ -89,4 +99,16 @@ final class Hexadecimal implements TypeInterface
{
$this->__construct($serialized);
}
/**
* @param array{string: string} $data
*/
public function __unserialize(array $data): void
{
if (!isset($data['string'])) {
throw new ValueError(sprintf('%s(): Argument #1 ($data) is invalid', __METHOD__));
}
$this->unserialize($data['string']);
}
}
+22
View File
@@ -15,9 +15,11 @@ declare(strict_types=1);
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;
@@ -114,6 +116,14 @@ final class Integer implements NumberInterface
return $this->toString();
}
/**
* @return array{string: string}
*/
public function __serialize(): array
{
return ['string' => $this->toString()];
}
/**
* Constructs the object from a serialized string representation
*
@@ -126,4 +136,16 @@ final class Integer implements NumberInterface
{
$this->__construct($serialized);
}
/**
* @param array{string: string} $data
*/
public function __unserialize(array $data): void
{
if (!isset($data['string'])) {
throw new ValueError(sprintf('%s(): Argument #1 ($data) is invalid', __METHOD__));
}
$this->unserialize($data['string']);
}
}
+25
View File
@@ -16,10 +16,12 @@ namespace Ramsey\Uuid\Type;
use Ramsey\Uuid\Exception\UnsupportedOperationException;
use Ramsey\Uuid\Type\Integer as IntegerObject;
use ValueError;
use stdClass;
use function json_decode;
use function json_encode;
use function sprintf;
/**
* A value object representing a timestamp
@@ -88,6 +90,17 @@ final class Time implements TypeInterface
return (string) json_encode($this);
}
/**
* @return array{seconds: string, microseconds: string}
*/
public function __serialize(): array
{
return [
'seconds' => $this->getSeconds()->toString(),
'microseconds' => $this->getMicroseconds()->toString(),
];
}
/**
* Constructs the object from a serialized string representation
*
@@ -109,4 +122,16 @@ final class Time implements TypeInterface
$this->__construct($time->seconds, $time->microseconds);
}
/**
* @param array{seconds: string, microseconds: string} $data
*/
public function __unserialize(array $data): void
{
if (!isset($data['seconds']) || !isset($data['microseconds'])) {
throw new ValueError(sprintf('%s(): Argument #1 ($data) is invalid', __METHOD__));
}
$this->__construct($data['seconds'], $data['microseconds']);
}
}
+22
View File
@@ -23,10 +23,12 @@ use Ramsey\Uuid\Lazy\LazyUuidFromString;
use Ramsey\Uuid\Rfc4122\FieldsInterface as Rfc4122FieldsInterface;
use Ramsey\Uuid\Type\Hexadecimal;
use Ramsey\Uuid\Type\Integer as IntegerObject;
use ValueError;
use function assert;
use function bin2hex;
use function preg_match;
use function sprintf;
use function str_replace;
use function strcmp;
use function strlen;
@@ -289,6 +291,14 @@ class Uuid implements UuidInterface
return $this->getFields()->getBytes();
}
/**
* @return array{bytes: string}
*/
public function __serialize(): array
{
return ['bytes' => $this->serialize()];
}
/**
* Re-constructs the object from its serialized form
*
@@ -313,6 +323,18 @@ class Uuid implements UuidInterface
$this->timeConverter = $uuid->timeConverter;
}
/**
* @param array{bytes: string} $data
*/
public function __unserialize(array $data): void
{
if (!isset($data['bytes'])) {
throw new ValueError(sprintf('%s(): Argument #1 ($data) is invalid', __METHOD__));
}
$this->unserialize($data['bytes']);
}
public function compareTo(UuidInterface $other): int
{
$compare = strcmp($this->toString(), $other->toString());