From 8b0a51bf13ca77a131e8124aab9632a9f40b8734 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20B=C3=BCrk?= Date: Fri, 26 Jul 2024 21:47:04 +0200 Subject: [PATCH 1/3] chore: fix latest php-cs-fixer findings --- src/CachedKeySet.php | 2 +- src/JWK.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CachedKeySet.php b/src/CachedKeySet.php index 65bab74f..dab57864 100644 --- a/src/CachedKeySet.php +++ b/src/CachedKeySet.php @@ -180,7 +180,7 @@ private function keyIdExists(string $keyId): bool $jwksResponse = $this->httpClient->sendRequest($request); if ($jwksResponse->getStatusCode() !== 200) { throw new UnexpectedValueException( - sprintf('HTTP Error: %d %s for URI "%s"', + \sprintf('HTTP Error: %d %s for URI "%s"', $jwksResponse->getStatusCode(), $jwksResponse->getReasonPhrase(), $this->jwksUri, diff --git a/src/JWK.php b/src/JWK.php index 63fb2484..1116eb97 100644 --- a/src/JWK.php +++ b/src/JWK.php @@ -212,7 +212,7 @@ private static function createPemFromCrvAndXYCoordinates(string $crv, string $x, ) ); - return sprintf( + return \sprintf( "-----BEGIN PUBLIC KEY-----\n%s\n-----END PUBLIC KEY-----\n", wordwrap(base64_encode($pem), 64, "\n", true) ); From 7c7f4bce5570f9f7f18906ce0082deb4b64f68ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20B=C3=BCrk?= Date: Fri, 26 Jul 2024 21:57:55 +0200 Subject: [PATCH 2/3] chore: Mitigate PHP8.4 deprecation warnings (#570) --- src/CachedKeySet.php | 4 ++-- src/JWK.php | 4 ++-- src/JWT.php | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/CachedKeySet.php b/src/CachedKeySet.php index dab57864..8e8e8d68 100644 --- a/src/CachedKeySet.php +++ b/src/CachedKeySet.php @@ -80,9 +80,9 @@ public function __construct( ClientInterface $httpClient, RequestFactoryInterface $httpFactory, CacheItemPoolInterface $cache, - int $expiresAfter = null, + ?int $expiresAfter = null, bool $rateLimit = false, - string $defaultAlg = null + ?string $defaultAlg = null ) { $this->jwksUri = $jwksUri; $this->httpClient = $httpClient; diff --git a/src/JWK.php b/src/JWK.php index 1116eb97..6efc2fe3 100644 --- a/src/JWK.php +++ b/src/JWK.php @@ -52,7 +52,7 @@ class JWK * * @uses parseKey */ - public static function parseKeySet(array $jwks, string $defaultAlg = null): array + public static function parseKeySet(array $jwks, ?string $defaultAlg = null): array { $keys = []; @@ -93,7 +93,7 @@ public static function parseKeySet(array $jwks, string $defaultAlg = null): arra * * @uses createPemFromModulusAndExponent */ - public static function parseKey(array $jwk, string $defaultAlg = null): ?Key + public static function parseKey(array $jwk, ?string $defaultAlg = null): ?Key { if (empty($jwk)) { throw new InvalidArgumentException('JWK must not be empty'); diff --git a/src/JWT.php b/src/JWT.php index e9d75639..9100bf0f 100644 --- a/src/JWT.php +++ b/src/JWT.php @@ -96,7 +96,7 @@ class JWT public static function decode( string $jwt, $keyOrKeyArray, - stdClass &$headers = null + ?stdClass &$headers = null ): stdClass { // Validate JWT $timestamp = \is_null(static::$timestamp) ? \time() : static::$timestamp; @@ -200,8 +200,8 @@ public static function encode( array $payload, $key, string $alg, - string $keyId = null, - array $head = null + ?string $keyId = null, + ?array $head = null ): string { $header = ['typ' => 'JWT']; if (isset($head) && \is_array($head)) { From 0df848cdcd548021309c541dbb370dae6763fbe1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20B=C3=BCrk?= Date: Fri, 26 Jul 2024 21:59:41 +0200 Subject: [PATCH 3/3] chore: Enable php-cs-fixer rules to avoid implicitly nullable method arguments --- .php-cs-fixer.dist.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index fb636632..93ff7a4c 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -16,6 +16,10 @@ 'native_function_invocation' => [ 'strict' => false ], + 'nullable_type_declaration' => [ + 'syntax' => 'question_mark', + ], + 'nullable_type_declaration_for_default_null_value' => true, ]) ->setFinder( PhpCsFixer\Finder::create()