Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed implicitly nullable params #6616

Merged
merged 1 commit into from Mar 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 14 additions & 4 deletions .php-cs-fixer.php
@@ -1,5 +1,14 @@
<?php

declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
$header = <<<'EOF'
This file is part of Hyperf.

Expand All @@ -23,13 +32,13 @@
'location' => 'after_declare_strict',
],
'array_syntax' => [
'syntax' => 'short'
'syntax' => 'short',
],
'list_syntax' => [
'syntax' => 'short'
'syntax' => 'short',
],
'concat_space' => [
'spacing' => 'one'
'spacing' => 'one',
],
'blank_line_before_statement' => [
'statements' => [
Expand All @@ -38,7 +47,7 @@
],
'general_phpdoc_annotation_remove' => [
'annotations' => [
'author'
'author',
],
],
'ordered_imports' => [
Expand Down Expand Up @@ -85,6 +94,7 @@
'single_quote' => true,
'standardize_not_equals' => true,
'multiline_comment_opening_closing' => true,
'nullable_type_declaration_for_default_null_value' => true, // Since PHP 8.3, default null values can be declared as nullable.
])
->setFinder(
PhpCsFixer\Finder::create()
Expand Down
2 changes: 1 addition & 1 deletion src/amqp/src/AMQPConnection.php
Expand Up @@ -64,7 +64,7 @@ public function __construct(
string $login_method = 'AMQPLAIN',
$login_response = null,
string $locale = 'en_US',
AbstractIO $io = null,
?AbstractIO $io = null,
int $heartbeat = 0,
int $connection_timeout = 0,
float $channel_rpc_timeout = 0.0
Expand Down
4 changes: 2 additions & 2 deletions src/async-queue/src/Driver/DriverInterface.php
Expand Up @@ -48,12 +48,12 @@ public function consume(): void;
/**
* Reload failed message into waiting queue.
*/
public function reload(string $queue = null): int;
public function reload(?string $queue = null): int;

/**
* Delete all failed message from failed queue.
*/
public function flush(string $queue = null): bool;
public function flush(?string $queue = null): bool;

/**
* Return info for current queue.
Expand Down
4 changes: 2 additions & 2 deletions src/async-queue/src/Driver/RedisDriver.php
Expand Up @@ -109,7 +109,7 @@ public function fail(mixed $data): bool
return false;
}

public function reload(string $queue = null): int
public function reload(?string $queue = null): int
{
$channel = $this->channel->getFailed();
if ($queue) {
Expand All @@ -127,7 +127,7 @@ public function reload(string $queue = null): int
return $num;
}

public function flush(string $queue = null): bool
public function flush(?string $queue = null): bool
{
$channel = $this->channel->getFailed();
if ($queue) {
Expand Down
8 changes: 4 additions & 4 deletions src/collection/src/Arr.php
Expand Up @@ -127,7 +127,7 @@ public static function exists(array|ArrayAccess $array, int|string $key): bool
/**
* Return the first element in an array passing a given truth test.
*/
public static function first(array $array, callable $callback = null, mixed $default = null): mixed
public static function first(array $array, ?callable $callback = null, mixed $default = null): mixed
{
if (is_null($callback)) {
if (empty($array)) {
Expand All @@ -148,7 +148,7 @@ public static function first(array $array, callable $callback = null, mixed $def
/**
* Return the last element in an array passing a given truth test.
*/
public static function last(array $array, callable $callback = null, mixed $default = null): mixed
public static function last(array $array, ?callable $callback = null, mixed $default = null): mixed
{
if (is_null($callback)) {
return empty($array) ? value($default) : end($array);
Expand Down Expand Up @@ -419,7 +419,7 @@ public static function pull(array &$array, string $key, mixed $default = null):
*
* @throws InvalidArgumentException
*/
public static function random(array $array, int $number = null): mixed
public static function random(array $array, ?int $number = null): mixed
{
$requested = is_null($number) ? 1 : $number;
$count = count($array);
Expand Down Expand Up @@ -471,7 +471,7 @@ public static function set(array &$array, null|int|string $key, mixed $value): a
/**
* Shuffle the given array and return the result.
*/
public static function shuffle(array $array, int $seed = null): array
public static function shuffle(array $array, ?int $seed = null): array
{
if (empty($array)) {
return [];
Expand Down
24 changes: 12 additions & 12 deletions src/collection/src/Collection.php
Expand Up @@ -188,7 +188,7 @@ public static function unwrap($value): array
* @param (callable(int): TTimesValue)|null $callback
* @return static<int, TTimesValue>
*/
public static function times(int $number, callable $callback = null): self
public static function times(int $number, ?callable $callback = null): self
{
if ($number < 1) {
return new static();
Expand Down Expand Up @@ -514,7 +514,7 @@ public function except($keys): self
* @param (callable(TValue, TKey): bool)|null $callback
* @return static<TKey, TValue>
*/
public function filter(callable $callback = null): self
public function filter(?callable $callback = null): self
{
if ($callback) {
return new static(Arr::where($this->items, $callback));
Expand All @@ -529,7 +529,7 @@ public function filter(callable $callback = null): self
* @param callable($this, $value): $this $default
* @return $this
*/
public function when(bool $value, callable $callback, callable $default = null): self
public function when(bool $value, callable $callback, ?callable $default = null): self
{
if ($value) {
return $callback($this, $value);
Expand All @@ -547,7 +547,7 @@ public function when(bool $value, callable $callback, callable $default = null):
* @param callable($this): null|$this $default
* @return $this
*/
public function unless(bool $value, callable $callback, callable $default = null): self
public function unless(bool $value, callable $callback, ?callable $default = null): self
{
return $this->when(! $value, $callback, $default);
}
Expand Down Expand Up @@ -647,7 +647,7 @@ public function whereInstanceOf(string $type): self
* @param TFirstDefault|(\Closure(): TFirstDefault) $default
* @return TFirstDefault|TValue
*/
public function first(callable $callback = null, $default = null)
public function first(?callable $callback = null, $default = null)
{
return Arr::first($this->items, $callback, $default);
}
Expand Down Expand Up @@ -786,7 +786,7 @@ public function has($key): bool
/**
* Concatenate values of a given key as a string.
*/
public function implode(string $value, string $glue = null): string
public function implode(string $value, ?string $glue = null): string
{
$first = $this->first();
if (is_array($first) || is_object($first)) {
Expand Down Expand Up @@ -850,7 +850,7 @@ public function keys(): self
* @param TLastDefault|(\Closure(): TLastDefault) $default
* @return TLastDefault|TValue
*/
public function last(callable $callback = null, $default = null)
public function last(?callable $callback = null, $default = null)
{
return Arr::last($this->items, $callback, $default);
}
Expand Down Expand Up @@ -1197,7 +1197,7 @@ public function put($key, $value): self
* @return static<int, TValue>|TValue
* @throws InvalidArgumentException
*/
public function random(int $number = null)
public function random(?int $number = null)
{
if (is_null($number)) {
return Arr::random($this->items);
Expand Down Expand Up @@ -1304,7 +1304,7 @@ public function shift()
*
* @return static<TKey, TValue>
*/
public function shuffle(int $seed = null): self
public function shuffle(?int $seed = null): self
{
return new static(Arr::shuffle($this->items, $seed));
}
Expand All @@ -1314,7 +1314,7 @@ public function shuffle(int $seed = null): self
*
* @return static<TKey, TValue>
*/
public function slice(int $offset, int $length = null): self
public function slice(int $offset, ?int $length = null): self
{
return new static(array_slice($this->items, $offset, $length, true));
}
Expand Down Expand Up @@ -1369,7 +1369,7 @@ public function chunk(int $size): self
* @param callable(TValue, TValue): int $callback
* @return static<TKey, TValue>
*/
public function sort(callable $callback = null): self
public function sort(?callable $callback = null): self
{
$items = $this->items;
$callback ? uasort($items, $callback) : asort($items);
Expand Down Expand Up @@ -1445,7 +1445,7 @@ public function sortKeysDesc(int $options = SORT_REGULAR): self
* @param array<array-key, TValue> $replacement
* @return static<TKey, TValue>
*/
public function splice(int $offset, int $length = null, $replacement = []): self
public function splice(int $offset, ?int $length = null, $replacement = []): self
{
if (func_num_args() === 1) {
return new static(array_splice($this->items, $offset));
Expand Down
2 changes: 1 addition & 1 deletion src/command/src/Command.php
Expand Up @@ -69,7 +69,7 @@ abstract class Command extends SymfonyCommand
*/
protected int $exitCode = self::SUCCESS;

public function __construct(string $name = null)
public function __construct(?string $name = null)
{
$this->name = $name ?? $this->name;

Expand Down
2 changes: 1 addition & 1 deletion src/command/tests/Command/FooExceptionCommand.php
Expand Up @@ -18,7 +18,7 @@

class FooExceptionCommand extends Command
{
public function __construct(string $name = null)
public function __construct(?string $name = null)
{
parent::__construct($name);

Expand Down
2 changes: 1 addition & 1 deletion src/command/tests/Command/FooExitCommand.php
Expand Up @@ -17,7 +17,7 @@

class FooExitCommand extends Command
{
public function __construct(string $name = null)
public function __construct(?string $name = null)
{
parent::__construct($name);

Expand Down
2 changes: 1 addition & 1 deletion src/command/tests/Command/FooTraitCommand.php
Expand Up @@ -15,7 +15,7 @@ class FooTraitCommand extends \Hyperf\Command\Command
{
use Traits\Foo;

public function __construct(string $name = null)
public function __construct(?string $name = null)
{
parent::__construct($name);
}
Expand Down
4 changes: 2 additions & 2 deletions src/conditionable/src/Conditionable.php
Expand Up @@ -27,7 +27,7 @@ trait Conditionable
* @param null|mixed $value
* @return $this|TWhenReturnType
*/
public function when($value = null, callable $callback = null, callable $default = null)
public function when($value = null, ?callable $callback = null, ?callable $default = null)
{
$value = $value instanceof Closure ? $value($this) : $value;

Expand Down Expand Up @@ -61,7 +61,7 @@ public function when($value = null, callable $callback = null, callable $default
* @param null|mixed $value
* @return $this|TUnlessReturnType
*/
public function unless($value = null, callable $callback = null, callable $default = null)
public function unless($value = null, ?callable $callback = null, ?callable $default = null)
{
$value = $value instanceof Closure ? $value($this) : $value;

Expand Down
2 changes: 1 addition & 1 deletion src/consul/src/Client.php
Expand Up @@ -37,7 +37,7 @@ abstract class Client
*/
private $logger;

public function __construct(Closure $clientFactory, LoggerInterface $logger = null)
public function __construct(Closure $clientFactory, ?LoggerInterface $logger = null)
{
$this->clientFactory = $clientFactory;
$this->logger = $logger ?: new NullLogger();
Expand Down
2 changes: 1 addition & 1 deletion src/consul/src/ConsulResponse.php
Expand Up @@ -32,7 +32,7 @@ public function __call($name, $arguments)
return $this->response->{$name}(...$arguments);
}

public function json(string $key = null, $default = null)
public function json(?string $key = null, $default = null)
{
if ($this->response->getHeaderLine('content-type') !== 'application/json') {
throw new ServerException('The Content-Type of response is not equal application/json');
Expand Down
2 changes: 1 addition & 1 deletion src/crontab/src/Parser.php
Expand Up @@ -78,7 +78,7 @@ public function isValid(string $crontabString): bool
/**
* Parse each segment of crontab string.
*/
protected function parseSegment(string $string, int $min, int $max, int $start = null)
protected function parseSegment(string $string, int $min, int $max, ?int $start = null)
{
if ($start === null || $start < $min) {
$start = $min;
Expand Down
4 changes: 2 additions & 2 deletions src/dag/src/Vertex.php
Expand Up @@ -32,7 +32,7 @@ class Vertex
*/
public array $children = [];

public static function make(callable $job, string $key = null): self
public static function make(callable $job, ?string $key = null): self
{
$closure = Closure::fromCallable($job);
if ($key === null) {
Expand All @@ -45,7 +45,7 @@ public static function make(callable $job, string $key = null): self
return $v;
}

public static function of(Runner $job, string $key = null): self
public static function of(Runner $job, ?string $key = null): self
{
if ($key === null) {
$key = spl_object_hash($job);
Expand Down
4 changes: 2 additions & 2 deletions src/database-sqlite/src/Schema/Grammars/SQLiteGrammar.php
Expand Up @@ -429,7 +429,7 @@ public function typeMultiPolygon(Fluent $column): string
return 'multipolygon';
}

protected function getIndexColumns(Connection $connection, string $tableName = null): array
protected function getIndexColumns(Connection $connection, ?string $tableName = null): array
{
$sql = <<<'SQL'
SELECT t.name AS table_name,
Expand Down Expand Up @@ -460,7 +460,7 @@ protected function getIndexColumns(Connection $connection, string $tableName = n
/**
* @see http://ezcomponents.org/docs/api/trunk/DatabaseSchema/ezcDbSchemaPgsqlReader.html
*/
protected function getTableIndexesList(Connection $connection, array $tableIndexes, string $tableName = null): array
protected function getTableIndexesList(Connection $connection, array $tableIndexes, ?string $tableName = null): array
{
$indexBuffer = [];

Expand Down
2 changes: 1 addition & 1 deletion src/database-sqlite/src/Schema/SQLiteBuilder.php
Expand Up @@ -83,7 +83,7 @@ public function getIndexListing(string $table): array
*
* @param array|string $index
*/
public function hasIndex(string $table, $index, string $type = null): bool
public function hasIndex(string $table, $index, ?string $type = null): bool
{
$type = is_null($type) ? $type : strtolower($type);

Expand Down
2 changes: 1 addition & 1 deletion src/database/src/Migrations/MigrationCreator.php
Expand Up @@ -36,7 +36,7 @@ public function __construct(protected Filesystem $files)
*
* @throws Exception
*/
public function create(string $name, string $path, string $table = null, bool $create = false): string
public function create(string $name, string $path, ?string $table = null, bool $create = false): string
{
$this->ensureMigrationDoesntAlreadyExist($name, $path);

Expand Down
4 changes: 2 additions & 2 deletions src/database/src/Model/Builder.php
Expand Up @@ -261,7 +261,7 @@ public function withoutGlobalScope($scope)
*
* @return $this
*/
public function withoutGlobalScopes(array $scopes = null)
public function withoutGlobalScopes(?array $scopes = null)
{
if (! is_array($scopes)) {
$scopes = array_keys($this->scopes);
Expand Down Expand Up @@ -559,7 +559,7 @@ public function firstOrFail($columns = ['*'])
* @param array|Closure $columns
* @return \Hyperf\Database\Model\Model|mixed|static
*/
public function firstOr($columns = ['*'], Closure $callback = null)
public function firstOr($columns = ['*'], ?Closure $callback = null)
{
if ($columns instanceof Closure) {
$callback = $columns;
Expand Down
2 changes: 1 addition & 1 deletion src/database/src/Model/Concerns/HasAttributes.php
Expand Up @@ -542,7 +542,7 @@ public function syncOriginalAttributes($attributes): static
/**
* Sync the changed attributes.
*/
public function syncChanges(array $columns = null): static
public function syncChanges(?array $columns = null): static
{
$changes = $this->getDirty();

Expand Down