Skip to content

Commit

Permalink
Enabled `SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultV…
Browse files Browse the repository at this point in the history
…alue` rule (phpcs).
  • Loading branch information
LastDragon-ru committed Jul 20, 2024
1 parent 128cbf9 commit 8615ec2
Show file tree
Hide file tree
Showing 137 changed files with 188 additions and 187 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/Helpers/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ abstract protected function getName(): string;
* @param list<string>|string $key
* @param array<string, mixed> $replace
*/
public function get(array|string $key, array $replace = [], string $locale = null): string {
public function get(array|string $key, array $replace = [], ?string $locale = null): string {
return $this->translate($key, function (string $key) use ($replace, $locale): string {
return Cast::toString($this->translator->get($this->key($key), $replace, $locale));
});
Expand All @@ -44,7 +44,7 @@ public function choice(
array|string $key,
Countable|array|int $number,
array $replace = [],
string $locale = null,
?string $locale = null,
): string {
return $this->translate($key, function (string $key) use ($number, $replace, $locale): string {
return $this->translator->choice($this->key($key), $number, $replace, $locale);
Expand Down
4 changes: 2 additions & 2 deletions packages/dev/src/App/Example.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ public function __invoke(File $file): ?string {
return $result;
}

public static function dump(mixed $value, string $expression = null): void {
public static function dump(mixed $value, ?string $expression = null): void {
self::getDumper()->dump($value, $expression ?? self::getExpression(__FUNCTION__));
}

public static function raw(Stringable|string $value, string $type, string $expression = null): void {
public static function raw(Stringable|string $value, string $type, ?string $expression = null): void {
self::getDumper()->raw($value, $expression ?? self::getExpression(__FUNCTION__), $type);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/documentator/src/PackageException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Throwable;

abstract class PackageException extends Exception {
public function __construct(string $message, Throwable $previous = null) {
public function __construct(string $message, ?Throwable $previous = null) {
parent::__construct($message, 0, $previous);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct(
protected readonly File $target,
protected readonly File $dependency,
protected readonly array $stack,
Throwable $previous = null,
?Throwable $previous = null,
) {
parent::__construct(
sprintf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function __construct(
* @var Dependency<*>
*/
protected readonly Dependency $dependency,
Throwable $previous = null,
?Throwable $previous = null,
) {
parent::__construct(
sprintf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class FileSaveFailed extends ProcessorError {
public function __construct(
protected Directory $root,
protected readonly File $target,
Throwable $previous = null,
?Throwable $previous = null,
) {
parent::__construct(
sprintf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function __construct(
protected Directory $root,
protected readonly File $target,
protected readonly Task $task,
Throwable $previous = null,
?Throwable $previous = null,
) {
parent::__construct(
sprintf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class ProcessingFailed extends ProcessorError {
public function __construct(
protected Directory $root,
Throwable $previous = null,
?Throwable $previous = null,
) {
parent::__construct(
sprintf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class DependencyIsMissing extends InstructionFailed {
public function __construct(
Context $context,
private readonly string $class,
Throwable $previous = null,
?Throwable $previous = null,
) {
parent::__construct(
$context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ abstract class InstructionFailed extends PreprocessError {
public function __construct(
private readonly Context $context,
string $message,
Throwable $previous = null,
?Throwable $previous = null,
) {
parent::__construct($message, $previous);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class PreprocessFailed extends PreprocessError {
public function __construct(
Throwable $previous = null,
?Throwable $previous = null,
) {
parent::__construct(
'Preprocessing failed.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class ArtisanCommandError extends InstructionFailed {
public function __construct(
Context $context,
Throwable $previous = null,
?Throwable $previous = null,
) {
parent::__construct(
$context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ArtisanCommandFailed extends InstructionFailed {
public function __construct(
Context $context,
private readonly int $result,
Throwable $previous = null,
?Throwable $previous = null,
) {
parent::__construct(
$context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use function sprintf;

class TargetIsNotValidPhpFile extends InstructionFailed {
public function __construct(Context $context, Throwable $previous = null) {
public function __construct(Context $context, ?Throwable $previous = null) {
parent::__construct(
$context,
sprintf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class DocumentTitleIsMissing extends InstructionFailed {
public function __construct(
Context $context,
private readonly File $document,
Throwable $previous = null,
?Throwable $previous = null,
) {
parent::__construct(
$context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ExampleFailed extends InstructionFailed {
public function __construct(
Context $context,
private readonly File $example,
Throwable $previous = null,
?Throwable $previous = null,
) {
parent::__construct(
$context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use function sprintf;

class TargetExecFailed extends InstructionFailed {
public function __construct(Context $context, Throwable $previous = null) {
public function __construct(Context $context, ?Throwable $previous = null) {
parent::__construct(
$context,
sprintf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use function sprintf;

class TargetIsNotDirective extends InstructionFailed {
public function __construct(Context $context, Throwable $previous = null) {
public function __construct(Context $context, ?Throwable $previous = null) {
parent::__construct(
$context,
sprintf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class PackageComposerJsonIsMissing extends InstructionFailed {
public function __construct(
Context $context,
private readonly Directory $package,
Throwable $previous = null,
?Throwable $previous = null,
) {
parent::__construct(
$context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function __construct(
Context $context,
private readonly Directory $package,
private readonly File $readme,
Throwable $previous = null,
?Throwable $previous = null,
) {
parent::__construct(
$context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function __construct(
Context $context,
private readonly Directory $package,
private readonly File $readme,
Throwable $previous = null,
?Throwable $previous = null,
) {
parent::__construct(
$context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use function sprintf;

class TemplateDataMissed extends InstructionFailed {
public function __construct(Context $context, Throwable $previous = null) {
public function __construct(Context $context, ?Throwable $previous = null) {
parent::__construct(
$context,
sprintf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class TemplateVariablesMissed extends InstructionFailed {
public function __construct(
Context $context,
private readonly array $variables,
Throwable $previous = null,
?Throwable $previous = null,
) {
parent::__construct(
$context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class TemplateVariablesUnused extends InstructionFailed {
public function __construct(
Context $context,
private readonly array $variables,
Throwable $previous = null,
?Throwable $previous = null,
) {
parent::__construct(
$context,
Expand Down
10 changes: 5 additions & 5 deletions packages/documentator/src/Utils/Git.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __construct(
*
* @return list<string>
*/
public function getTags(callable $filter = null, string $root = null): array {
public function getTags(?callable $filter = null, ?string $root = null): array {
$tags = $this->run(['git', 'tag', '--list'], $root);
$tags = explode("\n", $tags);
$tags = $filter ? array_filter($tags, $filter) : $tags;
Expand All @@ -30,22 +30,22 @@ public function getTags(callable $filter = null, string $root = null): array {
return $tags;
}

public function getFile(string $path, string $revision = 'HEAD', string $root = null): string {
public function getFile(string $path, string $revision = 'HEAD', ?string $root = null): string {
return $this->run(['git', 'show', "{$revision}:{$path}"], $root);
}

public function getBranch(string $root = null): string {
public function getBranch(?string $root = null): string {
return $this->run(['git', 'rev-parse', '--abbrev-ref=HEAD'], $root);
}

public function getRoot(string $root = null): string {
public function getRoot(?string $root = null): string {
return $this->run(['git', 'rev-parse', '--show-toplevel'], $root);
}

/**
* @param array<array-key, string>|string $command
*/
private function run(array|string $command, string $root = null): string {
private function run(array|string $command, ?string $root = null): string {
$process = $this->factory->newPendingProcess();
$process = $root !== null ? $process->path($root) : $process->command('');
$output = $process->run($command)->throw()->output();
Expand Down
2 changes: 1 addition & 1 deletion packages/documentator/src/Utils/Markdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ protected static function getText(string $string, ?AbstractBlock $node): ?string
*
* @return ?T
*/
protected static function getFirstNode(?Node $node, string $class, callable $filter = null): ?Node {
protected static function getFirstNode(?Node $node, string $class, ?callable $filter = null): ?Node {
// Null?
if ($node === null) {
return null;
Expand Down
2 changes: 1 addition & 1 deletion packages/eloquent/src/Exceptions/PropertyIsNotRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class PropertyIsNotRelation extends PackageException {
public function __construct(
protected Model $model,
protected string $property,
Throwable $previous = null,
?Throwable $previous = null,
) {
parent::__construct(sprintf(
'Property `%s::%s()` is not a relation.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
class ChunkedChangeSafeIterator extends IteratorImpl {
private string $column;

public function __construct(Builder $builder, string $column = null) {
public function __construct(Builder $builder, ?string $column = null) {
parent::__construct($builder);

$this->column = $column ?? $this->getDefaultColumn($builder);
Expand Down
4 changes: 2 additions & 2 deletions packages/eloquent/src/Mixins/EloquentBuilderMixin.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function orderByKeyDesc(): Closure {
* @return Closure(int=): ChunkedIterator<Model>
*/
public function getChunkedIterator(): Closure {
return function (int $chunk = null): ChunkedIterator {
return function (?int $chunk = null): ChunkedIterator {
/** @var Builder<Model> $this */
$iterator = new ChunkedIterator($this);

Expand All @@ -52,7 +52,7 @@ public function getChunkedIterator(): Closure {
* @return Closure(int=,string=): ChunkedChangeSafeIterator<Model>
*/
public function getChangeSafeIterator(): Closure {
return function (int $chunk = null, string $column = null): ChunkedChangeSafeIterator {
return function (?int $chunk = null, ?string $column = null): ChunkedChangeSafeIterator {
/** @var Builder<Model> $this */
$iterator = new ChunkedChangeSafeIterator($this, $column);

Expand Down
2 changes: 1 addition & 1 deletion packages/eloquent/src/PackageException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Throwable;

abstract class PackageException extends Exception {
public function __construct(string $message = '', Throwable $previous = null) {
public function __construct(string $message = '', ?Throwable $previous = null) {
parent::__construct($message, 0, $previous);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class FailedToCreateDateFormatter extends PackageException {
public function __construct(
protected string $type,
protected string|int|null $format,
Throwable $previous = null,
?Throwable $previous = null,
) {
parent::__construct(sprintf(
'Failed to create instance of `%s` for type `%s` with format `%s`.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class FailedToCreateNumberFormatter extends PackageException {
public function __construct(
protected string $type,
Throwable $previous = null,
?Throwable $previous = null,
) {
parent::__construct(sprintf(
'Failed to create instance of `%s` for type `%s`.',
Expand Down
2 changes: 1 addition & 1 deletion packages/formatter/src/Exceptions/FailedToFormatValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function __construct(
protected string $type,
protected int $errorCode,
protected string $errorMessage,
Throwable $previous = null,
?Throwable $previous = null,
) {
parent::__construct(sprintf(
'Formatting for type `%s` failed: `%s` (`%s`).',
Expand Down
Loading

0 comments on commit 8615ec2

Please sign in to comment.