Skip to content

Commit 73099af

Browse files
authored
feature #6 Add support for PHP 8.4 (sstok)
This PR was merged into the 1.0-dev branch. Discussion ---------- | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Fixed tickets | | License | MIT No functional changes, but implicit `null` arguments are deprecated. Commits ------- 82d76b6 Add support for PHP 8.4
2 parents bdbe7f1 + 82d76b6 commit 73099af

10 files changed

+29
-23
lines changed

.github/workflows/ci.yaml

+7-6
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ jobs:
6060
strategy:
6161
matrix:
6262
php-version:
63-
- '8.2'
63+
- '8.3'
6464

6565
steps:
6666
-
@@ -103,20 +103,21 @@ jobs:
103103
strategy:
104104
matrix:
105105
include:
106-
-
107-
php-version: '8.2'
108-
composer-options: '--prefer-stable'
109-
symfony-version: '6.3'
110106
-
111107
php-version: '8.2'
112108
composer-options: '--prefer-stable'
113109
symfony-version: '^6.4'
114110

115111
-
116-
php-version: '8.2'
112+
php-version: '8.3'
117113
composer-options: '--prefer-stable'
118114
symfony-version: '^7.0'
119115

116+
-
117+
php-version: '8.4'
118+
composer-options: '--prefer-stable'
119+
symfony-version: '^7.2'
120+
120121
steps:
121122
-
122123
name: 'Check out'

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717
"homepage": "https://rollerworks.github.io",
1818
"require": {
1919
"php": ">=8.2",
20-
"paragonie/constant_time_encoding": "^2.6",
20+
"paragonie/constant_time_encoding": "^2.6 || ^3.0",
2121
"paragonie/hidden-string": "^2.0",
2222
"psr/clock": "^1.0"
2323
},
2424
"require-dev": {
2525
"doctrine/instantiator": "^2.0",
2626
"phpunit/phpunit": "^10.4",
2727
"rollerscapes/standards": "^1.0",
28-
"symfony/clock": "^6.3"
28+
"symfony/clock": "^6.3 || ^7.2"
2929
},
3030
"minimum-stability": "dev",
3131
"prefer-stable": true,

src/AbstractSplitTokenFactory.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ abstract class AbstractSplitTokenFactory implements SplitTokenFactory
1818
private ?\DateInterval $defaultLifeTime = null;
1919
private ?ClockInterface $clock;
2020

