Skip to content

Commit

Permalink
fix: Explicit nullable type
Browse files Browse the repository at this point in the history
Issue #1461
  • Loading branch information
lee-to committed Jan 9, 2025
1 parent 4d95bcc commit 5d4eef0
Show file tree
Hide file tree
Showing 30 changed files with 45 additions and 42 deletions.
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
->setRules([
'@PSR12' => true,
'native_function_invocation' => true,
'nullable_type_declaration_for_default_null_value' => true,
'array_syntax' => ['syntax' => 'short'],
'ordered_imports' => ['sort_algorithm' => 'alpha'],
'no_unused_imports' => true,
Expand Down
2 changes: 2 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
$rectorConfig->importShortClasses();
$rectorConfig->removeUnusedImports();

$rectorConfig->rule(Rector\Php84\Rector\Param\ExplicitNullableParamTypeRector::class);

$rectorConfig->sets([
LevelSetList::UP_TO_PHP_82,
SetList::CODE_QUALITY,
Expand Down
2 changes: 1 addition & 1 deletion src/Contracts/src/Core/CrudResourceContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
interface CrudResourceContract extends ResourceContract
{
public function getRoute(
string $name = null,
?string $name = null,
DataWrapperContract|int|string|null $key = null,
array $query = []
): string;
Expand Down
4 changes: 2 additions & 2 deletions src/Contracts/src/Core/DependencyInjection/FieldsContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function whenFieldsConditions(): static;
*/
public function findByColumn(
string $column,
FieldContract $default = null
?FieldContract $default = null
): ?FieldContract;

/**
Expand All @@ -69,7 +69,7 @@ public function findByColumn(
*/
public function findByClass(
string $class,
FieldContract $default = null
?FieldContract $default = null
): ?FieldContract;

public function wrapNames(string $name): static;
Expand Down
6 changes: 3 additions & 3 deletions src/Contracts/src/Core/PagesContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface PagesContract extends Enumerable
*/
public function findByType(
PageType $type,
PageContract $default = null
?PageContract $default = null
): ?PageContract;

/**
Expand All @@ -37,7 +37,7 @@ public function findByType(
*/
public function findByClass(
string $class,
PageContract $default = null
?PageContract $default = null
): ?PageContract;

/**
Expand All @@ -46,7 +46,7 @@ public function findByClass(
*/
public function findByUri(
string $uri,
PageContract $default = null
?PageContract $default = null
): ?PageContract;

public function activePage(): ?PageContract;
Expand Down
4 changes: 2 additions & 2 deletions src/Contracts/src/Core/ResourcesContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface ResourcesContract extends Enumerable
*/
public function findByUri(
string $uri,
ResourceContract $default = null
?ResourceContract $default = null
): ?ResourceContract;

/**
Expand All @@ -35,6 +35,6 @@ public function findByUri(
*/
public function findByClass(
string $class,
ResourceContract $default = null
?ResourceContract $default = null
): ?ResourceContract;
}
6 changes: 3 additions & 3 deletions src/Contracts/src/UI/Collection/ComponentsContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ public function onlyComponents(): static;

public function findForm(
string $name,
FormBuilderContract $default = null
?FormBuilderContract $default = null
): ?FormBuilderContract;

public function findTable(
string $name,
TableBuilderContract $default = null
?TableBuilderContract $default = null
): ?TableBuilderContract;

public function findByName(
string $name,
ComponentContract $default = null
?ComponentContract $default = null
): ?ComponentContract;
}
4 changes: 2 additions & 2 deletions src/Contracts/src/UI/FormElementContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function setParent(FormElementContract $field): static;

public function formName(?string $formName = null): static;

public function getIdentity(string $index = null): string;
public function getIdentity(?string $index = null): string;

public function getFormName(): ?string;

Expand Down Expand Up @@ -69,7 +69,7 @@ public function getDefaultIfExists(): mixed;

public function getRowIndex(): int;

public function getNameAttribute(string $index = null): string;
public function getNameAttribute(?string $index = null): string;

public function customWrapperAttributes(array $attributes): static;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface HasQuickFormElementAttributesContract
{
public function setNameAttribute(string $name): static;

public function getNameAttribute(string $index = null): string;
public function getNameAttribute(?string $index = null): string;

public function wrapName(string $wrapName): static;

Expand Down
6 changes: 3 additions & 3 deletions src/Core/src/Collections/Components.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function onlyFields(bool $withWrappers = false): FieldsContract
*/
public function findForm(
string $name,
FormBuilderContract $default = null
?FormBuilderContract $default = null
): ?FormBuilderContract {
return $this->onlyForms()->first(
static fn (FormBuilderContract $component): bool => $component->getName() === $name,
Expand All @@ -113,7 +113,7 @@ public function findForm(
*/
public function findTable(
string $name,
TableBuilderContract $default = null
?TableBuilderContract $default = null
): ?TableBuilderContract {
return $this->onlyTables()->first(
static fn (TableBuilderContract $component): bool => $component->getName() === $name,
Expand All @@ -126,7 +126,7 @@ public function findTable(
*/
public function findByName(
string $name,
ComponentContract $default = null
?ComponentContract $default = null
): ?ComponentContract {
return $this->onlyComponents()->first(
static fn (ComponentContract $component): bool => $component->getName() === $name,
Expand Down
6 changes: 3 additions & 3 deletions src/Core/src/Pages/Pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ public function setResource(ResourceContract $resource): Pages

public function findByType(
PageType $type,
PageContract $default = null
?PageContract $default = null
): ?PageContract {
return $this->first(static fn (PageContract $page): bool => $page->getPageType() === $type, $default);
}

public function findByClass(
string $class,
PageContract $default = null
?PageContract $default = null
): ?PageContract {
return $this->first(
static fn (PageContract $page): bool => $page::class === $class,
Expand Down Expand Up @@ -61,7 +61,7 @@ public function activePage(): ?PageContract

public function findByUri(
string $uri,
PageContract $default = null
?PageContract $default = null
): ?PageContract {
return $this->first(
static function (PageContract $page) use ($uri): bool {
Expand Down
4 changes: 2 additions & 2 deletions src/Core/src/Resources/Resources.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ final class Resources extends Collection implements ResourcesContract
{
public function findByUri(
string $uri,
ResourceContract $default = null
?ResourceContract $default = null
): ?ResourceContract {
return $this->first(
static fn (ResourceContract $resource): bool => $resource->getUriKey() === $uri,
Expand All @@ -22,7 +22,7 @@ public function findByUri(

public function findByClass(
string $class,
ResourceContract $default = null
?ResourceContract $default = null
): ?ResourceContract {
return $this->first(
static fn (ResourceContract $resource): bool => $resource::class === $class,
Expand Down
4 changes: 2 additions & 2 deletions src/Core/src/Storage/FileStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ public function storeAs(string $path, mixed $file, $name = null, array $options
return $this->store($path, $file, $options);
}

public function getFiles(string $directory = null, bool $recursive = false): array
public function getFiles(?string $directory = null, bool $recursive = false): array
{
return iterator_to_array(
Finder::create()->files()->in($directory)->depth(0)->sortByName(),
false
);
}

public function getDirectories(string $directory = null, bool $recursive = false): array
public function getDirectories(?string $directory = null, bool $recursive = false): array
{
$directories = [];

Expand Down
2 changes: 1 addition & 1 deletion src/Laravel/src/Buttons/MassDeleteButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class MassDeleteButton
{
public static function for(
CrudResource $resource,
string $componentName = null,
?string $componentName = null,
?string $redirectAfterDelete = null,
bool $isAsync = true,
string $modalName = 'resource-mass-delete-modal',
Expand Down
2 changes: 1 addition & 1 deletion src/Laravel/src/Collections/Fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function detailFields(bool $withOutside = false, bool $onlyOutside = fals
*/
public function findByRelation(
string $relation,
ModelRelationField $default = null
?ModelRelationField $default = null
): ?ModelRelationField {
return $this->onlyRelationFields()->first(
static fn (ModelRelationField $field): bool => $field->getRelationName() === $relation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function getAsyncSearchCount(): int;
public function getAsyncSearchValueCallback(): ?Closure;

public function asyncSearch(
string $column = null,
?string $column = null,
?Closure $searchQuery = null,
?Closure $formatted = null,
?string $associatedWith = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public function getGuard(): string
return $this->get('auth.guard', 'moonshine');
}

public function getUserField(string $field, string $default = null): string|false
public function getUserField(string $field, ?string $default = null): string|false
{
return $this->get("user_fields.$field", $default ?? $field);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Laravel/src/Handlers/Handlers.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class Handlers extends Collection
{
public function findByUri(
string $uri,
Handler $default = null
?Handler $default = null
): ?Handler {
return $this->first(
static fn (Handler $handler): bool => $handler->getUriKey() === $uri,
Expand Down
2 changes: 1 addition & 1 deletion src/Laravel/src/Http/Controllers/MoonShineController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(
protected function json(
string $message = '',
array $data = [],
string $redirect = null,
?string $redirect = null,
ToastType $messageType = ToastType::SUCCESS,
int $status = Response::HTTP_OK
): JsonResponse {
Expand Down
2 changes: 1 addition & 1 deletion src/Laravel/src/Storage/LaravelStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function getFiles(string $directory, bool $recursive = false): array
return $this->filesystem->files($directory, $recursive);
}

public function getDirectories(string $directory = null, bool $recursive = false): array
public function getDirectories(?string $directory = null, bool $recursive = false): array
{
return $this->filesystem->directories($directory, $recursive);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Laravel/src/Traits/Fields/WithAsyncSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public function getAsyncSearchOption(Model $model, ?string $searchColumn = null)
* @param ?Closure(mixed $data, FieldContract $field): static $formatted
*/
public function asyncSearch(
string $column = null,
?string $column = null,
?Closure $searchQuery = null,
?Closure $formatted = null,
?string $associatedWith = null,
Expand Down
2 changes: 1 addition & 1 deletion src/Laravel/src/Traits/Resource/ResourceCrudRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ trait ResourceCrudRouter
* @param DataWrapperContract<T>|int|string|null $key
*/
public function getRoute(
string $name = null,
?string $name = null,
DataWrapperContract|int|string|null $key = null,
array $query = []
): string {
Expand Down
2 changes: 1 addition & 1 deletion src/MenuManager/src/MenuGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class MenuGroup extends MenuElement
public function __construct(
Closure|string $label,
protected iterable $items = [],
string $icon = null,
?string $icon = null,
) {
parent::__construct();

Expand Down
2 changes: 1 addition & 1 deletion src/MenuManager/src/MenuItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class MenuItem extends MenuElement
final public function __construct(
Closure|string $label,
protected Closure|MenuFillerContract|string $filler,
string $icon = null,
?string $icon = null,
Closure|bool $blank = false
) {
parent::__construct();
Expand Down
4 changes: 2 additions & 2 deletions src/UI/src/Collections/Fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public function extractLabels(): array
*/
public function findByColumn(
string $column,
FieldContract $default = null
?FieldContract $default = null
): ?FieldContract {
return $this->first(
static fn (FieldContract $field): bool => $field->getColumn() === $column,
Expand All @@ -328,7 +328,7 @@ public function findByColumn(

public function findByClass(
string $class,
FieldContract $default = null
?FieldContract $default = null
): ?FieldContract {
return $this->first(
static fn (FieldContract $field): bool => $field::class === $class,
Expand Down
2 changes: 1 addition & 1 deletion src/UI/src/Fields/FormElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public function setParent(FormElementContract $field): static
return $this;
}

public function getIdentity(string $index = null): string
public function getIdentity(?string $index = null): string
{
return (string) str($this->getNameAttribute($index))
->replace(['[', ']'], '_')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function setNameAttribute(string $name): static
return $this;
}

public function getNameAttribute(string $index = null): string
public function getNameAttribute(?string $index = null): string
{
return $this->prepareNameAttribute($index);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Expectations.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
->toBe(['onAfterDestroy']);
});

expect()->extend('hasFields', fn (array $fields = null) => expect($this->value)
expect()->extend('hasFields', fn (?array $fields = null) => expect($this->value)
->toBeCollection()
->toHaveCount($fields ? \count($fields) : 0));
2 changes: 1 addition & 1 deletion tests/Feature/ComponentsEqualsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function compare(
array $parameters = [],
array $attributes = [],
string $slot = '',
string $alias = null
?string $alias = null
): void {
if ($attributes === []) {
$attributes = [
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/Resources/TestResourceBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

class TestResourceBuilder
{
public static function new(string $model = null): TestResource
public static function new(?string $model = null): TestResource
{
$resource = app(TestResource::class);

Expand Down

0 comments on commit 5d4eef0

Please sign in to comment.