Skip to content

Commit

Permalink
Make implicit nullable types explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Mar 20, 2024
1 parent bbff78d commit 5ec5c7b
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 23 deletions.
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
'no_superfluous_phpdoc_tags' => [
'allow_mixed' => true,
],
'nullable_type_declaration_for_default_null_value' => true,
'phpdoc_annotation_without_dot' => false,
'phpdoc_summary' => false,
'phpdoc_to_comment' => false,
Expand Down
4 changes: 2 additions & 2 deletions src/Coroutine.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ public static function of(callable $generatorFn): self
}

public function then(
callable $onFulfilled = null,
callable $onRejected = null
?callable $onFulfilled = null,
?callable $onRejected = null
): PromiseInterface {
return $this->result->then($onFulfilled, $onRejected);
}
Expand Down
10 changes: 5 additions & 5 deletions src/Each.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ final class Each
*/
public static function of(
$iterable,
callable $onFulfilled = null,
callable $onRejected = null
?callable $onFulfilled = null,
?callable $onRejected = null
): PromiseInterface {
return (new EachPromise($iterable, [
'fulfilled' => $onFulfilled,
Expand All @@ -46,8 +46,8 @@ public static function of(
public static function ofLimit(
$iterable,
$concurrency,
callable $onFulfilled = null,
callable $onRejected = null
?callable $onFulfilled = null,
?callable $onRejected = null
): PromiseInterface {
return (new EachPromise($iterable, [
'fulfilled' => $onFulfilled,
Expand All @@ -67,7 +67,7 @@ public static function ofLimit(
public static function ofLimitAll(
$iterable,
$concurrency,
callable $onFulfilled = null
?callable $onFulfilled = null
): PromiseInterface {
return self::ofLimit(
$iterable,
Expand Down
4 changes: 2 additions & 2 deletions src/FulfilledPromise.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public function __construct($value)
}

public function then(
callable $onFulfilled = null,
callable $onRejected = null
?callable $onFulfilled = null,
?callable $onRejected = null
): PromiseInterface {
// Return itself if there is no onFulfilled function.
if (!$onFulfilled) {
Expand Down
8 changes: 4 additions & 4 deletions src/Promise.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ class Promise implements PromiseInterface
* @param callable $cancelFn Fn that when invoked cancels the promise.
*/
public function __construct(
callable $waitFn = null,
callable $cancelFn = null
?callable $waitFn = null,
?callable $cancelFn = null
) {
$this->waitFn = $waitFn;
$this->cancelFn = $cancelFn;
}

public function then(
callable $onFulfilled = null,
callable $onRejected = null
?callable $onFulfilled = null,
?callable $onRejected = null
): PromiseInterface {
if ($this->state === self::PENDING) {
$p = new Promise(null, [$this, 'cancel']);
Expand Down
4 changes: 2 additions & 2 deletions src/PromiseInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ interface PromiseInterface
* @param callable $onRejected Invoked when the promise is rejected.
*/
public function then(
callable $onFulfilled = null,
callable $onRejected = null
?callable $onFulfilled = null,
?callable $onRejected = null
): PromiseInterface;

/**
Expand Down
4 changes: 2 additions & 2 deletions src/RejectedPromise.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public function __construct($reason)
}

public function then(
callable $onFulfilled = null,
callable $onRejected = null
?callable $onFulfilled = null,
?callable $onRejected = null
): PromiseInterface {
// If there's no onRejected callback then just return self.
if (!$onRejected) {
Expand Down
2 changes: 1 addition & 1 deletion src/RejectionException.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class RejectionException extends \RuntimeException
* @param mixed $reason Rejection reason.
* @param string|null $description Optional description.
*/
public function __construct($reason, string $description = null)
public function __construct($reason, ?string $description = null)
{
$this->reason = $reason;

Expand Down
2 changes: 1 addition & 1 deletion src/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class Utils
*
* @param TaskQueueInterface|null $assign Optionally specify a new queue instance.
*/
public static function queue(TaskQueueInterface $assign = null): TaskQueueInterface
public static function queue(?TaskQueueInterface $assign = null): TaskQueueInterface
{
static $queue;

Expand Down
2 changes: 1 addition & 1 deletion tests/CoroutineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function testWaitShouldHandleIntermediateErrors(): void
});
});
})
->otherwise(function (\Exception $error = null) {
->otherwise(function (?\Exception $error = null) {
if (!$error) {
self::fail('Error did not propagate.');
}
Expand Down
4 changes: 2 additions & 2 deletions tests/NotPromiseInstance.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function __construct()
$this->nextPromise = new Promise();
}

public function then(callable $res = null, callable $rej = null): PromiseInterface
public function then(?callable $res = null, ?callable $rej = null): PromiseInterface
{
return $this->nextPromise->then($res, $rej);
}
Expand All @@ -36,7 +36,7 @@ public function reject($reason): void
$this->nextPromise->reject($reason);
}

public function wait(bool $unwrap = true, bool $defaultResolution = null): void
public function wait(bool $unwrap = true, ?bool $defaultResolution = null): void
{
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Thennable.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function __construct()
$this->nextPromise = new Promise();
}

public function then(callable $res = null, callable $rej = null)
public function then(?callable $res = null, ?callable $rej = null)
{
return $this->nextPromise->then($res, $rej);
}
Expand Down

0 comments on commit 5ec5c7b

Please sign in to comment.