From 57cafa9cd6b94ce8f31f8bc97ce6fb321f775041 Mon Sep 17 00:00:00 2001 From: Ayesh Karunaratne Date: Fri, 15 Mar 2024 14:21:44 +0700 Subject: [PATCH] [PHP 8.4] Fixes for implicit nullability deprecation Fixes all issues that emits a deprecation notice on PHP 8.4. See: - [RFC](https://wiki.php.net/rfc/deprecate-implicitly-nullable-types) - [PHP 8.4: Implicitly nullable parameter declarations deprecated](https://php.watch/versions/8.4/implicitly-marking-parameter-type-nullable-deprecated) --- src/Deferred.php | 2 +- src/Internal/FulfilledPromise.php | 2 +- src/Internal/RejectedPromise.php | 2 +- src/Promise.php | 6 +++--- tests/DeferredTest.php | 2 +- tests/Internal/FulfilledPromiseTest.php | 2 +- tests/Internal/RejectedPromiseTest.php | 2 +- tests/PromiseTest.php | 2 +- tests/PromiseTest/CancelTestTrait.php | 2 +- tests/PromiseTest/PromiseFulfilledTestTrait.php | 2 +- tests/PromiseTest/PromisePendingTestTrait.php | 2 +- tests/PromiseTest/PromiseRejectedTestTrait.php | 2 +- tests/PromiseTest/PromiseSettledTestTrait.php | 2 +- tests/PromiseTest/RejectTestTrait.php | 2 +- tests/PromiseTest/ResolveTestTrait.php | 2 +- tests/fixtures/SimpleFulfilledTestThenable.php | 2 +- tests/fixtures/SimpleTestCancellableThenable.php | 4 ++-- 17 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/Deferred.php b/src/Deferred.php index dac6b2b8..80b8fcfb 100644 --- a/src/Deferred.php +++ b/src/Deferred.php @@ -21,7 +21,7 @@ final class Deferred /** * @param (callable(callable(T):void,callable(\Throwable):void):void)|null $canceller */ - public function __construct(callable $canceller = null) + public function __construct(?callable $canceller = null) { $this->promise = new Promise(function ($resolve, $reject): void { $this->resolveCallback = $resolve; diff --git a/src/Internal/FulfilledPromise.php b/src/Internal/FulfilledPromise.php index 3c02b434..8664ffdb 100644 --- a/src/Internal/FulfilledPromise.php +++ b/src/Internal/FulfilledPromise.php @@ -34,7 +34,7 @@ public function __construct($value = null) * @param ?(callable((T is void ? null : T)): (PromiseInterface|TFulfilled)) $onFulfilled * @return PromiseInterface<($onFulfilled is null ? T : TFulfilled)> */ - public function then(callable $onFulfilled = null, callable $onRejected = null): PromiseInterface + public function then(?callable $onFulfilled = null, ?callable $onRejected = null): PromiseInterface { if (null === $onFulfilled) { return $this; diff --git a/src/Internal/RejectedPromise.php b/src/Internal/RejectedPromise.php index 348ca6d2..5c4f7be7 100644 --- a/src/Internal/RejectedPromise.php +++ b/src/Internal/RejectedPromise.php @@ -61,7 +61,7 @@ public function __destruct() * @param ?(callable(\Throwable): (PromiseInterface|TRejected)) $onRejected * @return PromiseInterface<($onRejected is null ? never : TRejected)> */ - public function then(callable $onFulfilled = null, callable $onRejected = null): PromiseInterface + public function then(?callable $onFulfilled = null, ?callable $onRejected = null): PromiseInterface { if (null === $onRejected) { return $this; diff --git a/src/Promise.php b/src/Promise.php index c46b41f0..4ac27007 100644 --- a/src/Promise.php +++ b/src/Promise.php @@ -29,7 +29,7 @@ final class Promise implements PromiseInterface * @param callable(callable(T):void,callable(\Throwable):void):void $resolver * @param (callable(callable(T):void,callable(\Throwable):void):void)|null $canceller */ - public function __construct(callable $resolver, callable $canceller = null) + public function __construct(callable $resolver, ?callable $canceller = null) { $this->canceller = $canceller; @@ -41,7 +41,7 @@ public function __construct(callable $resolver, callable $canceller = null) $this->call($cb); } - public function then(callable $onFulfilled = null, callable $onRejected = null): PromiseInterface + public function then(?callable $onFulfilled = null, ?callable $onRejected = null): PromiseInterface { if (null !== $this->result) { return $this->result->then($onFulfilled, $onRejected); @@ -166,7 +166,7 @@ public function always(callable $onFulfilledOrRejected): PromiseInterface return $this->finally($onFulfilledOrRejected); } - private function resolver(callable $onFulfilled = null, callable $onRejected = null): callable + private function resolver(?callable $onFulfilled = null, ?callable $onRejected = null): callable { return function (callable $resolve, callable $reject) use ($onFulfilled, $onRejected): void { $this->handlers[] = static function (PromiseInterface $promise) use ($onFulfilled, $onRejected, $resolve, $reject): void { diff --git a/tests/DeferredTest.php b/tests/DeferredTest.php index 416254f5..f63c0fda 100644 --- a/tests/DeferredTest.php +++ b/tests/DeferredTest.php @@ -14,7 +14,7 @@ class DeferredTest extends TestCase /** * @return CallbackPromiseAdapter */ - public function getPromiseTestAdapter(callable $canceller = null): CallbackPromiseAdapter + public function getPromiseTestAdapter(?callable $canceller = null): CallbackPromiseAdapter { $d = new Deferred($canceller); diff --git a/tests/Internal/FulfilledPromiseTest.php b/tests/Internal/FulfilledPromiseTest.php index 5a9ca9cd..b216e1d7 100644 --- a/tests/Internal/FulfilledPromiseTest.php +++ b/tests/Internal/FulfilledPromiseTest.php @@ -20,7 +20,7 @@ class FulfilledPromiseTest extends TestCase /** * @return CallbackPromiseAdapter */ - public function getPromiseTestAdapter(callable $canceller = null): CallbackPromiseAdapter + public function getPromiseTestAdapter(?callable $canceller = null): CallbackPromiseAdapter { /** @var ?FulfilledPromise */ $promise = null; diff --git a/tests/Internal/RejectedPromiseTest.php b/tests/Internal/RejectedPromiseTest.php index 7cfc0d66..2338b4f7 100644 --- a/tests/Internal/RejectedPromiseTest.php +++ b/tests/Internal/RejectedPromiseTest.php @@ -17,7 +17,7 @@ class RejectedPromiseTest extends TestCase /** * @return CallbackPromiseAdapter */ - public function getPromiseTestAdapter(callable $canceller = null): CallbackPromiseAdapter + public function getPromiseTestAdapter(?callable $canceller = null): CallbackPromiseAdapter { /** @var ?RejectedPromise */ $promise = null; diff --git a/tests/PromiseTest.php b/tests/PromiseTest.php index 34411dcc..a0e9acef 100644 --- a/tests/PromiseTest.php +++ b/tests/PromiseTest.php @@ -15,7 +15,7 @@ class PromiseTest extends TestCase /** * @return CallbackPromiseAdapter */ - public function getPromiseTestAdapter(callable $canceller = null): CallbackPromiseAdapter + public function getPromiseTestAdapter(?callable $canceller = null): CallbackPromiseAdapter { $resolveCallback = $rejectCallback = null; diff --git a/tests/PromiseTest/CancelTestTrait.php b/tests/PromiseTest/CancelTestTrait.php index 14def13a..d119c1bf 100644 --- a/tests/PromiseTest/CancelTestTrait.php +++ b/tests/PromiseTest/CancelTestTrait.php @@ -8,7 +8,7 @@ trait CancelTestTrait { - abstract public function getPromiseTestAdapter(callable $canceller = null): PromiseAdapterInterface; + abstract public function getPromiseTestAdapter(?callable $canceller = null): PromiseAdapterInterface; /** @test */ public function cancelShouldCallCancellerWithResolverArguments(): void diff --git a/tests/PromiseTest/PromiseFulfilledTestTrait.php b/tests/PromiseTest/PromiseFulfilledTestTrait.php index c5f35916..172c457f 100644 --- a/tests/PromiseTest/PromiseFulfilledTestTrait.php +++ b/tests/PromiseTest/PromiseFulfilledTestTrait.php @@ -11,7 +11,7 @@ trait PromiseFulfilledTestTrait { - abstract public function getPromiseTestAdapter(callable $canceller = null): PromiseAdapterInterface; + abstract public function getPromiseTestAdapter(?callable $canceller = null): PromiseAdapterInterface; /** @test */ public function fulfilledPromiseShouldBeImmutable(): void diff --git a/tests/PromiseTest/PromisePendingTestTrait.php b/tests/PromiseTest/PromisePendingTestTrait.php index a5268794..db5e2e4a 100644 --- a/tests/PromiseTest/PromisePendingTestTrait.php +++ b/tests/PromiseTest/PromisePendingTestTrait.php @@ -7,7 +7,7 @@ trait PromisePendingTestTrait { - abstract public function getPromiseTestAdapter(callable $canceller = null): PromiseAdapterInterface; + abstract public function getPromiseTestAdapter(?callable $canceller = null): PromiseAdapterInterface; /** @test */ public function thenShouldReturnAPromiseForPendingPromise(): void diff --git a/tests/PromiseTest/PromiseRejectedTestTrait.php b/tests/PromiseTest/PromiseRejectedTestTrait.php index 0f80d727..a1256984 100644 --- a/tests/PromiseTest/PromiseRejectedTestTrait.php +++ b/tests/PromiseTest/PromiseRejectedTestTrait.php @@ -11,7 +11,7 @@ trait PromiseRejectedTestTrait { - abstract public function getPromiseTestAdapter(callable $canceller = null): PromiseAdapterInterface; + abstract public function getPromiseTestAdapter(?callable $canceller = null): PromiseAdapterInterface; /** @test */ public function rejectedPromiseShouldBeImmutable(): void diff --git a/tests/PromiseTest/PromiseSettledTestTrait.php b/tests/PromiseTest/PromiseSettledTestTrait.php index 3f63dd5d..093ab8bd 100644 --- a/tests/PromiseTest/PromiseSettledTestTrait.php +++ b/tests/PromiseTest/PromiseSettledTestTrait.php @@ -8,7 +8,7 @@ trait PromiseSettledTestTrait { - abstract public function getPromiseTestAdapter(callable $canceller = null): PromiseAdapterInterface; + abstract public function getPromiseTestAdapter(?callable $canceller = null): PromiseAdapterInterface; /** @test */ public function thenShouldReturnAPromiseForSettledPromise(): void diff --git a/tests/PromiseTest/RejectTestTrait.php b/tests/PromiseTest/RejectTestTrait.php index 2b5617bb..eb1d8916 100644 --- a/tests/PromiseTest/RejectTestTrait.php +++ b/tests/PromiseTest/RejectTestTrait.php @@ -12,7 +12,7 @@ trait RejectTestTrait { - abstract public function getPromiseTestAdapter(callable $canceller = null): PromiseAdapterInterface; + abstract public function getPromiseTestAdapter(?callable $canceller = null): PromiseAdapterInterface; /** @test */ public function rejectShouldRejectWithAnException(): void diff --git a/tests/PromiseTest/ResolveTestTrait.php b/tests/PromiseTest/ResolveTestTrait.php index ed73dfc8..2a23065b 100644 --- a/tests/PromiseTest/ResolveTestTrait.php +++ b/tests/PromiseTest/ResolveTestTrait.php @@ -13,7 +13,7 @@ trait ResolveTestTrait { - abstract public function getPromiseTestAdapter(callable $canceller = null): PromiseAdapterInterface; + abstract public function getPromiseTestAdapter(?callable $canceller = null): PromiseAdapterInterface; /** @test */ public function resolveShouldResolve(): void diff --git a/tests/fixtures/SimpleFulfilledTestThenable.php b/tests/fixtures/SimpleFulfilledTestThenable.php index d9a093f7..c435bcc1 100644 --- a/tests/fixtures/SimpleFulfilledTestThenable.php +++ b/tests/fixtures/SimpleFulfilledTestThenable.php @@ -4,7 +4,7 @@ class SimpleFulfilledTestThenable { - public function then(callable $onFulfilled = null, callable $onRejected = null): self + public function then(?callable $onFulfilled = null, ?callable $onRejected = null): self { if ($onFulfilled) { $onFulfilled('foo'); diff --git a/tests/fixtures/SimpleTestCancellableThenable.php b/tests/fixtures/SimpleTestCancellableThenable.php index a4e9d642..9f77659b 100644 --- a/tests/fixtures/SimpleTestCancellableThenable.php +++ b/tests/fixtures/SimpleTestCancellableThenable.php @@ -10,12 +10,12 @@ class SimpleTestCancellableThenable /** @var ?callable */ public $onCancel; - public function __construct(callable $onCancel = null) + public function __construct(?callable $onCancel = null) { $this->onCancel = $onCancel; } - public function then(callable $onFulfilled = null, callable $onRejected = null): self + public function then(?callable $onFulfilled = null, ?callable $onRejected = null): self { return new self(); }