From bfb3c221ed0fc8ccb60da3b93c0d338dd8afac03 Mon Sep 17 00:00:00 2001 From: Florent Morselli Date: Fri, 12 May 2023 18:08:01 +0200 Subject: [PATCH] Add explicit nullable type where needed --- src/Bundle/JoseFramework/Routing/JWKSetLoader.php | 4 ++-- src/Bundle/JoseFramework/Serializer/JWESerializer.php | 4 ++-- src/Bundle/JoseFramework/Serializer/JWSSerializer.php | 4 ++-- src/Bundle/JoseFramework/Services/JWEDecrypter.php | 2 +- src/Bundle/JoseFramework/Services/JWSVerifier.php | 2 +- src/Component/Console/KeyAnalyzerCommand.php | 2 +- src/Component/Console/KeysetAnalyzerCommand.php | 2 +- src/Component/Encryption/JWEDecrypter.php | 6 +++--- src/Component/Signature/JWSVerifier.php | 6 +++--- 9 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Bundle/JoseFramework/Routing/JWKSetLoader.php b/src/Bundle/JoseFramework/Routing/JWKSetLoader.php index ad2c9fffd..47c1a5721 100644 --- a/src/Bundle/JoseFramework/Routing/JWKSetLoader.php +++ b/src/Bundle/JoseFramework/Routing/JWKSetLoader.php @@ -32,7 +32,7 @@ public function add(string $pattern, string $name): void /** * {@inheritdoc} */ - public function load(mixed $resource, string $type = null): RouteCollection + public function load(mixed $resource, ?string $type = null): RouteCollection { return $this->routes; } @@ -40,7 +40,7 @@ public function load(mixed $resource, string $type = null): RouteCollection /** * {@inheritdoc} */ - public function supports(mixed $resource, string $type = null): bool + public function supports(mixed $resource, ?string $type = null): bool { return $type === 'jwkset'; } diff --git a/src/Bundle/JoseFramework/Serializer/JWESerializer.php b/src/Bundle/JoseFramework/Serializer/JWESerializer.php index b6e249fa1..8776c524b 100644 --- a/src/Bundle/JoseFramework/Serializer/JWESerializer.php +++ b/src/Bundle/JoseFramework/Serializer/JWESerializer.php @@ -26,14 +26,14 @@ public function __construct( $this->serializerManager = $serializerManager; } - public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = []): bool + public function supportsDenormalization(mixed $data, string $type, ?string $format = null, array $context = []): bool { return $type === JWE::class && class_exists(JWESerializerManager::class) && $this->formatSupported($format); } - public function denormalize(mixed $data, string $type, string $format = null, array $context = []): JWE + public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): JWE { if ($data instanceof JWE === false) { throw new LogicException('Expected data to be a JWE.'); diff --git a/src/Bundle/JoseFramework/Serializer/JWSSerializer.php b/src/Bundle/JoseFramework/Serializer/JWSSerializer.php index aac2f6e63..d38cf6ab4 100644 --- a/src/Bundle/JoseFramework/Serializer/JWSSerializer.php +++ b/src/Bundle/JoseFramework/Serializer/JWSSerializer.php @@ -26,14 +26,14 @@ public function __construct( $this->serializerManager = $serializerManager; } - public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = []): bool + public function supportsDenormalization(mixed $data, string $type, ?string $format = null, array $context = []): bool { return $type === JWS::class && class_exists(JWSSerializerManager::class) && $this->formatSupported($format); } - public function denormalize(mixed $data, string $type, string $format = null, array $context = []): JWS + public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): JWS { if ($data instanceof JWS === false) { throw new LogicException('Expected data to be a JWS.'); diff --git a/src/Bundle/JoseFramework/Services/JWEDecrypter.php b/src/Bundle/JoseFramework/Services/JWEDecrypter.php index 4e4c0c859..833fa857a 100644 --- a/src/Bundle/JoseFramework/Services/JWEDecrypter.php +++ b/src/Bundle/JoseFramework/Services/JWEDecrypter.php @@ -29,7 +29,7 @@ public function decryptUsingKeySet( JWE &$jwe, JWKSet $jwkset, int $recipient, - JWK &$jwk = null, + ?JWK &$jwk = null, ?JWK $senderKey = null ): bool { $success = parent::decryptUsingKeySet($jwe, $jwkset, $recipient, $jwk, $senderKey); diff --git a/src/Bundle/JoseFramework/Services/JWSVerifier.php b/src/Bundle/JoseFramework/Services/JWSVerifier.php index f5c058445..5b728d053 100644 --- a/src/Bundle/JoseFramework/Services/JWSVerifier.php +++ b/src/Bundle/JoseFramework/Services/JWSVerifier.php @@ -27,7 +27,7 @@ public function verifyWithKeySet( JWKSet $jwkset, int $signatureIndex, ?string $detachedPayload = null, - JWK &$jwk = null + ?JWK &$jwk = null ): bool { $success = parent::verifyWithKeySet($jws, $jwkset, $signatureIndex, $detachedPayload, $jwk); if ($success) { diff --git a/src/Component/Console/KeyAnalyzerCommand.php b/src/Component/Console/KeyAnalyzerCommand.php index 9c4bed0a9..4f8a274f2 100644 --- a/src/Component/Console/KeyAnalyzerCommand.php +++ b/src/Component/Console/KeyAnalyzerCommand.php @@ -24,7 +24,7 @@ final class KeyAnalyzerCommand extends Command public function __construct( private readonly KeyAnalyzerManager $analyzerManager, - string $name = null + ?string $name = null ) { parent::__construct($name); } diff --git a/src/Component/Console/KeysetAnalyzerCommand.php b/src/Component/Console/KeysetAnalyzerCommand.php index d33e8ce46..120e337b0 100644 --- a/src/Component/Console/KeysetAnalyzerCommand.php +++ b/src/Component/Console/KeysetAnalyzerCommand.php @@ -27,7 +27,7 @@ final class KeysetAnalyzerCommand extends Command public function __construct( private readonly KeysetAnalyzerManager $keysetAnalyzerManager, private readonly KeyAnalyzerManager $keyAnalyzerManager, - string $name = null + ?string $name = null ) { parent::__construct($name); } diff --git a/src/Component/Encryption/JWEDecrypter.php b/src/Component/Encryption/JWEDecrypter.php index 8ba11c23d..a9f037e2e 100644 --- a/src/Component/Encryption/JWEDecrypter.php +++ b/src/Component/Encryption/JWEDecrypter.php @@ -74,14 +74,14 @@ public function decryptUsingKey(JWE &$jwe, JWK $jwk, int $recipient, ?JWK $sende * * @param JWE $jwe A JWE object to decrypt * @param JWKSet $jwkset The key set used to decrypt the input - * @param JWK $jwk The key used to decrypt the token in case of success + * @param JWK|null $jwk The key used to decrypt the token in case of success * @param int $recipient The recipient used to decrypt the token in case of success */ public function decryptUsingKeySet( JWE &$jwe, JWKSet $jwkset, int $recipient, - JWK &$jwk = null, + ?JWK &$jwk = null, ?JWK $senderKey = null ): bool { if ($jwkset->count() === 0) { @@ -108,7 +108,7 @@ private function decryptRecipientKey( JWE $jwe, JWKSet $jwkset, int $i, - JWK &$successJwk = null, + ?JWK &$successJwk = null, ?JWK $senderKey = null ): ?string { $recipient = $jwe->getRecipient($i); diff --git a/src/Component/Signature/JWSVerifier.php b/src/Component/Signature/JWSVerifier.php index d750a507d..68e71302c 100644 --- a/src/Component/Signature/JWSVerifier.php +++ b/src/Component/Signature/JWSVerifier.php @@ -49,7 +49,7 @@ public function verifyWithKey(JWS $jws, JWK $jwk, int $signature, ?string $detac * * @param JWS $jws A JWS object * @param JWKSet $jwkset The signature will be verified using keys in the key set - * @param JWK $jwk The key used to verify the signature in case of success + * @param JWK|null $jwk The key used to verify the signature in case of success * @param string|null $detachedPayload If not null, the value must be the detached payload encoded in Base64 URL safe. If the input contains a payload, throws an exception. * * @return bool true if the verification of the signature succeeded, else false @@ -59,7 +59,7 @@ public function verifyWithKeySet( JWKSet $jwkset, int $signatureIndex, ?string $detachedPayload = null, - JWK &$jwk = null + ?JWK &$jwk = null ): bool { if ($jwkset->count() === 0) { throw new InvalidArgumentException('There is no key in the key set.'); @@ -78,7 +78,7 @@ private function verifySignature( JWKSet $jwkset, Signature $signature, ?string $detachedPayload = null, - JWK &$successJwk = null + ?JWK &$successJwk = null ): bool { $input = $this->getInputToVerify($jws, $signature, $detachedPayload); $algorithm = $this->getAlgorithm($signature);