Skip to content

Commit

Permalink
Merge pull request #260 from SimonFrings/nullable
Browse files Browse the repository at this point in the history
Improve PHP 8.4+ support by avoiding implicitly nullable type declarations
  • Loading branch information
WyriHaximus authored May 15, 2024
2 parents e563d55 + 57cafa9 commit 9dcf6c6
Show file tree
Hide file tree
Showing 17 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/Deferred.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Internal/FulfilledPromise.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct($value = null)
* @param ?(callable((T is void ? null : T)): (PromiseInterface<TFulfilled>|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;
Expand Down
2 changes: 1 addition & 1 deletion src/Internal/RejectedPromise.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function __destruct()
* @param ?(callable(\Throwable): (PromiseInterface<TRejected>|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;
Expand Down
6 changes: 3 additions & 3 deletions src/Promise.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion tests/DeferredTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class DeferredTest extends TestCase
/**
* @return CallbackPromiseAdapter<T>
*/
public function getPromiseTestAdapter(callable $canceller = null): CallbackPromiseAdapter
public function getPromiseTestAdapter(?callable $canceller = null): CallbackPromiseAdapter
{
$d = new Deferred($canceller);

Expand Down
2 changes: 1 addition & 1 deletion tests/Internal/FulfilledPromiseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class FulfilledPromiseTest extends TestCase
/**
* @return CallbackPromiseAdapter<T>
*/
public function getPromiseTestAdapter(callable $canceller = null): CallbackPromiseAdapter
public function getPromiseTestAdapter(?callable $canceller = null): CallbackPromiseAdapter
{
/** @var ?FulfilledPromise<T> */
$promise = null;
Expand Down
2 changes: 1 addition & 1 deletion tests/Internal/RejectedPromiseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class RejectedPromiseTest extends TestCase
/**
* @return CallbackPromiseAdapter<never>
*/
public function getPromiseTestAdapter(callable $canceller = null): CallbackPromiseAdapter
public function getPromiseTestAdapter(?callable $canceller = null): CallbackPromiseAdapter
{
/** @var ?RejectedPromise */
$promise = null;
Expand Down
2 changes: 1 addition & 1 deletion tests/PromiseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class PromiseTest extends TestCase
/**
* @return CallbackPromiseAdapter<T>
*/
public function getPromiseTestAdapter(callable $canceller = null): CallbackPromiseAdapter
public function getPromiseTestAdapter(?callable $canceller = null): CallbackPromiseAdapter
{
$resolveCallback = $rejectCallback = null;

Expand Down
2 changes: 1 addition & 1 deletion tests/PromiseTest/CancelTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/PromiseTest/PromiseFulfilledTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/PromiseTest/PromisePendingTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/PromiseTest/PromiseRejectedTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/PromiseTest/PromiseSettledTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/PromiseTest/RejectTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/PromiseTest/ResolveTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/SimpleFulfilledTestThenable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/SimpleTestCancellableThenable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 9dcf6c6

Please sign in to comment.