diff --git a/lib/CancellationTokenSource.php b/lib/CancellationTokenSource.php index a57c6e9e..965c7cb0 100644 --- a/lib/CancellationTokenSource.php +++ b/lib/CancellationTokenSource.php @@ -150,7 +150,7 @@ public function getToken(): CancellationToken * * @return void */ - public function cancel(\Throwable $previous = null) + public function cancel(?\Throwable $previous = null) { if ($this->onCancel === null) { return; diff --git a/lib/CancelledException.php b/lib/CancelledException.php index 25f8c400..7cc1da46 100644 --- a/lib/CancelledException.php +++ b/lib/CancelledException.php @@ -10,7 +10,7 @@ */ class CancelledException extends \Exception { - public function __construct(\Throwable $previous = null) + public function __construct(?\Throwable $previous = null) { parent::__construct("The operation was cancelled", 0, $previous); } diff --git a/lib/Coroutine.php b/lib/Coroutine.php index 5a3b4aa8..d4195bfe 100644 --- a/lib/Coroutine.php +++ b/lib/Coroutine.php @@ -88,7 +88,7 @@ public function __construct(\Generator $generator) * @psalm-suppress MissingClosureParamType * @psalm-suppress MissingClosureReturnType */ - $onResolve = function (\Throwable $e = null, $v) use ($generator, &$onResolve) { + $onResolve = function (?\Throwable $e = null, $v) use ($generator, &$onResolve) { /** @var bool $immediate Used to control iterative coroutine continuation. */ static $immediate = true; diff --git a/lib/Internal/ResolutionQueue.php b/lib/Internal/ResolutionQueue.php index 353a8b93..8b6397e3 100644 --- a/lib/Internal/ResolutionQueue.php +++ b/lib/Internal/ResolutionQueue.php @@ -27,7 +27,7 @@ class ResolutionQueue * Promise|\React\Promise\PromiseInterface|array, mixed, * mixed>|null) | callable(\Throwable|null, mixed): void $callback */ - public function __construct(callable $callback = null) + public function __construct(?callable $callback = null) { if ($callback !== null) { $this->push($callback); diff --git a/lib/InvalidYieldError.php b/lib/InvalidYieldError.php index 8785708e..fddb7710 100644 --- a/lib/InvalidYieldError.php +++ b/lib/InvalidYieldError.php @@ -9,7 +9,7 @@ class InvalidYieldError extends \Error * @param string $prefix * @param \Throwable|null $previous */ - public function __construct(\Generator $generator, string $prefix, \Throwable $previous = null) + public function __construct(\Generator $generator, string $prefix, ?\Throwable $previous = null) { $yielded = $generator->current(); $prefix .= \sprintf( diff --git a/lib/Loop.php b/lib/Loop.php index d89d2101..33adce10 100644 --- a/lib/Loop.php +++ b/lib/Loop.php @@ -86,7 +86,7 @@ public function getHandle() * * @return void */ - public static function run(callable $callback = null) + public static function run(?callable $callback = null) { if ($callback) { self::$driver->defer($callback); @@ -406,7 +406,7 @@ public static function getState(string $key) * * @return callable(\Throwable $error)|null The previous handler, `null` if there was none. */ - public static function setErrorHandler(callable $callback = null) + public static function setErrorHandler(?callable $callback = null) { return self::$driver->setErrorHandler($callback); } diff --git a/lib/Loop/Driver.php b/lib/Loop/Driver.php index 448bab62..89b372a7 100644 --- a/lib/Loop/Driver.php +++ b/lib/Loop/Driver.php @@ -593,7 +593,7 @@ final public function getState(string $key) * * @return callable(\Throwable $error):void|null The previous handler, `null` if there was none. */ - public function setErrorHandler(callable $callback = null) + public function setErrorHandler(?callable $callback = null) { $previous = $this->errorHandler; $this->errorHandler = $callback; diff --git a/lib/Loop/TracingDriver.php b/lib/Loop/TracingDriver.php index 7b787548..3e7de532 100644 --- a/lib/Loop/TracingDriver.php +++ b/lib/Loop/TracingDriver.php @@ -147,7 +147,7 @@ public function unreference(string $watcherId) $this->unreferencedWatchers[$watcherId] = true; } - public function setErrorHandler(callable $callback = null) + public function setErrorHandler(?callable $callback = null) { return $this->driver->setErrorHandler($callback); } diff --git a/lib/MultiReasonException.php b/lib/MultiReasonException.php index 19c5c4d8..09758fb8 100644 --- a/lib/MultiReasonException.php +++ b/lib/MultiReasonException.php @@ -11,7 +11,7 @@ class MultiReasonException extends \Exception * @param \Throwable[] $reasons Array of exceptions rejecting the promise. * @param string|null $message */ - public function __construct(array $reasons, string $message = null) + public function __construct(array $reasons, ?string $message = null) { parent::__construct($message ?: "Multiple errors encountered; use " . self::class . "::getReasons() to retrieve the array of exceptions thrown"); diff --git a/lib/functions.php b/lib/functions.php index 7b1c2c55..31f41283 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -570,7 +570,7 @@ function wrap($promise, callable $callback): Promise $deferred = new Deferred(); - $promise->onResolve(static function (\Throwable $exception = null, $result) use ($deferred, $callback) { + $promise->onResolve(static function (?\Throwable $exception = null, $result) use ($deferred, $callback) { try { $result = $callback($exception, $result); } catch (\Throwable $exception) {