diff --git a/packages/actions/src/AssociateAction.php b/packages/actions/src/AssociateAction.php index e9ecd1c39a2..8d029b37c2e 100644 --- a/packages/actions/src/AssociateAction.php +++ b/packages/actions/src/AssociateAction.php @@ -70,7 +70,7 @@ protected function setUp(): void $this->form(fn (): array => [$this->getRecordSelect()]); - $this->action(function (array $arguments, array $data, Schema $form, Table $table): void { + $this->action(function (array $arguments, array $data, Schema $schema, Table $table): void { /** @var HasMany | MorphMany $relationship */ $relationship = Relation::noConstraints(fn () => $table->getRelationship()); @@ -99,7 +99,7 @@ protected function setUp(): void $this->record(null); - $form->fill(); + $schema->fill(); $this->halt(); diff --git a/packages/actions/src/AttachAction.php b/packages/actions/src/AttachAction.php index cc0454ecbe8..d9827caa6cb 100644 --- a/packages/actions/src/AttachAction.php +++ b/packages/actions/src/AttachAction.php @@ -70,7 +70,7 @@ protected function setUp(): void $this->form(fn (): array => [$this->getRecordSelect()]); - $this->action(function (array $arguments, array $data, Schema $form, Table $table): void { + $this->action(function (array $arguments, array $data, Schema $schema, Table $table): void { /** @var BelongsToMany $relationship */ $relationship = Relation::noConstraints(fn () => $table->getRelationship()); @@ -101,7 +101,7 @@ protected function setUp(): void $this->record(null); - $form->fill(); + $schema->fill(); $this->halt(); diff --git a/packages/actions/src/Concerns/CanBeMounted.php b/packages/actions/src/Concerns/CanBeMounted.php index 20b58dfcfdc..18f70d6535c 100644 --- a/packages/actions/src/Concerns/CanBeMounted.php +++ b/packages/actions/src/Concerns/CanBeMounted.php @@ -29,8 +29,8 @@ public function mountUsing(?Closure $callback): static */ public function fillForm(array | Closure $data): static { - $this->mountUsing(function (?Schema $form) use ($data): void { - $form?->fill($this->evaluate($data)); + $this->mountUsing(function (?Schema $schema) use ($data): void { + $schema?->fill($this->evaluate($data)); }); return $this; @@ -38,12 +38,12 @@ public function fillForm(array | Closure $data): static public function getMountUsing(): Closure { - return $this->mountUsing ?? static function (?Schema $form = null): void { - if (! $form) { + return $this->mountUsing ?? static function (?Schema $schema = null): void { + if (! $schema) { return; } - $form->fill(); + $schema->fill(); }; } } diff --git a/packages/actions/src/Concerns/HasForm.php b/packages/actions/src/Concerns/HasForm.php index 2e214a25d72..438b4324d5c 100644 --- a/packages/actions/src/Concerns/HasForm.php +++ b/packages/actions/src/Concerns/HasForm.php @@ -49,9 +49,9 @@ public function form(array | Closure | null $form): static /** * @deprecated Use `getSchema()` instead. */ - public function getForm(Schema $form): ?Schema + public function getForm(Schema $schema): ?Schema { - return $this->getSchema($form); + return $this->getSchema($schema); } public function mutateFormDataUsing(?Closure $callback): static diff --git a/packages/actions/src/CreateAction.php b/packages/actions/src/CreateAction.php index c9b5e159a74..4810d0abb43 100644 --- a/packages/actions/src/CreateAction.php +++ b/packages/actions/src/CreateAction.php @@ -54,10 +54,10 @@ protected function setUp(): void $this->record(null); - $this->action(function (array $arguments, Schema $form): void { + $this->action(function (array $arguments, Schema $schema): void { if ($arguments['another'] ?? false) { $preserveRawState = $this->evaluate($this->preserveFormDataWhenCreatingAnotherUsing, [ - 'data' => $form->getRawState(), + 'data' => $schema->getRawState(), ]) ?? []; } @@ -104,7 +104,7 @@ protected function setUp(): void }); $this->record($record); - $form->model($record)->saveRelationships(); + $schema->model($record)->saveRelationships(); if ($arguments['another'] ?? false) { $this->callAfter(); @@ -113,12 +113,12 @@ protected function setUp(): void $this->record(null); // Ensure that the form record is anonymized so that relationships aren't loaded. - $form->model($model); + $schema->model($model); - $form->fill(); + $schema->fill(); - $form->rawState([ - ...$form->getRawState(), + $schema->rawState([ + ...$schema->getRawState(), ...$preserveRawState ?? [], ]); diff --git a/packages/forms/src/Components/Select.php b/packages/forms/src/Components/Select.php index 3b719304f44..7489b5bd6a8 100644 --- a/packages/forms/src/Components/Select.php +++ b/packages/forms/src/Components/Select.php @@ -281,19 +281,19 @@ public function getCreateOptionAction(): ?Action $action = Action::make($this->getCreateOptionActionName()) ->label(__('filament-forms::components.select.actions.create_option.label')) - ->form(function (Select $component, Schema $form): array | Schema | null { - return $component->getCreateOptionActionForm($form->model( + ->form(function (Select $component, Schema $schema): array | Schema | null { + return $component->getCreateOptionActionForm($schema->model( $component->getRelationship() ? $component->getRelationship()->getModel()::class : null, )); }) - ->action(static function (Action $action, array $arguments, Select $component, array $data, Schema $form): void { + ->action(static function (Action $action, array $arguments, Select $component, array $data, Schema $schema): void { if (! $component->getCreateOptionUsing()) { throw new Exception("Select field [{$component->getStatePath()}] must have a [createOptionUsing()] closure set."); } $createdOptionKey = $component->evaluate($component->getCreateOptionUsing(), [ 'data' => $data, - 'form' => $form, + 'form' => $schema, ]); $state = $component->isMultiple() @@ -312,7 +312,7 @@ public function getCreateOptionAction(): ?Action $action->callAfter(); - $form->fill(); + $schema->fill(); $action->halt(); }) @@ -365,9 +365,9 @@ public function editOptionAction(?Closure $callback): static /** * @return array | Schema | null */ - public function getCreateOptionActionForm(Schema $form): array | Schema | null + public function getCreateOptionActionForm(Schema $schema): array | Schema | null { - return $this->evaluate($this->createOptionActionForm, ['form' => $form]); + return $this->evaluate($this->createOptionActionForm, ['form' => $schema]); } public function hasCreateOptionActionFormSchema(): bool @@ -378,9 +378,9 @@ public function hasCreateOptionActionFormSchema(): bool /** * @return array | Schema | null */ - public function getEditOptionActionForm(Schema $form): array | Schema | null + public function getEditOptionActionForm(Schema $schema): array | Schema | null { - return $this->evaluate($this->editOptionActionForm, ['form' => $form]); + return $this->evaluate($this->editOptionActionForm, ['form' => $schema]); } public function hasEditOptionActionFormSchema(): bool @@ -436,20 +436,20 @@ public function getEditOptionAction(): ?Action $action = Action::make($this->getEditOptionActionName()) ->label(__('filament-forms::components.select.actions.edit_option.label')) - ->form(function (Select $component, Schema $form): array | Schema | null { + ->form(function (Select $component, Schema $schema): array | Schema | null { return $component->getEditOptionActionForm( - $form->model($component->getSelectedRecord()), + $schema->model($component->getSelectedRecord()), ); }) ->fillForm($this->getEditOptionActionFormData()) - ->action(static function (Action $action, array $arguments, Select $component, array $data, Schema $form): void { + ->action(static function (Action $action, array $arguments, Select $component, array $data, Schema $schema): void { if (! $component->getUpdateOptionUsing()) { throw new Exception("Select field [{$component->getStatePath()}] must have a [updateOptionUsing()] closure set."); } $component->evaluate($component->getUpdateOptionUsing(), [ 'data' => $data, - 'form' => $form, + 'form' => $schema, ]); $component->refreshSelectedOptionLabel(); @@ -1061,12 +1061,12 @@ public function relationship(string | Closure | null $name = null, string | Clos $relationship->syncWithPivotValues($state, $pivotData, detaching: false); }); - $this->createOptionUsing(static function (Select $component, array $data, Schema $form) { + $this->createOptionUsing(static function (Select $component, array $data, Schema $schema) { $record = $component->getRelationship()->getRelated(); $record->fill($data); $record->save(); - $form->model($record)->saveRelationships(); + $schema->model($record)->saveRelationships(); return $record->getKey(); }); @@ -1075,8 +1075,8 @@ public function relationship(string | Closure | null $name = null, string | Clos return $component->getSelectedRecord()?->attributesToArray(); }); - $this->updateOptionUsing(static function (array $data, Schema $form): void { - $form->getRecord()?->update($data); + $this->updateOptionUsing(static function (array $data, Schema $schema): void { + $schema->getRecord()?->update($data); }); $this->dehydrated(fn (Select $component): bool => ! $component->isMultiple()); diff --git a/packages/forms/src/Concerns/InteractsWithForms.php b/packages/forms/src/Concerns/InteractsWithForms.php index 8fd13a1a86a..12f2f2a373c 100644 --- a/packages/forms/src/Concerns/InteractsWithForms.php +++ b/packages/forms/src/Concerns/InteractsWithForms.php @@ -71,7 +71,7 @@ protected function cacheForms(): array return [$form => $this->{$form}($this->makeSchema())]; }) ->forget('') - ->map(fn (Schema $form, string $formName) => $form->key($formName)) + ->map(fn (Schema $schema, string $formName) => $schema->key($formName)) ->all(), ]; @@ -140,9 +140,9 @@ protected function getForms(): array ]; } - public function form(Schema $form): Schema + public function form(Schema $schema): Schema { - return $form + return $schema ->schema($this->getFormSchema()) ->model($this->getFormModel()) ->statePath($this->getFormStatePath()) diff --git a/packages/infolists/src/Concerns/InteractsWithInfolists.php b/packages/infolists/src/Concerns/InteractsWithInfolists.php index 08fa8ffa371..624264b5fa5 100644 --- a/packages/infolists/src/Concerns/InteractsWithInfolists.php +++ b/packages/infolists/src/Concerns/InteractsWithInfolists.php @@ -18,9 +18,9 @@ public function getInfolist(string $name): ?Schema /** * @deprecated Use `cacheSchema()` instead. */ - protected function cacheInfolist(string $name, Schema $infolist): ?Schema + protected function cacheInfolist(string $name, Schema $schema): ?Schema { - return $this->cacheSchema($name, $infolist); + return $this->cacheSchema($name, $schema); } /** diff --git a/packages/panels/src/Auth/Pages/EditProfile.php b/packages/panels/src/Auth/Pages/EditProfile.php index d503ef25078..5e2ad7bc19d 100644 --- a/packages/panels/src/Auth/Pages/EditProfile.php +++ b/packages/panels/src/Auth/Pages/EditProfile.php @@ -336,9 +336,9 @@ protected function getCurrentPasswordFormComponent(): Component ->dehydrated(false); } - public function form(Schema $form): Schema + public function form(Schema $schema): Schema { - return $form; + return $schema; } /** diff --git a/packages/panels/src/Auth/Pages/Login.php b/packages/panels/src/Auth/Pages/Login.php index eb9142d2871..8fbb8abf6dc 100644 --- a/packages/panels/src/Auth/Pages/Login.php +++ b/packages/panels/src/Auth/Pages/Login.php @@ -151,14 +151,14 @@ protected function throwFailureValidationException(): never ]); } - public function form(Schema $form): Schema + public function form(Schema $schema): Schema { - return $form; + return $schema; } - public function multiFactorChallengeForm(Schema $form): Schema + public function multiFactorChallengeForm(Schema $schema): Schema { - return $form; + return $schema; } /** diff --git a/packages/panels/src/Auth/Pages/PasswordReset/RequestPasswordReset.php b/packages/panels/src/Auth/Pages/PasswordReset/RequestPasswordReset.php index be0dead7146..39038ac7a3b 100644 --- a/packages/panels/src/Auth/Pages/PasswordReset/RequestPasswordReset.php +++ b/packages/panels/src/Auth/Pages/PasswordReset/RequestPasswordReset.php @@ -106,9 +106,9 @@ protected function getRateLimitedNotification(TooManyRequestsException $exceptio ->danger(); } - public function form(Schema $form): Schema + public function form(Schema $schema): Schema { - return $form; + return $schema; } /** diff --git a/packages/panels/src/Auth/Pages/PasswordReset/ResetPassword.php b/packages/panels/src/Auth/Pages/PasswordReset/ResetPassword.php index efef88c4976..1d1de0d5085 100644 --- a/packages/panels/src/Auth/Pages/PasswordReset/ResetPassword.php +++ b/packages/panels/src/Auth/Pages/PasswordReset/ResetPassword.php @@ -117,9 +117,9 @@ protected function getRateLimitedNotification(TooManyRequestsException $exceptio ->danger(); } - public function form(Schema $form): Schema + public function form(Schema $schema): Schema { - return $form + return $schema ->schema([ $this->getEmailFormComponent(), $this->getPasswordFormComponent(), diff --git a/packages/panels/src/Auth/Pages/Register.php b/packages/panels/src/Auth/Pages/Register.php index c029cce880a..a1277a40c1a 100644 --- a/packages/panels/src/Auth/Pages/Register.php +++ b/packages/panels/src/Auth/Pages/Register.php @@ -148,9 +148,9 @@ protected function sendEmailVerificationNotification(Model $user): void $user->notify($notification); } - public function form(Schema $form): Schema + public function form(Schema $schema): Schema { - return $form; + return $schema; } /** diff --git a/packages/panels/src/Pages/Dashboard/Concerns/HasFiltersForm.php b/packages/panels/src/Pages/Dashboard/Concerns/HasFiltersForm.php index d4a61a6edb2..b3d744e7002 100644 --- a/packages/panels/src/Pages/Dashboard/Concerns/HasFiltersForm.php +++ b/packages/panels/src/Pages/Dashboard/Concerns/HasFiltersForm.php @@ -15,9 +15,9 @@ protected function getHasFiltersForms(): array ]; } - public function filtersForm(Schema $form): Schema + public function filtersForm(Schema $schema): Schema { - return $form; + return $schema; } public function getFiltersForm(): Schema diff --git a/packages/panels/src/Pages/Tenancy/EditTenantProfile.php b/packages/panels/src/Pages/Tenancy/EditTenantProfile.php index a029206e4cc..1a3876a88e1 100644 --- a/packages/panels/src/Pages/Tenancy/EditTenantProfile.php +++ b/packages/panels/src/Pages/Tenancy/EditTenantProfile.php @@ -177,9 +177,9 @@ protected function getRedirectUrl(): ?string return null; } - public function form(Schema $form): Schema + public function form(Schema $schema): Schema { - return $form; + return $schema; } /** diff --git a/packages/panels/src/Pages/Tenancy/RegisterTenant.php b/packages/panels/src/Pages/Tenancy/RegisterTenant.php index e2caa736b09..dfe924bea08 100644 --- a/packages/panels/src/Pages/Tenancy/RegisterTenant.php +++ b/packages/panels/src/Pages/Tenancy/RegisterTenant.php @@ -120,9 +120,9 @@ protected function getRedirectUrl(): ?string return Filament::getUrl($this->tenant); } - public function form(Schema $form): Schema + public function form(Schema $schema): Schema { - return $form; + return $schema; } /** diff --git a/packages/panels/src/Resources/Concerns/InteractsWithRelationshipTable.php b/packages/panels/src/Resources/Concerns/InteractsWithRelationshipTable.php index 3adc15f4c8b..d6cbd225aa8 100644 --- a/packages/panels/src/Resources/Concerns/InteractsWithRelationshipTable.php +++ b/packages/panels/src/Resources/Concerns/InteractsWithRelationshipTable.php @@ -67,30 +67,30 @@ public static function getRelationshipName(): string return static::getRelatedResource()::getParentResourceRegistration()->getRelationshipName(); } - public function configureForm(Schema $form): Schema + public function configureForm(Schema $schema): Schema { - $form->columns(2); + $schema->columns(2); if (static::getRelatedResource()) { - static::getRelatedResource()::form($form); + static::getRelatedResource()::form($schema); } - $this->form($form); + $this->form($schema); - return $form; + return $schema; } - public function configureInfolist(Schema $infolist): Schema + public function configureInfolist(Schema $schema): Schema { - $infolist->columns(2); + $schema->columns(2); if (static::getRelatedResource()) { - static::getRelatedResource()::infolist($infolist); + static::getRelatedResource()::infolist($schema); } - $this->infolist($infolist); + $this->infolist($schema); - return $infolist; + return $schema; } protected function makeTable(): Table diff --git a/packages/panels/src/Resources/Pages/Concerns/HasWizard.php b/packages/panels/src/Resources/Pages/Concerns/HasWizard.php index 03d3d40c33f..0d3954f0c7e 100644 --- a/packages/panels/src/Resources/Pages/Concerns/HasWizard.php +++ b/packages/panels/src/Resources/Pages/Concerns/HasWizard.php @@ -14,9 +14,9 @@ public function getStartStep(): int return 1; } - public function form(Schema $form): Schema + public function form(Schema $schema): Schema { - return parent::form($form) + return parent::form($schema) ->schema([ Wizard::make($this->getSteps()) ->startOnStep($this->getStartStep()) diff --git a/packages/panels/src/Resources/Pages/CreateRecord.php b/packages/panels/src/Resources/Pages/CreateRecord.php index 5d4df1af1c4..58f564702d9 100644 --- a/packages/panels/src/Resources/Pages/CreateRecord.php +++ b/packages/panels/src/Resources/Pages/CreateRecord.php @@ -261,9 +261,9 @@ public function getTitle(): string | Htmlable ]); } - public function form(Schema $form): Schema + public function form(Schema $schema): Schema { - return $form; + return $schema; } /** @@ -281,16 +281,16 @@ protected function getForms(): array ]; } - public function configureForm(Schema $form): Schema + public function configureForm(Schema $schema): Schema { - $form->columns($this->hasInlineLabels() ? 1 : 2); - $form->inlineLabel($this->hasInlineLabels()); + $schema->columns($this->hasInlineLabels() ? 1 : 2); + $schema->inlineLabel($this->hasInlineLabels()); - static::getResource()::form($form); + static::getResource()::form($schema); - $this->form($form); + $this->form($schema); - return $form; + return $schema; } protected function getRedirectUrl(): string diff --git a/packages/panels/src/Resources/Pages/EditRecord.php b/packages/panels/src/Resources/Pages/EditRecord.php index 1dad33bba4b..389dd8e9b42 100644 --- a/packages/panels/src/Resources/Pages/EditRecord.php +++ b/packages/panels/src/Resources/Pages/EditRecord.php @@ -255,16 +255,16 @@ protected function mutateFormDataBeforeSave(array $data): array return $data; } - public function configureForm(Schema $form): Schema + public function configureForm(Schema $schema): Schema { - $form->columns($this->hasInlineLabels() ? 1 : 2); - $form->inlineLabel($this->hasInlineLabels()); + $schema->columns($this->hasInlineLabels() ? 1 : 2); + $schema->inlineLabel($this->hasInlineLabels()); - static::getResource()::form($form); + static::getResource()::form($schema); - $this->form($form); + $this->form($schema); - return $form; + return $schema; } public function getDefaultActionSchemaResolver(Action $action): ?Closure @@ -326,9 +326,9 @@ protected function getCancelFormAction(): Action ->color('gray'); } - public function form(Schema $form): Schema + public function form(Schema $schema): Schema { - return $form; + return $schema; } /** diff --git a/packages/panels/src/Resources/Pages/ListRecords.php b/packages/panels/src/Resources/Pages/ListRecords.php index ab9948aeaa8..6cfdb72612b 100644 --- a/packages/panels/src/Resources/Pages/ListRecords.php +++ b/packages/panels/src/Resources/Pages/ListRecords.php @@ -82,14 +82,14 @@ public function getTitle(): string | Htmlable return static::$title ?? static::getResource()::getTitleCasePluralModelLabel(); } - public function form(Schema $form): Schema + public function form(Schema $schema): Schema { - return static::getResource()::form($form); + return static::getResource()::form($schema); } - public function infolist(Schema $infolist): Schema + public function infolist(Schema $schema): Schema { - return static::getResource()::infolist($infolist); + return static::getResource()::infolist($schema); } public function getDefaultActionSchemaResolver(Action $action): ?Closure diff --git a/packages/panels/src/Resources/Pages/ManageRelatedRecords.php b/packages/panels/src/Resources/Pages/ManageRelatedRecords.php index 5145ecc5d6d..418a293e354 100644 --- a/packages/panels/src/Resources/Pages/ManageRelatedRecords.php +++ b/packages/panels/src/Resources/Pages/ManageRelatedRecords.php @@ -155,14 +155,14 @@ public function getOwnerRecord(): Model return $this->getRecord(); } - public function form(Schema $form): Schema + public function form(Schema $schema): Schema { - return $form; + return $schema; } - public function infolist(Schema $infolist): Schema + public function infolist(Schema $schema): Schema { - return $infolist; + return $schema; } /** diff --git a/packages/panels/src/Resources/Pages/ViewRecord.php b/packages/panels/src/Resources/Pages/ViewRecord.php index 179f6d2e76c..c25ebad3ac5 100644 --- a/packages/panels/src/Resources/Pages/ViewRecord.php +++ b/packages/panels/src/Resources/Pages/ViewRecord.php @@ -134,31 +134,31 @@ public function getTitle(): string | Htmlable ]); } - public function form(Schema $form): Schema + public function form(Schema $schema): Schema { - return $form; + return $schema; } - public function configureForm(Schema $form): Schema + public function configureForm(Schema $schema): Schema { - $form->columns($this->hasInlineLabels() ? 1 : 2); - $form->inlineLabel($this->hasInlineLabels()); + $schema->columns($this->hasInlineLabels() ? 1 : 2); + $schema->inlineLabel($this->hasInlineLabels()); - static::getResource()::form($form); + static::getResource()::form($schema); - $this->form($form); + $this->form($schema); - return $form; + return $schema; } - public function configureInfolist(Schema $infolist): Schema + public function configureInfolist(Schema $schema): Schema { - $infolist->columns($this->hasInlineLabels() ? 1 : 2); - $infolist->inlineLabel($this->hasInlineLabels()); + $schema->columns($this->hasInlineLabels() ? 1 : 2); + $schema->inlineLabel($this->hasInlineLabels()); - static::getResource()::infolist($infolist); + static::getResource()::infolist($schema); - return $infolist; + return $schema; } /** diff --git a/packages/panels/src/Resources/RelationManagers/RelationManager.php b/packages/panels/src/Resources/RelationManagers/RelationManager.php index f7101115919..378ce35d6f0 100644 --- a/packages/panels/src/Resources/RelationManagers/RelationManager.php +++ b/packages/panels/src/Resources/RelationManagers/RelationManager.php @@ -201,14 +201,14 @@ public function getOwnerRecord(): Model return $this->ownerRecord; } - public function form(Schema $form): Schema + public function form(Schema $schema): Schema { - return $form; + return $schema; } - public function infolist(Schema $infolist): Schema + public function infolist(Schema $schema): Schema { - return $infolist; + return $schema; } public function isReadOnly(): bool diff --git a/packages/panels/src/Resources/Resource.php b/packages/panels/src/Resources/Resource.php index 32c84865c7c..7f2df69acfa 100644 --- a/packages/panels/src/Resources/Resource.php +++ b/packages/panels/src/Resources/Resource.php @@ -37,14 +37,14 @@ abstract class Resource */ protected static ?string $model = null; - public static function form(Schema $form): Schema + public static function form(Schema $schema): Schema { - return $form; + return $schema; } - public static function infolist(Schema $infolist): Schema + public static function infolist(Schema $schema): Schema { - return $infolist; + return $schema; } public static function table(Table $table): Table diff --git a/packages/schemas/src/Components/Concerns/BelongsToContainer.php b/packages/schemas/src/Components/Concerns/BelongsToContainer.php index 3a7b31411b0..a26fe909845 100644 --- a/packages/schemas/src/Components/Concerns/BelongsToContainer.php +++ b/packages/schemas/src/Components/Concerns/BelongsToContainer.php @@ -10,9 +10,9 @@ trait BelongsToContainer { protected Schema $container; - public function container(Schema $container): static + public function container(Schema $schema): static { - $this->container = $container; + $this->container = $schema; return $this; } diff --git a/packages/schemas/src/Components/Concerns/CanBeCollapsed.php b/packages/schemas/src/Components/Concerns/CanBeCollapsed.php index 4ef30a93e40..e480acbc5b6 100644 --- a/packages/schemas/src/Components/Concerns/CanBeCollapsed.php +++ b/packages/schemas/src/Components/Concerns/CanBeCollapsed.php @@ -24,9 +24,9 @@ public function collapsed(bool | Closure $condition = true, bool $shouldMakeComp return $this; } - public function isCollapsed(?Schema $item = null): bool + public function isCollapsed(?Schema $schema = null): bool { - return (bool) $this->evaluate($this->isCollapsed, ['item' => $item]); + return (bool) $this->evaluate($this->isCollapsed, ['item' => $schema]); } public function collapsible(bool | Closure | null $condition = true): static diff --git a/packages/spatie-laravel-settings-plugin/src/Pages/SettingsPage.php b/packages/spatie-laravel-settings-plugin/src/Pages/SettingsPage.php index 881e00f821f..fe263af4270 100644 --- a/packages/spatie-laravel-settings-plugin/src/Pages/SettingsPage.php +++ b/packages/spatie-laravel-settings-plugin/src/Pages/SettingsPage.php @@ -175,9 +175,9 @@ public function getSubmitFormAction(): Action return $this->getSaveFormAction(); } - public function form(Schema $form): Schema + public function form(Schema $schema): Schema { - return $form; + return $schema; } /** diff --git a/packages/tables/src/Filters/QueryBuilder.php b/packages/tables/src/Filters/QueryBuilder.php index 9b5cdd2f81a..ee0f1fc50c2 100644 --- a/packages/tables/src/Filters/QueryBuilder.php +++ b/packages/tables/src/Filters/QueryBuilder.php @@ -223,9 +223,9 @@ protected function getRuleBuilder(): RuleBuilder return $builder; } - protected function getNestedRuleBuilder(Schema $ruleBuilderBlockContainer, string $orGroupIndex): RuleBuilder + protected function getNestedRuleBuilder(Schema $schema, string $orGroupIndex): RuleBuilder { - $builder = $ruleBuilderBlockContainer + $builder = $schema ->getComponent(fn (Component $component): bool => $component instanceof Repeater) ->getChildComponentContainer($orGroupIndex) ->getComponent(fn (Component $component): bool => $component instanceof RuleBuilder); @@ -240,7 +240,7 @@ protected function getNestedRuleBuilder(Schema $ruleBuilderBlockContainer, strin /** * @param array $rule */ - protected function tapOperatorFromRule(array $rule, Schema $ruleBuilderBlockContainer, Closure $callback): void + protected function tapOperatorFromRule(array $rule, Schema $schema, Closure $callback): void { $constraint = $this->getConstraint($rule['type']); @@ -263,7 +263,7 @@ protected function tapOperatorFromRule(array $rule, Schema $ruleBuilderBlockCont } try { - $ruleBuilderBlockContainer->validate(); + $schema->validate(); } catch (ValidationException) { return; } diff --git a/packages/tables/src/Filters/QueryBuilder/Forms/Components/RuleBuilder.php b/packages/tables/src/Filters/QueryBuilder/Forms/Components/RuleBuilder.php index 5c106c26857..7362761599b 100644 --- a/packages/tables/src/Filters/QueryBuilder/Forms/Components/RuleBuilder.php +++ b/packages/tables/src/Filters/QueryBuilder/Forms/Components/RuleBuilder.php @@ -50,7 +50,7 @@ protected function setUp(): void } $itemLabels = collect($repeater->getItems()) - ->map(fn (Schema $item, string $itemUuid): string => $repeater->getItemLabel($itemUuid)); + ->map(fn (Schema $schema, string $itemUuid): string => $repeater->getItemLabel($itemUuid)); if ($itemLabels->count() === 1) { return $itemLabels->first(); @@ -75,22 +75,22 @@ protected function setUp(): void ->collapsible() ->expandAllAction(fn (Action $action) => $action->hidden()) ->collapseAllAction(fn (Action $action) => $action->hidden()) - ->itemLabel(function (Schema $item): string { - $builder = $item->getComponent(fn (Component $component): bool => $component instanceof RuleBuilder); + ->itemLabel(function (Schema $schema): string { + $builder = $schema->getComponent(fn (Component $component): bool => $component instanceof RuleBuilder); if (! ($builder instanceof RuleBuilder)) { throw new Exception('No rule builder component found.'); } $blockLabels = collect($builder->getItems()) - ->map(function (Schema $item, string $blockUuid): string { - $block = $item->getParentComponent(); + ->map(function (Schema $schema, string $blockUuid): string { + $block = $schema->getParentComponent(); if (! ($block instanceof Builder\Block)) { throw new Exception('No block component found.'); } - return $block->getLabel($item->getRawState(), $blockUuid); + return $block->getLabel($schema->getRawState(), $blockUuid); }); if ($blockLabels->isEmpty()) { diff --git a/packages/upgrade/src/Rector/RenameSchemaParamToMatchTypeRector.php b/packages/upgrade/src/Rector/RenameSchemaParamToMatchTypeRector.php new file mode 100644 index 00000000000..953ef3d75d7 --- /dev/null +++ b/packages/upgrade/src/Rector/RenameSchemaParamToMatchTypeRector.php @@ -0,0 +1,132 @@ +breakingVariableRenameGuard = $breakingVariableRenameGuard; + $this->expectedNameResolver = $expectedNameResolver; + $this->matchParamTypeExpectedNameResolver = $matchParamTypeExpectedNameResolver; + $this->paramRenameFactory = $paramRenameFactory; + $this->paramRenamer = $paramRenamer; + } + + public function getRuleDefinition(): RuleDefinition + { + return new RuleDefinition('Rename param to match ClassType', []); + } + + /** + * @return array> + */ + public function getNodeTypes(): array + { + return [ClassMethod::class, Function_::class, Closure::class, ArrowFunction::class]; + } + + /** + * @param ClassMethod|Function_|Closure|ArrowFunction $node + */ + public function refactor(Node $node): ?Node + { + $this->hasChanged = \false; + foreach ($node->params as $param) { + if ((! $param->type) || (! $this->isName($param->type, Schema::class))) { + continue; + } + $expectedName = $this->expectedNameResolver->resolveForParamIfNotYet($param); + if ($expectedName === null) { + continue; + } + if ($this->shouldSkipParam($param, $expectedName, $node)) { + continue; + } + $expectedName = $this->matchParamTypeExpectedNameResolver->resolve($param); + if ($expectedName === null) { + continue; + } + $paramRename = $this->paramRenameFactory->createFromResolvedExpectedName($node, $param, $expectedName); + if (! $paramRename instanceof ParamRename) { + continue; + } + $this->paramRenamer->rename($paramRename); + $this->hasChanged = \true; + } + if (! $this->hasChanged) { + return null; + } + + return $node; + } + + /** + * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure|\PhpParser\Node\Expr\ArrowFunction $classMethod + */ + private function shouldSkipParam(Param $param, string $expectedName, $classMethod): bool + { + /** @var string $paramName */ + $paramName = $this->getName($param); + if ($this->breakingVariableRenameGuard->shouldSkipParam($paramName, $expectedName, $classMethod, $param)) { + return \true; + } + if (! $classMethod instanceof ClassMethod) { + return \false; + } + // promoted property + if (! $this->isName($classMethod, MethodName::CONSTRUCT)) { + return \false; + } + + return $param->isPromoted(); + } +} diff --git a/packages/upgrade/src/rector.php b/packages/upgrade/src/rector.php index 7a7353b3520..3d437fe9a4c 100644 --- a/packages/upgrade/src/rector.php +++ b/packages/upgrade/src/rector.php @@ -259,5 +259,6 @@ $rectorConfig->rules([ Rector\SimpleMethodChangesRector::class, Rector\SimplePropertyChangesRector::class, + Rector\RenameSchemaParamToMatchTypeRector::class, ]); }; diff --git a/rector.php b/rector.php index 2f77d36b863..83dd52a3d59 100644 --- a/rector.php +++ b/rector.php @@ -1,11 +1,15 @@ withPaths([ __DIR__ . '/packages', ]) + ->withRules([ + RenameSchemaParamToMatchTypeRector::class, + ]) ->withTypeCoverageLevel(0) ->withDeadCodeLevel(0) ->withCodeQualityLevel(0);