From 82d76b60592e7236db25adb2686ea7ee78a68338 Mon Sep 17 00:00:00 2001 From: Sebastiaan Stok Date: Thu, 8 May 2025 20:32:55 +0200 Subject: [PATCH] Add support for PHP 8.4 --- .github/workflows/ci.yaml | 13 +++++++------ composer.json | 4 ++-- src/AbstractSplitTokenFactory.php | 4 ++-- src/Argon2SplitTokenFactory.php | 4 ++-- src/FakeSplitTokenFactory.php | 4 ++-- src/SplitToken.php | 4 ++-- src/SplitTokenFactory.php | 2 +- src/SplitTokenValueHolder.php | 6 +++--- tests/Argon2SplitTokenFactoryTest.php | 4 +++- tests/FakeSplitTokenFactoryTest.php | 7 +++++-- 10 files changed, 29 insertions(+), 23 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 861ea29..84a1f32 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -60,7 +60,7 @@ jobs: strategy: matrix: php-version: - - '8.2' + - '8.3' steps: - @@ -103,20 +103,21 @@ jobs: strategy: matrix: include: - - - php-version: '8.2' - composer-options: '--prefer-stable' - symfony-version: '6.3' - php-version: '8.2' composer-options: '--prefer-stable' symfony-version: '^6.4' - - php-version: '8.2' + php-version: '8.3' composer-options: '--prefer-stable' symfony-version: '^7.0' + - + php-version: '8.4' + composer-options: '--prefer-stable' + symfony-version: '^7.2' + steps: - name: 'Check out' diff --git a/composer.json b/composer.json index b4b5d10..954d44f 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ "homepage": "https://rollerworks.github.io", "require": { "php": ">=8.2", - "paragonie/constant_time_encoding": "^2.6", + "paragonie/constant_time_encoding": "^2.6 || ^3.0", "paragonie/hidden-string": "^2.0", "psr/clock": "^1.0" }, @@ -25,7 +25,7 @@ "doctrine/instantiator": "^2.0", "phpunit/phpunit": "^10.4", "rollerscapes/standards": "^1.0", - "symfony/clock": "^6.3" + "symfony/clock": "^6.3 || ^7.2" }, "minimum-stability": "dev", "prefer-stable": true, diff --git a/src/AbstractSplitTokenFactory.php b/src/AbstractSplitTokenFactory.php index db42fd2..45590d1 100644 --- a/src/AbstractSplitTokenFactory.php +++ b/src/AbstractSplitTokenFactory.php @@ -18,7 +18,7 @@ abstract class AbstractSplitTokenFactory implements SplitTokenFactory private ?\DateInterval $defaultLifeTime = null; private ?ClockInterface $clock; - public function __construct(\DateInterval | string $defaultLifeTime = null) + public function __construct(\DateInterval | string | null $defaultLifeTime = null) { if (\is_string($defaultLifeTime)) { $defaultLifeTime = new \DateInterval($defaultLifeTime); @@ -33,7 +33,7 @@ public function setClock(ClockInterface $clock): void $this->clock = $clock; } - final protected function getExpirationTimestamp(\DateTimeImmutable | \DateInterval $expiration = null): ?\DateTimeImmutable + final protected function getExpirationTimestamp(\DateTimeImmutable | \DateInterval | null $expiration = null): ?\DateTimeImmutable { if ($expiration instanceof \DateTimeImmutable) { return $expiration; diff --git a/src/Argon2SplitTokenFactory.php b/src/Argon2SplitTokenFactory.php index 045177f..ecdbb81 100644 --- a/src/Argon2SplitTokenFactory.php +++ b/src/Argon2SplitTokenFactory.php @@ -24,12 +24,12 @@ final class Argon2SplitTokenFactory extends AbstractSplitTokenFactory { /** @param array $config */ - public function __construct(private array $config = [], \DateInterval | string $defaultLifeTime = null) + public function __construct(private array $config = [], \DateInterval | string | null $defaultLifeTime = null) { parent::__construct($defaultLifeTime); } - public function generate(\DateTimeImmutable | \DateInterval $expiresAt = null): SplitToken + public function generate(\DateTimeImmutable | \DateInterval | null $expiresAt = null): SplitToken { $splitToken = Argon2SplitToken::create( // DO NOT ENCODE HERE (always provide as raw binary)! diff --git a/src/FakeSplitTokenFactory.php b/src/FakeSplitTokenFactory.php index e99c4d5..f57067e 100644 --- a/src/FakeSplitTokenFactory.php +++ b/src/FakeSplitTokenFactory.php @@ -30,14 +30,14 @@ public static function randomInstance(): self return new self(random_bytes(FakeSplitToken::TOKEN_DATA_LENGTH)); } - public function __construct(string $randomValue = null, \DateInterval | string $defaultLifeTime = null) + public function __construct(?string $randomValue = null, \DateInterval | string | null $defaultLifeTime = null) { parent::__construct($defaultLifeTime); $this->randomValue = $randomValue ?? ((string) hex2bin('d7351e5d4bebe0b2b298034107f6cb12a88fe463ebf8f85afce47a38e9d5d68f15cbfad6843a3128d22d')); } - public function generate(\DateTimeImmutable | \DateInterval $expiresAt = null): SplitToken + public function generate(\DateTimeImmutable | \DateInterval | null $expiresAt = null): SplitToken { return FakeSplitToken::create(new HiddenString($this->randomValue, false, true)) ->expireAt($this->getExpirationTimestamp($expiresAt)); diff --git a/src/SplitToken.php b/src/SplitToken.php index 24c22b3..fbf42d2 100644 --- a/src/SplitToken.php +++ b/src/SplitToken.php @@ -119,7 +119,7 @@ public static function create(HiddenString $randomBytes, array $config = []): st if (Binary::safeStrlen($bytesString) !== self::TOKEN_DATA_LENGTH) { // Don't zero memory as the value is invalid. - throw new \RuntimeException(sprintf('Invalid token-data provided, expected exactly %s bytes.', self::TOKEN_DATA_LENGTH)); + throw new \RuntimeException(\sprintf('Invalid token-data provided, expected exactly %s bytes.', self::TOKEN_DATA_LENGTH)); } $selector = Base64UrlSafe::encode(Binary::safeSubstr($bytesString, 0, self::SELECTOR_BYTES)); @@ -137,7 +137,7 @@ public static function create(HiddenString $randomBytes, array $config = []): st return $instance; } - public function expireAt(\DateTimeImmutable $expiresAt = null): static + public function expireAt(?\DateTimeImmutable $expiresAt = null): static { $instance = clone $this; $instance->expiresAt = $expiresAt; diff --git a/src/SplitTokenFactory.php b/src/SplitTokenFactory.php index 7c4e704..01ed723 100644 --- a/src/SplitTokenFactory.php +++ b/src/SplitTokenFactory.php @@ -34,7 +34,7 @@ public function setClock(ClockInterface $clock): void; * * @see HiddenString */ - public function generate(\DateTimeImmutable | \DateInterval $expiresAt = null): SplitToken; + public function generate(\DateTimeImmutable | \DateInterval | null $expiresAt = null): SplitToken; /** * Recreates a SplitToken object from a token-string diff --git a/src/SplitTokenValueHolder.php b/src/SplitTokenValueHolder.php index 7d73380..a21a9f2 100644 --- a/src/SplitTokenValueHolder.php +++ b/src/SplitTokenValueHolder.php @@ -31,10 +31,10 @@ final class SplitTokenValueHolder private ?string $verifierHash = null; private ?\DateTimeImmutable $expiresAt = null; /** @var array */ - private array $metadata = []; + private ?array $metadata = []; /** @param array $metadata */ - public function __construct(string $selector, string $verifierHash, \DateTimeImmutable $expiresAt = null, array $metadata = []) + public function __construct(string $selector, string $verifierHash, ?\DateTimeImmutable $expiresAt = null, array $metadata = []) { $this->selector = $selector; $this->verifierHash = $verifierHash; @@ -100,7 +100,7 @@ public function metadata(): array return $this->metadata ?? []; } - public function isExpired(\DateTimeImmutable $now = null): bool + public function isExpired(?\DateTimeImmutable $now = null): bool { if ($this->expiresAt === null) { return false; diff --git a/tests/Argon2SplitTokenFactoryTest.php b/tests/Argon2SplitTokenFactoryTest.php index cb13f6f..41050a9 100644 --- a/tests/Argon2SplitTokenFactoryTest.php +++ b/tests/Argon2SplitTokenFactoryTest.php @@ -93,7 +93,9 @@ public function it_creates_from_stringable_object(): void $splitToken = $factory->generate(); $stringObj = new class($splitToken->token()->getString()) implements \Stringable { - public function __construct(private string $value) {} + public function __construct(private string $value) + { + } public function __toString(): string { diff --git a/tests/FakeSplitTokenFactoryTest.php b/tests/FakeSplitTokenFactoryTest.php index 9695347..02a1d31 100644 --- a/tests/FakeSplitTokenFactoryTest.php +++ b/tests/FakeSplitTokenFactoryTest.php @@ -8,6 +8,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +namespace Rollerworks\Component\SplitToken\Tests; + use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Rollerworks\Component\SplitToken\FakeSplitTokenFactory; @@ -120,8 +122,9 @@ public function it_creates_from_stringable_object(): void $stringObj = new class($splitToken->token()->getString()) implements \Stringable { public function __construct( #[\SensitiveParameter] - private string $value - ) {} + private string $value, + ) { + } public function __toString(): string {