21-
public function __construct(\DateInterval | string $defaultLifeTime = null)
21+
public function __construct(\DateInterval | string | null $defaultLifeTime = null)
2222
{
2323
if (\is_string($defaultLifeTime)) {
2424
$defaultLifeTime = new \DateInterval($defaultLifeTime);
@@ -33,7 +33,7 @@ public function setClock(ClockInterface $clock): void
3333
$this->clock = $clock;
3434
}
3535

36-
final protected function getExpirationTimestamp(\DateTimeImmutable | \DateInterval $expiration = null): ?\DateTimeImmutable
36+
final protected function getExpirationTimestamp(\DateTimeImmutable | \DateInterval | null $expiration = null): ?\DateTimeImmutable
3737
{
3838
if ($expiration instanceof \DateTimeImmutable) {
3939
return $expiration;

src/Argon2SplitTokenFactory.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424
final class Argon2SplitTokenFactory extends AbstractSplitTokenFactory
2525
{
2626
/** @param array<string, int> $config */
27-
public function __construct(private array $config = [], \DateInterval | string $defaultLifeTime = null)
27+
public function __construct(private array $config = [], \DateInterval | string | null $defaultLifeTime = null)
2828
{
2929
parent::__construct($defaultLifeTime);
3030
}
3131

32-
public function generate(\DateTimeImmutable | \DateInterval $expiresAt = null): SplitToken
32+
public function generate(\DateTimeImmutable | \DateInterval | null $expiresAt = null): SplitToken
3333
{
3434
$splitToken = Argon2SplitToken::create(
3535
// DO NOT ENCODE HERE (always provide as raw binary)!

src/FakeSplitTokenFactory.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ public static function randomInstance(): self
3030
return new self(random_bytes(FakeSplitToken::TOKEN_DATA_LENGTH));
3131
}
3232

33-
public function __construct(string $randomValue = null, \DateInterval | string $defaultLifeTime = null)
33+
public function __construct(?string $randomValue = null, \DateInterval | string | null $defaultLifeTime = null)
3434
{
3535
parent::__construct($defaultLifeTime);
3636

3737
$this->randomValue = $randomValue ?? ((string) hex2bin('d7351e5d4bebe0b2b298034107f6cb12a88fe463ebf8f85afce47a38e9d5d68f15cbfad6843a3128d22d'));
3838
}
3939

40-
public function generate(\DateTimeImmutable | \DateInterval $expiresAt = null): SplitToken
40+
public function generate(\DateTimeImmutable | \DateInterval | null $expiresAt = null): SplitToken
4141
{
4242
return FakeSplitToken::create(new HiddenString($this->randomValue, false, true))
4343
->expireAt($this->getExpirationTimestamp($expiresAt));

src/SplitToken.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public static function create(HiddenString $randomBytes, array $config = []): st
119119

120120
if (Binary::safeStrlen($bytesString) !== self::TOKEN_DATA_LENGTH) {
121121
// Don't zero memory as the value is invalid.
122-
throw new \RuntimeException(sprintf('Invalid token-data provided, expected exactly %s bytes.', self::TOKEN_DATA_LENGTH));
122+
throw new \RuntimeException(\sprintf('Invalid token-data provided, expected exactly %s bytes.', self::TOKEN_DATA_LENGTH));
123123
}
124124

125125
$selector = Base64UrlSafe::encode(Binary::safeSubstr($bytesString, 0, self::SELECTOR_BYTES));
@@ -137,7 +137,7 @@ public static function create(HiddenString $randomBytes, array $config = []): st
137137
return $instance;
138138
}
139139

140-
public function expireAt(\DateTimeImmutable $expiresAt = null): static
140+
public function expireAt(?\DateTimeImmutable $expiresAt = null): static
141141
{
142142
$instance = clone $this;
143143
$instance->expiresAt = $expiresAt;

src/SplitTokenFactory.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function setClock(ClockInterface $clock): void;
3434
*
3535
* @see HiddenString
3636
*/
37-
public function generate(\DateTimeImmutable | \DateInterval $expiresAt = null): SplitToken;
37+
public function generate(\DateTimeImmutable | \DateInterval | null $expiresAt = null): SplitToken;
3838

3939
/**
4040
* Recreates a SplitToken object from a token-string

src/SplitTokenValueHolder.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ final class SplitTokenValueHolder
3131
private ?string $verifierHash = null;
3232
private ?\DateTimeImmutable $expiresAt = null;
3333
/** @var array<string, scalar> */
34-
private array $metadata = [];
34+
private ?array $metadata = [];
3535

3636
/** @param array<string, scalar> $metadata */
37-
public function __construct(string $selector, string $verifierHash, \DateTimeImmutable $expiresAt = null, array $metadata = [])
37+
public function __construct(string $selector, string $verifierHash, ?\DateTimeImmutable $expiresAt = null, array $metadata = [])
3838
{
3939
$this->selector = $selector;
4040
$this->verifierHash = $verifierHash;
@@ -100,7 +100,7 @@ public function metadata(): array
100100
return $this->metadata ?? [];
101101
}
102102

103-
public function isExpired(\DateTimeImmutable $now = null): bool
103+
public function isExpired(?\DateTimeImmutable $now = null): bool
104104
{
105105
if ($this->expiresAt === null) {
106106
return false;

tests/Argon2SplitTokenFactoryTest.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ public function it_creates_from_stringable_object(): void
9393
$splitToken = $factory->generate();
9494

9595
$stringObj = new class($splitToken->token()->getString()) implements \Stringable {
96-
public function __construct(private string $value) {}
96+
public function __construct(private string $value)
97+
{
98+
}
9799

98100
public function __toString(): string
99101
{

tests/FakeSplitTokenFactoryTest.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
99
*/
1010

11+
namespace Rollerworks\Component\SplitToken\Tests;
12+
1113
use PHPUnit\Framework\Attributes\Test;
1214
use PHPUnit\Framework\TestCase;
1315
use Rollerworks\Component\SplitToken\FakeSplitTokenFactory;
@@ -120,8 +122,9 @@ public function it_creates_from_stringable_object(): void
120122
$stringObj = new class($splitToken->token()->getString()) implements \Stringable {
121123
public function __construct(
122124
#[\SensitiveParameter]
123-
private string $value
124-
) {}
125+
private string $value,
126+
) {
127+
}
125128

126129
public function __toString(): string
127130
{

0 commit comments

Comments
 (0)