Skip to content

Commit fede2e3

Browse files
committed
Apply language migrations from PHP 7.4 to 8.1
1 parent e85a9ea commit fede2e3

File tree

18 files changed

+75
-173
lines changed

18 files changed

+75
-173
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22

33
## Unreleased
44

5-
* Dropped support for PHP version <8.1
5+
The most notable change is that you need PHP 8.1/8.2 to use the new version. The language migration to
6+
PHP 8.1 introduces potentially breaking changes concerning the strictness of parameter types -
7+
however, this should not affect your project in most cases (unless you have used internal classes
8+
directly or by extension).
9+
10+
Please see [UPGRADE-4.0.md](UPGRADE-4.0.md) for detailed information.
611

712
## 3.0.3 - 2022-08-22
813

UPGRADE-4.0.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Upgrade from 3.x to 4.0
2+
3+
## Introduction
4+
5+
The list of breaking changes below should not be an issue if you've been using the library as intended and documented.
6+
7+
## Complete list of breaking changes
8+
9+
The following list has been generated with [roave/backward-compatibility-check](https://github.com/Roave/BackwardCompatibilityCheck).
10+
11+
```
12+
[BC] CHANGED: The parameter $value of Kreait\Firebase\JWT\Value\Duration::make() changed from no type to a non-contravariant self|DateInterval|int|string
13+
[BC] CHANGED: The parameter $other of Kreait\Firebase\JWT\Value\Duration#isLargerThan() changed from no type to a non-contravariant self|DateInterval|int|string
14+
[BC] CHANGED: The parameter $other of Kreait\Firebase\JWT\Value\Duration#equals() changed from no type to a non-contravariant self|DateInterval|int|string
15+
[BC] CHANGED: The parameter $other of Kreait\Firebase\JWT\Value\Duration#isSmallerThan() changed from no type to a non-contravariant self|DateInterval|int|string
16+
[BC] CHANGED: The parameter $other of Kreait\Firebase\JWT\Value\Duration#compareTo() changed from no type to a non-contravariant self|DateInterval|int|string
17+
[BC] CHANGED: The parameter $duration of Kreait\Firebase\JWT\Action\FetchGooglePublicKeys#ifKeysDoNotExpireCacheFor() changed from no type to a non-contravariant Kreait\Firebase\JWT\Value\Duration|DateInterval|string|int
18+
[BC] CHANGED: The parameter $ttl of Kreait\Firebase\JWT\Action\CreateCustomToken#withTimeToLive() changed from no type to a non-contravariant Kreait\Firebase\JWT\Value\Duration|DateInterval|string|int
19+
[BC] CHANGED: The parameter $timeToLive of Kreait\Firebase\JWT\CustomTokenGenerator#createCustomToken() changed from no type to a non-contravariant Kreait\Firebase\JWT\Value\Duration|DateInterval|string|int|null
20+
[BC] REMOVED: Class Kreait\Firebase\JWT\Error\DiscoveryFailed has been deleted
21+
```

src/JWT/Action/CreateCustomToken.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,14 @@ final class CreateCustomToken
1313
public const MINIMUM_TTL = 'PT1S';
1414
public const MAXIMUM_TTL = 'PT1H';
1515
public const DEFAULT_TTL = self::MAXIMUM_TTL;
16-
private string $uid;
1716
private ?string $tenantId = null;
1817

1918
/** @var array<string, mixed> */
2019
private array $customClaims = [];
2120
private Duration $ttl;
2221

23-
private function __construct(string $uid)
22+
private function __construct(private string $uid)
2423
{
25-
$this->uid = $uid;
2624
$this->ttl = Duration::fromDateIntervalSpec(self::DEFAULT_TTL);
2725
}
2826

@@ -47,10 +45,7 @@ public function withChangedUid(string $uid): self
4745
return $action;
4846
}
4947

