Skip to content

Commit

Permalink
Make implicit nullable types explicit (#431)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas authored Mar 21, 2024
1 parent c5ea790 commit ab06144
Show file tree
Hide file tree
Showing 10 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/CancellationTokenSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/CancelledException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Coroutine.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion lib/Internal/ResolutionQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ResolutionQueue
* Promise|\React\Promise\PromiseInterface|array<array-key, Promise|\React\Promise\PromiseInterface>, 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);
Expand Down
2 changes: 1 addition & 1 deletion lib/InvalidYieldError.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions lib/Loop.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Loop/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/Loop/TracingDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/MultiReasonException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion lib/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit ab06144

Please sign in to comment.