50-
/**
51-
* @param mixed $value
52-
*/
53-
public function withCustomClaim(string $name, $value): self
48+
public function withCustomClaim(string $name, mixed $value): self
5449
{
5550
$action = clone $this;
5651
$action->customClaims[$name] = $value;
@@ -75,15 +70,12 @@ public function withCustomClaims(array $claims): self
7570
public function withAddedCustomClaims(array $claims): self
7671
{
7772
$action = clone $this;
78-
$action->customClaims = array_merge($action->customClaims, $claims);
73+
$action->customClaims = [...$action->customClaims, ...$claims];
7974

8075
return $action;
8176
}
8277

83-
/**
84-
* @param Duration|DateInterval|string|int $ttl
85-
*/
86-
public function withTimeToLive($ttl): self
78+
public function withTimeToLive(Duration|DateInterval|string|int $ttl): self
8779
{
8880
$ttl = Duration::make($ttl);
8981

src/JWT/Action/CreateCustomToken/WithLcobucciJWT.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,15 @@
2020
*/
2121
final class WithLcobucciJWT implements Handler
2222
{
23-
private string $clientEmail;
24-
private ClockInterface $clock;
25-
private Configuration $config;
23+
private readonly ClockInterface $clock;
24+
private readonly Configuration $config;
2625

2726
/**
2827
* @param non-empty-string $clientEmail
2928
* @param non-empty-string $privateKey
3029
*/
31-
public function __construct(string $clientEmail, string $privateKey, ClockInterface $clock)
30+
public function __construct(private readonly string $clientEmail, string $privateKey, ClockInterface $clock)
3231
{
33-
$this->clientEmail = $clientEmail;
3432
$this->clock = $clock;
3533

3634
$this->config = Configuration::forSymmetricSigner(

src/JWT/Action/FetchGooglePublicKeys.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,14 @@ final class FetchGooglePublicKeys
1717
public const DEFAULT_FALLBACK_CACHE_DURATION = 'PT1H';
1818

1919
/** @var array<int, string> */
20-
private array $urls;
21-
private Duration $fallbackCacheDuration;
20+
private readonly array $urls;
2221

2322
/**
2423
* @param array<array-key, string> $urls
2524
*/
26-
private function __construct(array $urls, Duration $fallbackCacheDuration)
25+
private function __construct(array $urls, private Duration $fallbackCacheDuration)
2726
{
2827
$this->urls = array_values($urls);
29-
$this->fallbackCacheDuration = $fallbackCacheDuration;
3028
}
3129

3230
public static function fromGoogle(): self
@@ -45,10 +43,8 @@ public static function fromUrl(string $url): self
4543
/**
4644
* A response from the Google APIs should have a cache control header that determines when the keys expire.
4745
* If it doesn't have one, fall back to this value.
48-
*
49-
* @param Duration|DateInterval|string|int $duration
5046
*/
51-
public function ifKeysDoNotExpireCacheFor($duration): self
47+
public function ifKeysDoNotExpireCacheFor(Duration|DateInterval|string|int $duration): self
5248
{
5349
$duration = Duration::make($duration);
5450

src/JWT/Action/FetchGooglePublicKeys/WithGuzzle.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
*/
2222
final class WithGuzzle implements Handler
2323
{
24-
private ClientInterface $client;
25-
private ClockInterface $clock;
24+
private readonly ClientInterface $client;
25+
private readonly ClockInterface $clock;
2626

2727
public function __construct(ClientInterface $client, ClockInterface $clock)
2828
{

src/JWT/Action/FetchGooglePublicKeys/WithPsr6Cache.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,16 @@
1111
use Psr\Cache\CacheItemPoolInterface;
1212
use StellaMaris\Clock\ClockInterface;
1313

14-
use function get_class;
15-
1614
/**
1715
* @internal
1816
*/
1917
final class WithPsr6Cache implements Handler
2018
{
21-
private Handler $handler;
22-
private CacheItemPoolInterface $cache;
23-
private ClockInterface $clock;
19+
private readonly CacheItemPoolInterface $cache;
20+
private readonly ClockInterface $clock;
2421

25-
public function __construct(Handler $handler, CacheItemPoolInterface $cache, ClockInterface $clock)
22+
public function __construct(private readonly Handler $handler, CacheItemPoolInterface $cache, ClockInterface $clock)
2623
{
27-
$this->handler = $handler;
2824
$this->cache = $cache;
2925
$this->clock = $clock;
3026
}
@@ -61,7 +57,7 @@ public function handle(FetchGooglePublicKeys $action): Keys
6157
$reason = sprintf(
6258
'The inner handler of %s (%s) failed in fetching keys: %s',
6359
self::class,
64-
get_class($this->handler),
60+
$this->handler::class,
6561
$e->getMessage(),
6662
);
6763

src/JWT/Action/VerifyIdToken/WithLcobucciJWT.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,13 @@
3939
*/
4040
final class WithLcobucciJWT implements Handler
4141
{
42-
private string $projectId;
43-
private Keys $keys;
44-
private ClockInterface $clock;
45-
private Parser $parser;
42+
private readonly ClockInterface $clock;
43+
private readonly Parser $parser;
4644
private Signer $signer;
47-
private Validator $validator;
45+
private readonly Validator $validator;
4846

49-
public function __construct(string $projectId, Keys $keys, ClockInterface $clock)
47+
public function __construct(private readonly string $projectId, private readonly Keys $keys, ClockInterface $clock)
5048
{
51-
$this->projectId = $projectId;
52-
$this->keys = $keys;
5349
$this->clock = $clock;
5450
$this->parser = new Parser(new JoseEncoder());
5551

src/JWT/Action/VerifySessionCookie/WithLcobucciJWT.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,13 @@
3939
*/
4040
final class WithLcobucciJWT implements Handler
4141
{
42-
private string $projectId;
43-
private Keys $keys;
44-
private ClockInterface $clock;
45-
private Parser $parser;
42+
private readonly ClockInterface $clock;
43+
private readonly Parser $parser;
4644
private Signer $signer;
47-
private Validator $validator;
45+
private readonly Validator $validator;
4846

49-
public function __construct(string $projectId, Keys $keys, ClockInterface $clock)
47+
public function __construct(private readonly string $projectId, private readonly Keys $keys, ClockInterface $clock)
5048
{
51-
$this->projectId = $projectId;
52-
$this->keys = $keys;
5349
$this->clock = $clock;
5450
$this->parser = new Parser(new JoseEncoder());
5551

src/JWT/CustomTokenGenerator.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,10 @@
1515

1616
final class CustomTokenGenerator
1717
{
18-
private Handler $handler;
1918
private ?string $tenantId = null;
2019

21-
public function __construct(Handler $handler)
20+
public function __construct(private readonly Handler $handler)
2221
{
23-
$this->handler = $handler;
2422
}
2523

2624
/**
@@ -53,11 +51,10 @@ public function execute(CreateCustomToken $action): Token
5351

5452
/**
5553
* @param array<string, mixed> $claims
56-
* @param Duration|DateInterval|string|int $timeToLive
5754
*
5855
* @throws CustomTokenCreationFailed
5956
*/
60-
public function createCustomToken(string $uid, ?array $claims = null, $timeToLive = null): Token
57+
public function createCustomToken(string $uid, ?array $claims = null, Duration|DateInterval|string|int $timeToLive = null): Token
6158
{
6259
$action = CreateCustomToken::forUid($uid);
6360

0 commit comments

Comments
 (0)