From e305e0c589507aaf9e5a4dfa5fdfcca4b82e11e3 Mon Sep 17 00:00:00 2001 From: Adam Lee Date: Wed, 17 Apr 2024 17:36:54 +0100 Subject: [PATCH] fix: Install & configure rector for laravel + apply fixes --- composer.json | 7 +++- rector.php | 32 +++++++++++++++++++ src/Commands/Generator/MakeAction.php | 2 +- src/Commands/Generator/MakeController.php | 2 +- src/Commands/Generator/MakeData.php | 4 +-- src/Commands/Generator/MakePresenter.php | 6 ++-- src/Commands/Generator/MakeResource.php | 24 +++++++------- .../Generator/Writers/ModuleWriter.php | 4 +-- src/Commands/RESTPresenterSetupCommand.php | 18 +++++------ src/Commands/XtendStarterKit.php | 16 +++++----- src/Concerns/InteractsWithDbSchema.php | 23 ++++++------- src/Concerns/WithAutoDiscovery.php | 14 ++++---- src/Concerns/WithResourcePagination.php | 2 +- src/Concerns/WithTypeScriptGenerator.php | 4 +-- src/Models/User.php | 16 ++++++---- src/RESTPresenterServiceProvider.php | 8 ++--- .../Users/Data/Response/ProfileData.php | 4 +-- src/Resources/Users/Presenters/Profile.php | 2 +- src/Resources/Users/Presenters/User.php | 2 +- .../Users/UserResourceController.php | 2 +- .../Auth/Sanctum/Actions/ResetPassword.php | 2 +- .../Sanctum/SanctumApiKitServiceProvider.php | 30 +++++++++-------- .../Tests/Feature/AuthenticationTest.php | 6 ++-- .../Tests/Feature/EmailVerificationTest.php | 6 ++-- .../Tests/Feature/PasswordResetTest.php | 6 ++-- .../Tests/Feature/RegistrationTest.php | 2 +- .../Filament/Base/FilamentStarterKit.php | 14 ++++---- .../Stores/Lunar/Concerns/HasStyle.php | 2 +- .../Stores/Lunar/Concerns/HasUrls.php | 2 +- .../Stores/Lunar/Concerns/HasVariants.php | 2 +- .../Brands/BrandResourceController.php | 2 +- .../Catalog/Brands/Presenters/Brand/Brand.php | 4 +-- .../CollectionGroupResourceController.php | 2 +- .../Concerns/WithGenerateCollectionsTree.php | 14 ++++---- .../Presenters/CategoryTree/Data/TreeData.php | 2 +- .../CollectionResourceController.php | 2 +- .../Presenters/Category/Category.php | 4 +-- .../Products/ProductResourceController.php | 2 +- src/StarterKits/Stores/Lunar/Routes/api.php | 2 +- .../Catalog/Brands/BrandsFeatureTest.php | 8 ++--- .../Presenters/Brand/BrandFeatureTest.php | 6 ++-- .../Brands/Presenters/Brand/BrandUnitTest.php | 6 ++-- .../CollectionGroupsFeatureTest.php | 8 ++--- .../CategoryTree/CategoryTreeFeatureTest.php | 6 ++-- .../CategoryTree/CategoryTreeUnitTest.php | 8 ++--- .../Collections/CollectionsFeatureTest.php | 10 +++--- .../CollectionGroupFeatureTest.php | 6 ++-- .../CollectionGroupUnitTest.php | 8 ++--- .../Category/CategoryFeatureTest.php | 6 ++-- .../Presenters/Category/CategoryUnitTest.php | 6 ++-- .../Filters/Brand/BrandFeatureTest.php | 6 ++-- .../Products/Filters/Brand/BrandUnitTest.php | 8 ++--- .../Filters/Status/StatusFeatureTest.php | 8 ++--- .../Filters/Status/StatusUnitTest.php | 10 +++--- .../Presenters/Detail/DetailFeatureTest.php | 6 ++-- .../Presenters/Detail/DetailUnitTest.php | 6 ++-- .../Presenters/Item/ItemFeatureTest.php | 6 ++-- .../Products/Presenters/Item/ItemUnitTest.php | 6 ++-- .../Catalog/Products/ProductsFeatureTest.php | 16 +++++----- .../Stores/Lunar/Tests/LunarTestCase.php | 12 +++---- src/Support/XtendRouter.php | 8 +---- tests/Helpers.php | 6 ++-- .../ResourcePresenterFeatureTest.php | 8 ++--- .../Presenters/Profile/ProfileFeatureTest.php | 6 ++-- .../Presenters/Profile/ProfileUnitTest.php | 10 +++--- .../Users/Presenters/User/UserFeatureTest.php | 6 ++-- .../Users/Presenters/User/UserUnitTest.php | 10 +++--- tests/Resources/Users/UsersFeatureTest.php | 8 ++--- .../Concerns/InteractsWithModelTest.php | 5 ++- .../Concerns/InteractsWithPresenterTest.php | 16 +++++----- .../Concerns/InteractsWithRequestTest.php | 10 +++--- .../Concerns/WithResourceFilteringTest.php | 8 ++--- 72 files changed, 285 insertions(+), 276 deletions(-) create mode 100644 rector.php diff --git a/composer.json b/composer.json index e092d20..0191b75 100644 --- a/composer.json +++ b/composer.json @@ -28,6 +28,7 @@ "spatie/laravel-typescript-transformer": "^2.4" }, "require-dev": { + "driftingly/rector-laravel": "^1.1", "fakerphp/faker": "^1.23", "filament/filament": "^3.2", "larastan/larastan": "^v2.9", @@ -41,6 +42,7 @@ "pestphp/pest-plugin-laravel": "^2.3", "pestphp/pest-plugin-livewire": "^2.1", "phpunit/phpunit": "^10", + "rector/rector": "^1.0.4", "spatie/invade": "^1.1", "spatie/pest-plugin-snapshots": "^2.1" }, @@ -62,7 +64,10 @@ "test": "vendor/bin/pest --testsuite=RESTPresenter", "test-coverage": "vendor/bin/pest --testsuite=RESTPresenter --coverage", "test-starter-kit:lunar": "vendor/bin/pest --testsuite=starter-kit:lunar", - "format": "vendor/bin/pint" + "test:format": "pint --test", + "test:refactor": "rector --dry-run", + "format": "vendor/bin/pint", + "refactor": "rector" }, "config": { "sort-packages": true, diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..cba3777 --- /dev/null +++ b/rector.php @@ -0,0 +1,32 @@ +withPaths([ + __DIR__ . '/src', + __DIR__ . '/tests', + ]) + ->withSkip([ + AddOverrideAttributeToOverriddenMethodsRector::class, + ]) + ->withAttributesSets( + symfony: true, + doctrine: true, + ) + ->withPreparedSets( + deadCode: true, + codeQuality: true, + typeDeclarations: true, + privatization: true, + earlyReturn: true, + strictBooleans: true, + ) + ->withSets([ + LaravelSetList::LARAVEL_110, + ]) + ->withPhpSets(); diff --git a/src/Commands/Generator/MakeAction.php b/src/Commands/Generator/MakeAction.php index c14684f..67cd428 100644 --- a/src/Commands/Generator/MakeAction.php +++ b/src/Commands/Generator/MakeAction.php @@ -73,7 +73,7 @@ protected function buildResourceReplacements(): array $resourceName = type($this->argument('name'))->asString(); return [ - '{{ actionNamespace }}' => $kitNamespace + '{{ actionNamespace }}' => $kitNamespace !== '' && $kitNamespace !== '0' ? 'XtendPackages\\RESTPresenter\\' . $kitNamespace . '\\Actions\\' . $this->getNameInput() . '\\' . $this->getNameInput() : 'XtendPackages\\RESTPresenter\\Resources\\' . Str::plural($resourceName) . '\\Actions\\' . $this->getNameInput() . '\\' . $this->getNameInput(), '{{ aliasAction }}' => 'Xtend' . $this->getNameInput() . 'Action', diff --git a/src/Commands/Generator/MakeController.php b/src/Commands/Generator/MakeController.php index a88d590..569eb80 100644 --- a/src/Commands/Generator/MakeController.php +++ b/src/Commands/Generator/MakeController.php @@ -32,7 +32,7 @@ protected function getDefaultNamespace($rootNamespace): string $namespace = type(config('rest-presenter.generator.namespace'))->asString(); $kitNamespace = type($this->argument('kit_namespace'))->asString(); - if ($kitNamespace) { + if ($kitNamespace !== '' && $kitNamespace !== '0') { return $namespace . '\\' . $kitNamespace; } diff --git a/src/Commands/Generator/MakeData.php b/src/Commands/Generator/MakeData.php index 8c2410b..a505eab 100644 --- a/src/Commands/Generator/MakeData.php +++ b/src/Commands/Generator/MakeData.php @@ -25,7 +25,7 @@ class MakeData extends GeneratorCommand protected $type = 'Data'; - public function handle() + public function handle(): void { parent::handle(); @@ -108,7 +108,7 @@ protected function buildResourceReplacements(): array */ protected function transformFieldProperties(array $fields): string { - return collect($fields)->map(function (array $fieldProperties, string $field) { + return collect($fields)->map(function (array $fieldProperties, string $field): string { $fieldType = strtolower(type($fieldProperties['type'])->asString()); $propertyType = match ($fieldType) { 'int', 'integer', 'bigint' => 'int', diff --git a/src/Commands/Generator/MakePresenter.php b/src/Commands/Generator/MakePresenter.php index 9e2a7a5..0e47c64 100644 --- a/src/Commands/Generator/MakePresenter.php +++ b/src/Commands/Generator/MakePresenter.php @@ -20,7 +20,7 @@ class MakePresenter extends GeneratorCommand protected $type = 'Presenter'; - public function handle() + public function handle(): void { if ($this->hasArgument('fields') && is_array($this->argument('fields'))) { $name = type($this->argument('name'))->asString(); @@ -75,9 +75,7 @@ protected function getPresenterNamespace(): string ->plural() ->value(); - $resourceNamespace = $this->argument('kit_namespace') - ? $this->argument('kit_namespace') - : $resourceDirectory; + $resourceNamespace = $this->argument('kit_namespace') ?: $resourceDirectory; $resourceNamespace = type($resourceNamespace)->asString(); return $resourceNamespace . '\\Presenters\\' . $presenterNamespace; diff --git a/src/Commands/Generator/MakeResource.php b/src/Commands/Generator/MakeResource.php index 3ee3ab9..f1cc92e 100644 --- a/src/Commands/Generator/MakeResource.php +++ b/src/Commands/Generator/MakeResource.php @@ -55,7 +55,7 @@ class MakeResource extends GeneratorCommand */ protected Collection $presentersArgument; - public function handle() + public function handle(): void { $this->actions ??= collect(); $this->filters ??= collect(); @@ -179,7 +179,7 @@ protected function transformActions(): string } return $this->actions->map( - fn ($action) => "'$action' => Actions\\" . ucfirst($action) . '::class', + fn ($action): string => "'$action' => Actions\\" . ucfirst($action) . '::class', )->implode(",\n\t\t\t") . ','; } @@ -190,7 +190,7 @@ protected function transformFilters(): string } return $this->filters->map( - fn ($filter) => "'$filter' => Filters\\" . ucfirst($filter) . '::class', + fn ($filter): string => "'$filter' => Filters\\" . ucfirst($filter) . '::class', )->implode(",\n\t\t\t") . ','; } @@ -201,7 +201,7 @@ protected function transformPresenters(): string } return $this->getPresenters()->map( - function ($presenter, $presenterKey) { + function (string $presenter, $presenterKey): string { $presenterNamespace = Str::of($presenterKey) ->replace('Presenter', '') ->studly() @@ -284,7 +284,7 @@ protected function promptForModel(InputInterface $input): void { $model = search( label: 'Which model should the resource use?', - options: fn () => $this->scanModels(), // @phpstan-ignore-line + options: fn (): array => $this->scanModels(), // @phpstan-ignore-line placeholder: 'Search for a model...', hint: 'Press Enter to select the model.' ); @@ -363,7 +363,7 @@ protected function promptForPresenters(InputInterface $input, bool $init = true) hint: 'Press Enter to confirm the presenter name.' ); - if ($presenterName) { + if ($presenterName !== '' && $presenterName !== '0') { $fields = $this->generateModelFields()->keyBy('name'); $selectedFields = multiselect( label: 'Select the fields you would like to include in the presenter:', @@ -422,12 +422,12 @@ protected function generateFilterSuggestions(): Collection $reflect = new ReflectionClass($this->model); return collect($reflect->getMethods(ReflectionMethod::IS_PUBLIC)) - ->filter(function (ReflectionMethod $method) { + ->filter(function (ReflectionMethod $method): bool { $returnNamedType = $method->getReturnType() instanceof ReflectionNamedType ? $method->getReturnType()->getName() : ''; return $returnNamedType && is_subclass_of($returnNamedType, Relation::class); }) - ->mapWithKeys(function (ReflectionMethod $method) { + ->mapWithKeys(function (ReflectionMethod $method): array { $returnNamedType = $method->getReturnType() instanceof ReflectionNamedType ? $method->getReturnType()->getName() : ''; return [ @@ -443,12 +443,12 @@ protected function scanModels(): array { return collect(app('files')->allFiles(app_path())) ->filter(fn (SplFileInfo $file) => Str::endsWith($file->getFilename(), '.php')) - ->map(fn (SplFileInfo $file) => $file->getRelativePathname()) + ->map(fn (SplFileInfo $file): string => $file->getRelativePathname()) ->map(fn (string $file) => 'App\\' . str_replace(['/', '.php'], ['\\', ''], $file)) - ->filter(fn (string $class) => class_exists($class)) - ->map(fn (string $class) => new ReflectionClass($class)) + ->filter(fn (string $class): bool => class_exists($class)) + ->map(fn (string $class): \ReflectionClass => new ReflectionClass($class)) ->filter(fn (ReflectionClass $class) => $class->isSubclassOf(Model::class)) - ->mapWithKeys(fn (ReflectionClass $class) => [$class->getName() => $class->getShortName()]) + ->mapWithKeys(fn (ReflectionClass $class): array => [$class->getName() => $class->getShortName()]) ->toArray(); } } diff --git a/src/Commands/Generator/Writers/ModuleWriter.php b/src/Commands/Generator/Writers/ModuleWriter.php index 424098e..8807b8c 100644 --- a/src/Commands/Generator/Writers/ModuleWriter.php +++ b/src/Commands/Generator/Writers/ModuleWriter.php @@ -18,9 +18,7 @@ public function format(TypesCollection $collection): string /** @var \ArrayIterator $iterator */ $iterator = $collection->getIterator(); - $iterator->uasort(function (TransformedType $a, TransformedType $b) { - return strcmp(type($a->name)->asString(), type($b->name)->asString()); - }); + $iterator->uasort(fn(TransformedType $a, TransformedType $b): int => strcmp(type($a->name)->asString(), type($b->name)->asString())); foreach ($iterator as $type) { /** @var TransformedType $type */ diff --git a/src/Commands/RESTPresenterSetupCommand.php b/src/Commands/RESTPresenterSetupCommand.php index 296f316..276c529 100644 --- a/src/Commands/RESTPresenterSetupCommand.php +++ b/src/Commands/RESTPresenterSetupCommand.php @@ -98,15 +98,13 @@ protected function publishingServiceProvider(): void } $callable = [ServiceProvider::class, 'addProviderToBootstrapFile']; - if (is_callable($callable)) { - call_user_func($callable, 'App\\Providers\\RESTPresenterServiceProvider', $providersPath); - } + call_user_func($callable, 'App\\Providers\\RESTPresenterServiceProvider', $providersPath); } protected function publishingDefaultResources(): void { collect($this->filesystem->directories(__DIR__ . '/../Resources')) - ->map(fn ($resource) => Str::singular(basename($resource))) + ->map(fn ($resource) => Str::singular(basename((string) $resource))) ->each(fn ($resource) => $this->call('rest-presenter:make-resource', [ 'model' => 'App\\Models\\' . Str::singular($resource), 'name' => $resource, @@ -122,11 +120,11 @@ protected function publishStarterKits(): void /** @var \Illuminate\Support\Collection $unpublishedStarterKits */ $unpublishedStarterKits = collect($this->filesystem->allFiles($starterKitsDirectory)) - ->map(fn ($file) => $file->getRelativePathname()) - ->filter(fn ($file) => ! $this->filesystem->exists($generatedKitsDirectory . '/' . $file)) - ->filter(fn ($file) => str_ends_with($file, 'ApiKitServiceProvider.php')) - ->map(fn ($file) => str_replace('ApiKitServiceProvider.php', '', basename($file))) - ->map(fn ($kit) => $kit) + ->map(fn ($file): string => $file->getRelativePathname()) + ->filter(fn ($file): bool => ! $this->filesystem->exists($generatedKitsDirectory . '/' . $file)) + ->filter(fn ($file): bool => str_ends_with($file, 'ApiKitServiceProvider.php')) + ->map(fn ($file): string|array => str_replace('ApiKitServiceProvider.php', '', basename($file))) + ->map(fn ($kit): string => $kit) ->values(); if ($unpublishedStarterKits->isEmpty()) { @@ -141,7 +139,7 @@ protected function publishStarterKits(): void hint: 'You can re-run this command to install more starter kits later', ); - if (! $starterKits) { + if ($starterKits === []) { return; } diff --git a/src/Commands/XtendStarterKit.php b/src/Commands/XtendStarterKit.php index b4470c7..908b695 100644 --- a/src/Commands/XtendStarterKit.php +++ b/src/Commands/XtendStarterKit.php @@ -62,7 +62,7 @@ protected function extendControllers(string $starterKitsDirectory, string $kitPa if ($this->kitCanExtendControllers($starterKitsDirectory, $kitPath)) { collect($this->filesystem->allFiles($starterKitsDirectory . '/' . $kitPath . '/Http/Controllers')) ->filter(fn (SplFileInfo $file) => Str::endsWith($file->getFilename(), 'Controller.php')) - ->each(function (SplFileInfo $file) use ($kitPath) { + ->each(function (SplFileInfo $file) use ($kitPath): void { $path = $file->getRelativePathName(); $kitNamespace = Str::of($kitPath) ->replace('/', '\\')->prepend('StarterKits\\') @@ -84,7 +84,7 @@ protected function extendResources(string $starterKitsDirectory, string $kitPath if ($this->kitCanExtendResources($starterKitsDirectory, $kitPath)) { collect($this->filesystem->allFiles($starterKitsDirectory . '/' . $kitPath . '/Resources')) ->filter(fn (SplFileInfo $file) => Str::endsWith($file->getFilename(), 'ResourceController.php')) - ->each(function (SplFileInfo $file) use ($starterKitsDirectory, $kitPath) { + ->each(function (SplFileInfo $file) use ($starterKitsDirectory, $kitPath): void { $path = $file->getRelativePath(); $kitNamespace = Str::of($kitPath) ->replace('/', '\\')->prepend('StarterKits\\') @@ -93,7 +93,7 @@ protected function extendResources(string $starterKitsDirectory, string $kitPath $resource = basename($path); $resourcePath = $kitPath . '/Resources/' . $path; - $kitNamespace = $kitNamespace . (class_basename($resource) !== $path ? '\\' . $resource : ''); + $kitNamespace .= class_basename($resource) !== $path ? '\\' . $resource : ''; $this->extendActions($starterKitsDirectory, $resourcePath, $kitNamespace); $this->extendPresenters($starterKitsDirectory, $resourcePath, $kitNamespace); @@ -116,7 +116,7 @@ protected function autoDiscoverResources(string $kitPath): void default => false, }; - if (! $supportedKit) { + if ($supportedKit === false) { $this->components->warn(__('No supported kit was found for ":kit_namespace"', ['kit_namespace' => $kitNamespace])); return; @@ -137,13 +137,13 @@ protected function autoDiscoverResources(string $kitPath): void ->before('\\Base') ->value(); - collect($resources)->each(function ($resource, $resourceNamespace) use ($kitNamespace) { + collect($resources)->each(function (array $resource, string $resourceNamespace) use ($kitNamespace): void { $resourceName = Str::of($resourceNamespace) ->classBasename() ->singular() ->value(); - if ($resource['fields']) { + if ($resource['fields'] !== '' && $resource['fields'] !== '0') { $this->call( command: 'rest-presenter:make-presenter', arguments: [ @@ -182,7 +182,7 @@ protected function extendActions(string $starterKitsDirectory, string $resourceP } collect($this->filesystem->directories($starterKitsDirectory . '/' . $resourcePath . '/Actions')) - ->each(function ($path) use ($kitNamespace) { + ->each(function ($path) use ($kitNamespace): void { $action = basename($path); $this->call('rest-presenter:make-action', [ @@ -202,7 +202,7 @@ protected function extendPresenters(string $starterKitsDirectory, string $resour } collect($this->filesystem->directories($starterKitsDirectory . '/' . $resourcePath . '/Presenters')) - ->each(function ($path) use ($kitNamespace) { + ->each(function ($path) use ($kitNamespace): void { $presenter = basename($path); $this->call('rest-presenter:make-presenter', [ diff --git a/src/Concerns/InteractsWithDbSchema.php b/src/Concerns/InteractsWithDbSchema.php index f6bc375..b5be55c 100644 --- a/src/Concerns/InteractsWithDbSchema.php +++ b/src/Concerns/InteractsWithDbSchema.php @@ -22,28 +22,23 @@ protected function getAllTableNames(): Collection */ protected function getTableColumns(string $table, bool $withProperties = false): Collection { - $columns = collect(! $withProperties - ? Schema::getColumnListing($table) - : Schema::getColumns($table), - ); - if (DB::connection()->getDriverName() === 'sqlite' && $withProperties) { - $columns = $this->replaceJsonColumnsSqliteWorkaround($table); + return $this->replaceJsonColumnsSqliteWorkaround($table); } - - return $columns; + return collect($withProperties + ? Schema::getColumns($table) + : Schema::getColumnListing($table), + ); } /** - * @param string $table * @param array $exclude - * * @return \Illuminate\Support\Collection */ protected function getTableColumnsForRelation(string $table, array $exclude = []): Collection { return $this->getTableColumns($table)->filter( - fn (string $column) => ! in_array($column, $exclude), + fn (string $column): bool => ! in_array($column, $exclude), ); } @@ -51,9 +46,9 @@ protected function findTableByName(string $table, bool $exactMatch = true): mixe { return $this->getAllTableNames() ->first( - fn ($tableName) => ! $exactMatch - ? Str::endsWith(type($tableName)->asString(), $table) - : $tableName === $table, + fn ($tableName) => $exactMatch + ? $tableName === $table + : Str::endsWith(type($tableName)->asString(), $table), ); } diff --git a/src/Concerns/WithAutoDiscovery.php b/src/Concerns/WithAutoDiscovery.php index ec3b219..9de220a 100644 --- a/src/Concerns/WithAutoDiscovery.php +++ b/src/Concerns/WithAutoDiscovery.php @@ -21,7 +21,7 @@ protected function autoDiscover(string $path, bool $isKit = false): void collect($fileSystem->allFiles($path)) ->filter(fn (SplFileInfo $file) => Str::endsWith($file->getFilename(), 'ResourceController.php')) - ->mapWithKeys(function (SplFileInfo $file) use ($namespace) { + ->mapWithKeys(function (SplFileInfo $file) use ($namespace): array { $name = Str::of(basename($file->getRelativePath())) ->replace('/', '.') ->kebab() @@ -45,13 +45,13 @@ protected function autoDiscover(string $path, bool $isKit = false): void ->value(); $routeName = $isKit ? $kit . '.' : null; - if (! $routeName) { + if ($routeName === null || $routeName === '' || $routeName === '0') { return null; } return Route::name($routeName) ->prefix($kit) - ->group(function () use ($name, $controller) { + ->group(function () use ($name, $controller): void { $this->isResourceOnlyActionRoutes($controller) ? $this->registerActionRoutes($controller) : $this->registerResourceRoutes($name, $controller); @@ -65,11 +65,9 @@ private function registerActionRoutes(string $controller): void $resource = $this->getXtendResourceController($controller); collect($resource->routeActions()) - ->each(function ($controller, $name) { - return Route::match($controller::$method, $name, $controller) // @phpstan-ignore-line - ->middleware($controller::$middleware ?? []) // @phpstan-ignore-line - ->name($name); - }); + ->each(fn($controller, $name) => Route::match($controller::$method, $name, $controller) // @phpstan-ignore-line + ->middleware($controller::$middleware ?? []) // @phpstan-ignore-line + ->name($name)); } private function registerResourceRoutes(string $name, string $controller): void diff --git a/src/Concerns/WithResourcePagination.php b/src/Concerns/WithResourcePagination.php index a29dfdc..878557c 100644 --- a/src/Concerns/WithResourcePagination.php +++ b/src/Concerns/WithResourcePagination.php @@ -4,7 +4,7 @@ trait WithResourcePagination { - public function applyPagination($query, $request) + public function applyPagination($query, $request): void { $query->paginate($request->input('limit', 10)); } diff --git a/src/Concerns/WithTypeScriptGenerator.php b/src/Concerns/WithTypeScriptGenerator.php index c821097..75eea7a 100644 --- a/src/Concerns/WithTypeScriptGenerator.php +++ b/src/Concerns/WithTypeScriptGenerator.php @@ -58,9 +58,7 @@ protected function ensureSpatieEnumTransformerIsRemoved(): void /** @var array $transformerArray */ $transformerArray = $transformersFromConfig['transformers']; - $transformers = collect($transformerArray)->reject(function ($transformer) { - return $transformer === 'Spatie\TypeScriptTransformer\Transformers\SpatieEnumTransformer'; - })->values()->all(); + $transformers = collect($transformerArray)->reject(fn($transformer): bool => $transformer === \Spatie\TypeScriptTransformer\Transformers\SpatieEnumTransformer::class)->values()->all(); $this->config->set('typescript-transformer.transformers', $transformers); } diff --git a/src/Models/User.php b/src/Models/User.php index 7964daf..96433e8 100644 --- a/src/Models/User.php +++ b/src/Models/User.php @@ -42,17 +42,19 @@ class User extends Authenticatable 'remember_token', ]; + protected static function newFactory(): UserFactory + { + return UserFactory::new(); + } /** * The attributes that should be cast. * - * @var array + * @return array */ - protected $casts = [ - 'email_verified_at' => 'datetime', - ]; - - protected static function newFactory(): UserFactory + protected function casts(): array { - return UserFactory::new(); + return [ + 'email_verified_at' => 'datetime', + ]; } } diff --git a/src/RESTPresenterServiceProvider.php b/src/RESTPresenterServiceProvider.php index 7457854..3852314 100644 --- a/src/RESTPresenterServiceProvider.php +++ b/src/RESTPresenterServiceProvider.php @@ -38,13 +38,9 @@ public function configurePackage(Package $package): void public function packageRegistered(): void { - $this->app->singleton('rest-presenter', function () { - return new RESTPresenter(); - }); + $this->app->singleton('rest-presenter', fn(): \XtendPackages\RESTPresenter\Base\RESTPresenter => new RESTPresenter()); - $this->app->bind('xtend-router', function (Application $app) { - return new Support\XtendRouter($app['events'], $app); - }); + $this->app->bind('xtend-router', fn(Application $app): \XtendPackages\RESTPresenter\Support\XtendRouter => new Support\XtendRouter($app['events'], $app)); XtendRoute::register(); } diff --git a/src/Resources/Users/Data/Response/ProfileData.php b/src/Resources/Users/Data/Response/ProfileData.php index ec30814..bfa09e7 100644 --- a/src/Resources/Users/Data/Response/ProfileData.php +++ b/src/Resources/Users/Data/Response/ProfileData.php @@ -27,8 +27,8 @@ public static function fromModel(Model $model): ProfileData { return new ProfileData( id: $model->getKey(), - firstName: static::firstName($model->name), - lastName: static::lastName($model->name), + firstName: self::firstName($model->name), + lastName: self::lastName($model->name), email: $model->email, ); } diff --git a/src/Resources/Users/Presenters/Profile.php b/src/Resources/Users/Presenters/Profile.php index ee83e18..2def54d 100644 --- a/src/Resources/Users/Presenters/Profile.php +++ b/src/Resources/Users/Presenters/Profile.php @@ -10,7 +10,7 @@ class Profile implements Presentable { public function __construct( - private ?Authenticatable $model, + private readonly ?Authenticatable $model, ) {} public function transform(): Data diff --git a/src/Resources/Users/Presenters/User.php b/src/Resources/Users/Presenters/User.php index b75bd74..b8c72bc 100644 --- a/src/Resources/Users/Presenters/User.php +++ b/src/Resources/Users/Presenters/User.php @@ -10,7 +10,7 @@ class User implements Presentable { public function __construct( - private ?Authenticatable $model, + private readonly ?Authenticatable $model, ) {} public function transform(): Data diff --git a/src/Resources/Users/UserResourceController.php b/src/Resources/Users/UserResourceController.php index 189e12b..dda11d4 100644 --- a/src/Resources/Users/UserResourceController.php +++ b/src/Resources/Users/UserResourceController.php @@ -26,7 +26,7 @@ public function index(Request $request): Collection $users = $this->getModelQueryInstance()->get(); return $users->map( - fn ($user) => $this->present($request, $user), + fn ($user): \Spatie\LaravelData\Data => $this->present($request, $user), ); } diff --git a/src/StarterKits/Auth/Sanctum/Actions/ResetPassword.php b/src/StarterKits/Auth/Sanctum/Actions/ResetPassword.php index f89edac..079a9ab 100644 --- a/src/StarterKits/Auth/Sanctum/Actions/ResetPassword.php +++ b/src/StarterKits/Auth/Sanctum/Actions/ResetPassword.php @@ -27,7 +27,7 @@ protected function sendResetLink(string $email): void { $status = Password::sendResetLink( credentials: ['email' => $email], - callback: function (User $user, $token) { + callback: function (User $user, $token): void { $this->setTemporaryPassword($user, $token); $user->sendPasswordResetNotification($token); }, diff --git a/src/StarterKits/Auth/Sanctum/SanctumApiKitServiceProvider.php b/src/StarterKits/Auth/Sanctum/SanctumApiKitServiceProvider.php index 8c5f8ed..ace3094 100644 --- a/src/StarterKits/Auth/Sanctum/SanctumApiKitServiceProvider.php +++ b/src/StarterKits/Auth/Sanctum/SanctumApiKitServiceProvider.php @@ -20,24 +20,26 @@ public function register(): void public function boot(): void { // @todo: Move this to mailable class and support translations - ResetPassword::toMailUsing(static function ($notifiable, string $token) { - return (new MailMessage) - ->subject(Lang::get('Reset Password Notification')) // @phpstan-ignore-line - ->line(Lang::get('You are receiving this email because we received a password reset request for your account.')) - ->action(Lang::get('Login'), url(config('app.frontend_url'))) // @phpstan-ignore-line - ->line(Lang::get('Please use the following temporary password to login to your account: :password', [ - 'password' => Actions\ResetPassword::generateTemporaryPassword($notifiable, $token), // @phpstan-ignore-line - ])) - ->line(Lang::get('If you did not request a password reset, no further action is required.')); - }); + ResetPassword::toMailUsing(static fn($notifiable, string $token) => (new MailMessage) + ->subject(Lang::get('Reset Password Notification')) // @phpstan-ignore-line + ->line(Lang::get('You are receiving this email because we received a password reset request for your account.')) + ->action(Lang::get('Login'), url(config('app.frontend_url'))) // @phpstan-ignore-line + ->line(Lang::get('Please use the following temporary password to login to your account: :password', [ + 'password' => Actions\ResetPassword::generateTemporaryPassword($notifiable, $token), // @phpstan-ignore-line + ])) + ->line(Lang::get('If you did not request a password reset, no further action is required.'))); } protected function ensurePersonalAccessTokensHasExpiresAtColumn(): void { - if (Schema::hasTable('personal_access_tokens') && ! Schema::hasColumn('personal_access_tokens', 'expires_at')) { - Schema::table('personal_access_tokens', function (Blueprint $table) { - $table->timestamp('expires_at')->after('last_used_at')->nullable(); - }); + if (!Schema::hasTable('personal_access_tokens')) { + return; + } + if (Schema::hasColumn('personal_access_tokens', 'expires_at')) { + return; } + Schema::table('personal_access_tokens', function (Blueprint $table): void { + $table->timestamp('expires_at')->after('last_used_at')->nullable(); + }); } } diff --git a/src/StarterKits/Auth/Sanctum/Tests/Feature/AuthenticationTest.php b/src/StarterKits/Auth/Sanctum/Tests/Feature/AuthenticationTest.php index cb7de28..2b0a09a 100644 --- a/src/StarterKits/Auth/Sanctum/Tests/Feature/AuthenticationTest.php +++ b/src/StarterKits/Auth/Sanctum/Tests/Feature/AuthenticationTest.php @@ -2,7 +2,7 @@ use XtendPackages\RESTPresenter\Models\User; -test('users can authenticate using the login screen', function () { +test('users can authenticate using the login screen', function (): void { $user = User::factory()->create(); $response = $this->post('/login', [ @@ -14,7 +14,7 @@ $response->assertNoContent(); }); -test('users can not authenticate with invalid password', function () { +test('users can not authenticate with invalid password', function (): void { $user = User::factory()->create(); $this->post('/login', [ @@ -25,7 +25,7 @@ $this->assertGuest(); }); -test('users can logout', function () { +test('users can logout', function (): void { $user = User::factory()->create(); $response = $this->actingAs($user)->post('/logout'); diff --git a/src/StarterKits/Auth/Sanctum/Tests/Feature/EmailVerificationTest.php b/src/StarterKits/Auth/Sanctum/Tests/Feature/EmailVerificationTest.php index 932c5d1..92952c0 100644 --- a/src/StarterKits/Auth/Sanctum/Tests/Feature/EmailVerificationTest.php +++ b/src/StarterKits/Auth/Sanctum/Tests/Feature/EmailVerificationTest.php @@ -5,7 +5,7 @@ use Illuminate\Support\Facades\URL; use XtendPackages\RESTPresenter\Models\User; -test('email can be verified', function () { +test('email can be verified', function (): void { $user = User::factory()->create([ 'email_verified_at' => null, ]); @@ -15,7 +15,7 @@ $verificationUrl = URL::temporarySignedRoute( 'verification.verify', now()->addMinutes(60), - ['id' => $user->id, 'hash' => sha1($user->email)] + ['id' => $user->id, 'hash' => sha1((string) $user->email)] ); $response = $this->actingAs($user)->get($verificationUrl); @@ -25,7 +25,7 @@ $response->assertRedirect(config('app.frontend_url') . '/dashboard?verified=1'); }); -test('email is not verified with invalid hash', function () { +test('email is not verified with invalid hash', function (): void { $user = User::factory()->create([ 'email_verified_at' => null, ]); diff --git a/src/StarterKits/Auth/Sanctum/Tests/Feature/PasswordResetTest.php b/src/StarterKits/Auth/Sanctum/Tests/Feature/PasswordResetTest.php index d7b73e6..0dedc49 100644 --- a/src/StarterKits/Auth/Sanctum/Tests/Feature/PasswordResetTest.php +++ b/src/StarterKits/Auth/Sanctum/Tests/Feature/PasswordResetTest.php @@ -4,7 +4,7 @@ use Illuminate\Support\Facades\Notification; use XtendPackages\RESTPresenter\Models\User; -test('reset password link can be requested', function () { +test('reset password link can be requested', function (): void { Notification::fake(); $user = User::factory()->create(); @@ -14,14 +14,14 @@ Notification::assertSentTo($user, ResetPassword::class); }); -test('password can be reset with valid token', function () { +test('password can be reset with valid token', function (): void { Notification::fake(); $user = User::factory()->create(); $this->post('/forgot-password', ['email' => $user->email]); - Notification::assertSentTo($user, ResetPassword::class, function (object $notification) use ($user) { + Notification::assertSentTo($user, ResetPassword::class, function (object $notification) use ($user): bool { $response = $this->post('/reset-password', [ 'token' => $notification->token, // @phpstan-ignore-line 'email' => $user->email, diff --git a/src/StarterKits/Auth/Sanctum/Tests/Feature/RegistrationTest.php b/src/StarterKits/Auth/Sanctum/Tests/Feature/RegistrationTest.php index 012ef40..9ed35b5 100644 --- a/src/StarterKits/Auth/Sanctum/Tests/Feature/RegistrationTest.php +++ b/src/StarterKits/Auth/Sanctum/Tests/Feature/RegistrationTest.php @@ -1,6 +1,6 @@ post('/register', [ 'name' => 'Test User', 'email' => 'test@example.com', diff --git a/src/StarterKits/Filament/Base/FilamentStarterKit.php b/src/StarterKits/Filament/Base/FilamentStarterKit.php index 888e114..ae4802b 100644 --- a/src/StarterKits/Filament/Base/FilamentStarterKit.php +++ b/src/StarterKits/Filament/Base/FilamentStarterKit.php @@ -36,19 +36,19 @@ protected function autoDiscoverResources(): void } collect($this->filesystem->allFiles(app_path('Filament/Resources'))) - ->filter(fn (SplFileInfo $file) => basename($file->getRelativePath()) === 'Pages') - ->map(fn (SplFileInfo $file) => $file->getRelativePathname()) + ->filter(fn (SplFileInfo $file): bool => basename($file->getRelativePath()) === 'Pages') + ->map(fn (SplFileInfo $file): string => $file->getRelativePathname()) ->map(fn (string $file) => resolve('App\\Filament\\Resources\\' . str_replace(['/', '.php'], ['\\', ''], $file))) - ->filter(fn ($class) => is_subclass_of($class, ListRecords::class)) - ->each(function ($page) { + ->filter(fn ($class): bool => is_subclass_of($class, ListRecords::class)) + ->each(function ($page): void { /** @var \Filament\Resources\Pages\ListRecords $page */ $page = type($page)->as(ListRecords::class); /** @var \Filament\Tables\Table $table */ $table = $page->table( - table: mock('Filament\Tables\Table')->makePartial(), + table: mock(\Filament\Tables\Table::class)->makePartial(), ); - $resourceNamespace = Str::of(get_class($page)) + $resourceNamespace = Str::of($page::class) ->replace('App\\Filament\\', '') ->before('\\Pages') ->replaceLast('Resource', '') @@ -63,7 +63,7 @@ protected function autoDiscoverResources(): void $modelFields = $this->generateModelFields(resolve($page->getModel()))->keyBy('name'); $tableColumns = collect(['id' => 'integer'])->merge(collect($table->getColumns()))->keys()->values(); $fields = $tableColumns->intersect($modelFields->keys())->mapWithKeys( - fn ($column) => [$column => $modelFields[$column]], + fn ($column): array => [$column => $modelFields[$column]], )->merge($modelFields); $this->resources[$resourceNamespace] = [ diff --git a/src/StarterKits/Stores/Lunar/Concerns/HasStyle.php b/src/StarterKits/Stores/Lunar/Concerns/HasStyle.php index e829e16..35e3144 100644 --- a/src/StarterKits/Stores/Lunar/Concerns/HasStyle.php +++ b/src/StarterKits/Stores/Lunar/Concerns/HasStyle.php @@ -9,7 +9,7 @@ trait HasStyle public function getStyle(): ?Collection { return $this->model->collections->first( - fn (Collection $collection) => $collection->group->handle === 'styles', + fn (Collection $collection): bool => $collection->group->handle === 'styles', ); } } diff --git a/src/StarterKits/Stores/Lunar/Concerns/HasUrls.php b/src/StarterKits/Stores/Lunar/Concerns/HasUrls.php index c780483..992671d 100644 --- a/src/StarterKits/Stores/Lunar/Concerns/HasUrls.php +++ b/src/StarterKits/Stores/Lunar/Concerns/HasUrls.php @@ -19,7 +19,7 @@ protected function getUrl(?Model $model = null): Url $urls = $model->urls ?? null; return $urls?->first( - fn (Url $url) => $url->language->code === app()->getLocale(), + fn (Url $url): bool => $url->language->code === app()->getLocale(), ); } } diff --git a/src/StarterKits/Stores/Lunar/Concerns/HasVariants.php b/src/StarterKits/Stores/Lunar/Concerns/HasVariants.php index 07b53d6..7a6cc97 100644 --- a/src/StarterKits/Stores/Lunar/Concerns/HasVariants.php +++ b/src/StarterKits/Stores/Lunar/Concerns/HasVariants.php @@ -25,7 +25,7 @@ protected function getProductOptions(string $handle): Collection /** @var Collection $values */ $values = $this->getVariants() ->flatMap(fn (ProductVariant $variant) => collect($variant->values)->filter( - fn (ProductOptionValue $value) => $value->option->handle === $handle, + fn (ProductOptionValue $value): bool => $value->option->handle === $handle, )->values()); return $values diff --git a/src/StarterKits/Stores/Lunar/Resources/Catalog/Brands/BrandResourceController.php b/src/StarterKits/Stores/Lunar/Resources/Catalog/Brands/BrandResourceController.php index bac79c6..387c745 100644 --- a/src/StarterKits/Stores/Lunar/Resources/Catalog/Brands/BrandResourceController.php +++ b/src/StarterKits/Stores/Lunar/Resources/Catalog/Brands/BrandResourceController.php @@ -18,7 +18,7 @@ public function index(Request $request): Collection $brands = $this->getModelQueryInstance()->get(); return $brands->map( - fn ($brand) => $this->present($request, $brand), + fn ($brand): \Spatie\LaravelData\Data => $this->present($request, $brand), ); } diff --git a/src/StarterKits/Stores/Lunar/Resources/Catalog/Brands/Presenters/Brand/Brand.php b/src/StarterKits/Stores/Lunar/Resources/Catalog/Brands/Presenters/Brand/Brand.php index 73ebbe8..300fcf7 100644 --- a/src/StarterKits/Stores/Lunar/Resources/Catalog/Brands/Presenters/Brand/Brand.php +++ b/src/StarterKits/Stores/Lunar/Resources/Catalog/Brands/Presenters/Brand/Brand.php @@ -32,7 +32,7 @@ public function transform(): BrandData | Data protected function getBrandSlug(): string { - return $this->model->urls->first(function (Url $url) { + return $this->model->urls->first(function (Url $url): bool { $matchesLocale = $url->language->code === app()->getLocale(); return $matchesLocale || $url->language->code === config('app.fallback_locale'); @@ -42,7 +42,7 @@ protected function getBrandSlug(): string protected function getImage(): ?MediaData { $mediaItem = $this->model->getFirstMedia('images'); - if (! $mediaItem) { + if (!$mediaItem instanceof \Spatie\MediaLibrary\MediaCollections\Models\Media) { return null; } diff --git a/src/StarterKits/Stores/Lunar/Resources/Catalog/CollectionGroups/CollectionGroupResourceController.php b/src/StarterKits/Stores/Lunar/Resources/Catalog/CollectionGroups/CollectionGroupResourceController.php index 0a50a03..c2c9159 100644 --- a/src/StarterKits/Stores/Lunar/Resources/Catalog/CollectionGroups/CollectionGroupResourceController.php +++ b/src/StarterKits/Stores/Lunar/Resources/Catalog/CollectionGroups/CollectionGroupResourceController.php @@ -18,7 +18,7 @@ public function index(Request $request): Collection $collectionGroups = $this->getModelQueryInstance()->get(); return $collectionGroups->map( - fn ($collectionGroup) => $this->present($request, $collectionGroup), + fn ($collectionGroup): \Spatie\LaravelData\Data => $this->present($request, $collectionGroup), ); } diff --git a/src/StarterKits/Stores/Lunar/Resources/Catalog/CollectionGroups/Presenters/CategoryTree/Concerns/WithGenerateCollectionsTree.php b/src/StarterKits/Stores/Lunar/Resources/Catalog/CollectionGroups/Presenters/CategoryTree/Concerns/WithGenerateCollectionsTree.php index 507f4d6..0179ba4 100644 --- a/src/StarterKits/Stores/Lunar/Resources/Catalog/CollectionGroups/Presenters/CategoryTree/Concerns/WithGenerateCollectionsTree.php +++ b/src/StarterKits/Stores/Lunar/Resources/Catalog/CollectionGroups/Presenters/CategoryTree/Concerns/WithGenerateCollectionsTree.php @@ -9,14 +9,12 @@ trait WithGenerateCollectionsTree { public function generateTree(\Illuminate\Support\Collection $collections): array { - return $collections->map(function (Collection $collection) { - return [ - 'id' => $collection->id, - 'name' => $collection->translateAttribute('name'), - 'slug' => $this->generateSlugComputed($collection), - 'children' => $this->generateTree($collection->children), - ]; - })->toArray(); + return $collections->map(fn(Collection $collection): array => [ + 'id' => $collection->id, + 'name' => $collection->translateAttribute('name'), + 'slug' => $this->generateSlugComputed($collection), + 'children' => $this->generateTree($collection->children), + ])->toArray(); } protected function generateSlugComputed(Collection $collection): string diff --git a/src/StarterKits/Stores/Lunar/Resources/Catalog/CollectionGroups/Presenters/CategoryTree/Data/TreeData.php b/src/StarterKits/Stores/Lunar/Resources/Catalog/CollectionGroups/Presenters/CategoryTree/Data/TreeData.php index aed168a..af97e5c 100644 --- a/src/StarterKits/Stores/Lunar/Resources/Catalog/CollectionGroups/Presenters/CategoryTree/Data/TreeData.php +++ b/src/StarterKits/Stores/Lunar/Resources/Catalog/CollectionGroups/Presenters/CategoryTree/Data/TreeData.php @@ -22,7 +22,7 @@ public static function fromModel(Model $model, array $categories): self id: $model->getKey(), name: $model->name ?? '', categories: collect($categories)->map( - fn (array $category) => CategoryData::from($category) + fn (array $category): \XtendPackages\RESTPresenter\StarterKits\Stores\Lunar\Resources\Catalog\CollectionGroups\Presenters\CategoryTree\Data\CategoryData => CategoryData::from($category) ), ); } diff --git a/src/StarterKits/Stores/Lunar/Resources/Catalog/Collections/CollectionResourceController.php b/src/StarterKits/Stores/Lunar/Resources/Catalog/Collections/CollectionResourceController.php index 969944f..247d41b 100644 --- a/src/StarterKits/Stores/Lunar/Resources/Catalog/Collections/CollectionResourceController.php +++ b/src/StarterKits/Stores/Lunar/Resources/Catalog/Collections/CollectionResourceController.php @@ -18,7 +18,7 @@ public function index(Request $request): \Illuminate\Support\Collection $collections = $this->getModelQueryInstance()->get(); return $collections->map( - fn ($collection) => $this->present($request, $collection), + fn ($collection): \Spatie\LaravelData\Data => $this->present($request, $collection), ); } diff --git a/src/StarterKits/Stores/Lunar/Resources/Catalog/Collections/Presenters/Category/Category.php b/src/StarterKits/Stores/Lunar/Resources/Catalog/Collections/Presenters/Category/Category.php index 98cd293..6e68bea 100644 --- a/src/StarterKits/Stores/Lunar/Resources/Catalog/Collections/Presenters/Category/Category.php +++ b/src/StarterKits/Stores/Lunar/Resources/Catalog/Collections/Presenters/Category/Category.php @@ -33,7 +33,7 @@ public function transform(): CategoryData | Data protected function getStyleSlug(): string { - return $this->model->urls->first(function (Url $url) { + return $this->model->urls->first(function (Url $url): bool { $matchesLocale = $url->language->code === app()->getLocale(); return $matchesLocale || $url->language->code === config('app.fallback_locale'); @@ -43,7 +43,7 @@ protected function getStyleSlug(): string protected function getBanner(): ?MediaData { $mediaItem = $this->model->getFirstMedia('images'); - if (! $mediaItem) { + if (!$mediaItem instanceof \Spatie\MediaLibrary\MediaCollections\Models\Media) { return null; } diff --git a/src/StarterKits/Stores/Lunar/Resources/Catalog/Products/ProductResourceController.php b/src/StarterKits/Stores/Lunar/Resources/Catalog/Products/ProductResourceController.php index 01e7e32..a1f69d4 100644 --- a/src/StarterKits/Stores/Lunar/Resources/Catalog/Products/ProductResourceController.php +++ b/src/StarterKits/Stores/Lunar/Resources/Catalog/Products/ProductResourceController.php @@ -21,7 +21,7 @@ public function index(Request $request): Collection $products = $this->getModelQueryInstance()->get(); return $products->map( - fn ($product) => $this->present($request, $product), + fn ($product): \Spatie\LaravelData\Data => $this->present($request, $product), ); } diff --git a/src/StarterKits/Stores/Lunar/Routes/api.php b/src/StarterKits/Stores/Lunar/Routes/api.php index 37017fa..65df20c 100644 --- a/src/StarterKits/Stores/Lunar/Routes/api.php +++ b/src/StarterKits/Stores/Lunar/Routes/api.php @@ -4,6 +4,6 @@ Route::name('api.v1.')->prefix('api/v1') ->middleware(config('rest-presenter.api.middleware')) - ->group(function () { + ->group(function (): void { Route::name('catalog:')->prefix('catalog')->group(__DIR__ . '/catalog.php'); }); diff --git a/src/StarterKits/Stores/Lunar/Tests/Catalog/Brands/BrandsFeatureTest.php b/src/StarterKits/Stores/Lunar/Tests/Catalog/Brands/BrandsFeatureTest.php index 8442661..2af1622 100644 --- a/src/StarterKits/Stores/Lunar/Tests/Catalog/Brands/BrandsFeatureTest.php +++ b/src/StarterKits/Stores/Lunar/Tests/Catalog/Brands/BrandsFeatureTest.php @@ -6,7 +6,7 @@ use function Pest\Laravel\getJson; $brandsNb = 10; -beforeEach(function () use ($brandsNb) { +beforeEach(function () use ($brandsNb): void { $this->brands = Brand::factory()->count($brandsNb)->create(); }); @@ -16,8 +16,8 @@ } }); -describe('Brands', function () { - test('can show a brand', function (Brand $brand) { +describe('Brands', function (): void { + test('can show a brand', function (Brand $brand): void { $response = getJson( uri: route('api.v1.catalog:brands.show', $brand), )->assertOk()->json(); @@ -32,7 +32,7 @@ ); })->with('brands'); - test('can list all brands', function () { + test('can list all brands', function (): void { $response = getJson( uri: route('api.v1.catalog:brands.index'), )->assertOk()->json(); diff --git a/src/StarterKits/Stores/Lunar/Tests/Catalog/Brands/Presenters/Brand/BrandFeatureTest.php b/src/StarterKits/Stores/Lunar/Tests/Catalog/Brands/Presenters/Brand/BrandFeatureTest.php index c1fd52c..454c41b 100644 --- a/src/StarterKits/Stores/Lunar/Tests/Catalog/Brands/Presenters/Brand/BrandFeatureTest.php +++ b/src/StarterKits/Stores/Lunar/Tests/Catalog/Brands/Presenters/Brand/BrandFeatureTest.php @@ -7,7 +7,7 @@ use function Pest\Laravel\getJson; -beforeEach(function () { +beforeEach(function (): void { Language::factory()->create(['code' => 'en']); $this->brand = Brand::factory() ->state(['name' => 'New Brand']) @@ -15,8 +15,8 @@ ->create(); }); -describe('Brand Presenter', function () { - test('transforms brand using Brand Presenter', function () { +describe('Brand Presenter', function (): void { + test('transforms brand using Brand Presenter', function (): void { $response = getJson( uri: route('api.v1.catalog:brands.show', $this->brand), headers: ['x-rest-presenter' => 'Brand'], diff --git a/src/StarterKits/Stores/Lunar/Tests/Catalog/Brands/Presenters/Brand/BrandUnitTest.php b/src/StarterKits/Stores/Lunar/Tests/Catalog/Brands/Presenters/Brand/BrandUnitTest.php index b8b3139..acfce74 100644 --- a/src/StarterKits/Stores/Lunar/Tests/Catalog/Brands/Presenters/Brand/BrandUnitTest.php +++ b/src/StarterKits/Stores/Lunar/Tests/Catalog/Brands/Presenters/Brand/BrandUnitTest.php @@ -9,7 +9,7 @@ use XtendPackages\RESTPresenter\StarterKits\Stores\Lunar\Resources\Catalog\Brands\Presenters\Brand\Brand as BrandPresenter; use XtendPackages\RESTPresenter\StarterKits\Stores\Lunar\Resources\Catalog\Brands\Presenters\Brand\Data\BrandData; -beforeEach(function () { +beforeEach(function (): void { $this->request = mock(Request::class); $this->language = mock(Language::class); $this->url = mock(Url::class); @@ -39,8 +39,8 @@ ])); }); -describe('Brand Presenter', function () { - test('Brand::transform returns the correct data', function () { +describe('Brand Presenter', function (): void { + test('Brand::transform returns the correct data', function (): void { $result = $this->brand->transform(); diff --git a/src/StarterKits/Stores/Lunar/Tests/Catalog/CollectionGroups/CollectionGroupsFeatureTest.php b/src/StarterKits/Stores/Lunar/Tests/Catalog/CollectionGroups/CollectionGroupsFeatureTest.php index 3b210ae..3606491 100644 --- a/src/StarterKits/Stores/Lunar/Tests/Catalog/CollectionGroups/CollectionGroupsFeatureTest.php +++ b/src/StarterKits/Stores/Lunar/Tests/Catalog/CollectionGroups/CollectionGroupsFeatureTest.php @@ -5,7 +5,7 @@ use function Pest\Laravel\getJson; -beforeEach(function () { +beforeEach(function (): void { $this->collectionGroups = CollectionGroup::factory()->count(5)->create(); }); @@ -15,8 +15,8 @@ } }); -describe('CollectionGroups', function () { - test('can show a collection', function (CollectionGroup $collectionGroup) { +describe('CollectionGroups', function (): void { + test('can show a collection', function (CollectionGroup $collectionGroup): void { $response = getJson( uri: route('api.v1.catalog:collection-groups.show', $collectionGroup), )->assertOk()->json(); @@ -28,7 +28,7 @@ ); })->with('collectionGroups'); - test('can list all collectionGroups', function () { + test('can list all collectionGroups', function (): void { $response = getJson( uri: route('api.v1.catalog:collection-groups.index'), )->assertOk()->json(); diff --git a/src/StarterKits/Stores/Lunar/Tests/Catalog/CollectionGroups/Presenters/CategoryTree/CategoryTreeFeatureTest.php b/src/StarterKits/Stores/Lunar/Tests/Catalog/CollectionGroups/Presenters/CategoryTree/CategoryTreeFeatureTest.php index 533a8a2..861ae01 100644 --- a/src/StarterKits/Stores/Lunar/Tests/Catalog/CollectionGroups/Presenters/CategoryTree/CategoryTreeFeatureTest.php +++ b/src/StarterKits/Stores/Lunar/Tests/Catalog/CollectionGroups/Presenters/CategoryTree/CategoryTreeFeatureTest.php @@ -6,7 +6,7 @@ use function Pest\Laravel\getJson; -beforeEach(function () { +beforeEach(function (): void { $this->collectionGroup = CollectionGroup::factory() ->state([ 'name' => 'Categories', @@ -22,8 +22,8 @@ ->create(); }); -describe('CategoryTree Presenter', function () { - test('transforms collection using CategoryTree Presenter', function () { +describe('CategoryTree Presenter', function (): void { + test('transforms collection using CategoryTree Presenter', function (): void { $response = getJson( uri: route('api.v1.catalog:collection-groups.show', $this->collectionGroup), headers: ['x-rest-presenter' => 'CategoryTree'], diff --git a/src/StarterKits/Stores/Lunar/Tests/Catalog/CollectionGroups/Presenters/CategoryTree/CategoryTreeUnitTest.php b/src/StarterKits/Stores/Lunar/Tests/Catalog/CollectionGroups/Presenters/CategoryTree/CategoryTreeUnitTest.php index 472a145..850b553 100644 --- a/src/StarterKits/Stores/Lunar/Tests/Catalog/CollectionGroups/Presenters/CategoryTree/CategoryTreeUnitTest.php +++ b/src/StarterKits/Stores/Lunar/Tests/Catalog/CollectionGroups/Presenters/CategoryTree/CategoryTreeUnitTest.php @@ -24,7 +24,7 @@ function mockCollection($id = null) ]); } -beforeEach(function () { +beforeEach(function (): void { $this->request = mock(Request::class); $this->collectionGroup = mock(CollectionGroup::class) ->makePartial() @@ -53,8 +53,8 @@ function mockCollection($id = null) )); }); -describe('CategoryTree Presenter', function () { - test('CategoryTree::transform returns the correct data', function () { +describe('CategoryTree Presenter', function (): void { + test('CategoryTree::transform returns the correct data', function (): void { $result = $this->categoryTree->transform(); @@ -66,7 +66,7 @@ function mockCollection($id = null) ->and($result->categories)->toHaveCount(5); // Test the categories within nested children - collect($result->categories)->each(function (CategoryData $category, $index) { + collect($result->categories)->each(function (CategoryData $category, $index): void { expect($category->id)->toBe($index + 1) ->and($category->name)->toBe('Category ' . ($index + 1)) ->and($category->slug)->toBe(($index + 1) . '-category-' . ($index + 1)) diff --git a/src/StarterKits/Stores/Lunar/Tests/Catalog/Collections/CollectionsFeatureTest.php b/src/StarterKits/Stores/Lunar/Tests/Catalog/Collections/CollectionsFeatureTest.php index 6a18f78..d265215 100644 --- a/src/StarterKits/Stores/Lunar/Tests/Catalog/Collections/CollectionsFeatureTest.php +++ b/src/StarterKits/Stores/Lunar/Tests/Catalog/Collections/CollectionsFeatureTest.php @@ -7,7 +7,7 @@ use function Pest\Laravel\getJson; $collectionsNb = 10; -beforeEach(function () use ($collectionsNb) { +beforeEach(function () use ($collectionsNb): void { $this->collectionGroup = CollectionGroup::factory() ->state([ 'name' => 'Categories', @@ -26,8 +26,8 @@ } }); -describe('Collections', function () { - test('can show a collection', function (Collection $collection) { +describe('Collections', function (): void { + test('can show a collection', function (Collection $collection): void { $response = getJson( uri: route('api.v1.catalog:collections.show', $collection), )->assertOk()->json(); @@ -39,7 +39,7 @@ ); })->with('collections'); - test('can list all collections for a specific collection group', function () { + test('can list all collections for a specific collection group', function (): void { $filters = [ 'collection_group_id' => $this->collectionGroup->id, ]; @@ -56,7 +56,7 @@ ->toHaveCount($this->collections->count()); }); - test('can list all collections', function () { + test('can list all collections', function (): void { $response = getJson( uri: route('api.v1.catalog:collections.index'), )->assertOk()->json(); diff --git a/src/StarterKits/Stores/Lunar/Tests/Catalog/Collections/Filters/CollectionGroup/CollectionGroupFeatureTest.php b/src/StarterKits/Stores/Lunar/Tests/Catalog/Collections/Filters/CollectionGroup/CollectionGroupFeatureTest.php index 5dc32de..7660d2b 100644 --- a/src/StarterKits/Stores/Lunar/Tests/Catalog/Collections/Filters/CollectionGroup/CollectionGroupFeatureTest.php +++ b/src/StarterKits/Stores/Lunar/Tests/Catalog/Collections/Filters/CollectionGroup/CollectionGroupFeatureTest.php @@ -6,7 +6,7 @@ use function Pest\Laravel\getJson; -beforeEach(function () { +beforeEach(function (): void { Collection::factory()->count(20)->create(); $this->collectionGroup = CollectionGroup::factory() ->state([ @@ -19,8 +19,8 @@ $this->collections = $this->collectionGroup->collections; }); -describe('CollectionGroup Filter', function () { - test('can list all collections for a specific collection group', function () { +describe('CollectionGroup Filter', function (): void { + test('can list all collections for a specific collection group', function (): void { $filters = [ 'collection_group_id' => $this->collectionGroup->id, ]; diff --git a/src/StarterKits/Stores/Lunar/Tests/Catalog/Collections/Filters/CollectionGroup/CollectionGroupUnitTest.php b/src/StarterKits/Stores/Lunar/Tests/Catalog/Collections/Filters/CollectionGroup/CollectionGroupUnitTest.php index ec081dd..7ae674e 100644 --- a/src/StarterKits/Stores/Lunar/Tests/Catalog/Collections/Filters/CollectionGroup/CollectionGroupUnitTest.php +++ b/src/StarterKits/Stores/Lunar/Tests/Catalog/Collections/Filters/CollectionGroup/CollectionGroupUnitTest.php @@ -6,7 +6,7 @@ use XtendPackages\RESTPresenter\Concerns\WithResourceFiltering; use XtendPackages\RESTPresenter\StarterKits\Stores\Lunar\Resources\Catalog\Collections\Filters; -beforeEach(function () { +beforeEach(function (): void { $this->resourceController = new class() { use InteractsWithModel; use WithResourceFiltering; @@ -25,9 +25,9 @@ public function filters(): array }; }); -describe('CollectionGroup Filter', function () { +describe('CollectionGroup Filter', function (): void { test('CollectionGroup::handle modifies the query if collection_group_id filter is present in the request', - function () { + function (): void { $request = new Request(); $request->merge(['filters' => ['collection_group_id' => 1]]); app()->instance('request', $request); @@ -40,7 +40,7 @@ function () { }); test('CollectionGroup::handle does not modify the query if collection_group_id filter is not present in the request', - function () { + function (): void { $request = new Request(); app()->instance('request', $request); diff --git a/src/StarterKits/Stores/Lunar/Tests/Catalog/Collections/Presenters/Category/CategoryFeatureTest.php b/src/StarterKits/Stores/Lunar/Tests/Catalog/Collections/Presenters/Category/CategoryFeatureTest.php index ca83a98..ec58861 100644 --- a/src/StarterKits/Stores/Lunar/Tests/Catalog/Collections/Presenters/Category/CategoryFeatureTest.php +++ b/src/StarterKits/Stores/Lunar/Tests/Catalog/Collections/Presenters/Category/CategoryFeatureTest.php @@ -8,7 +8,7 @@ use function Pest\Laravel\getJson; -beforeEach(function () { +beforeEach(function (): void { Language::factory()->create(['code' => 'en']); $this->collectionGroup = CollectionGroup::factory() ->state([ @@ -23,8 +23,8 @@ ->create(); }); -describe('Category Presenter', function () { - test('transforms collection using Category Presenter', function () { +describe('Category Presenter', function (): void { + test('transforms collection using Category Presenter', function (): void { $response = getJson( uri: route('api.v1.catalog:collections.show', ['collection' => 1]), headers: ['x-rest-presenter' => 'Category'], diff --git a/src/StarterKits/Stores/Lunar/Tests/Catalog/Collections/Presenters/Category/CategoryUnitTest.php b/src/StarterKits/Stores/Lunar/Tests/Catalog/Collections/Presenters/Category/CategoryUnitTest.php index f4cc482..8a93a6d 100644 --- a/src/StarterKits/Stores/Lunar/Tests/Catalog/Collections/Presenters/Category/CategoryUnitTest.php +++ b/src/StarterKits/Stores/Lunar/Tests/Catalog/Collections/Presenters/Category/CategoryUnitTest.php @@ -9,7 +9,7 @@ use XtendPackages\RESTPresenter\StarterKits\Stores\Lunar\Resources\Catalog\Collections\Presenters\Category\Category; use XtendPackages\RESTPresenter\StarterKits\Stores\Lunar\Resources\Catalog\Collections\Presenters\Category\Data\CategoryData; -beforeEach(function () { +beforeEach(function (): void { $this->request = mock(Request::class); $this->language = mock(Language::class); $this->url = mock(Url::class); @@ -44,8 +44,8 @@ ])); }); -describe('Category Presenter', function () { - test('Category::transform returns the correct data', function () { +describe('Category Presenter', function (): void { + test('Category::transform returns the correct data', function (): void { $result = $this->category->transform(); diff --git a/src/StarterKits/Stores/Lunar/Tests/Catalog/Products/Filters/Brand/BrandFeatureTest.php b/src/StarterKits/Stores/Lunar/Tests/Catalog/Products/Filters/Brand/BrandFeatureTest.php index beba8b0..fac329b 100644 --- a/src/StarterKits/Stores/Lunar/Tests/Catalog/Products/Filters/Brand/BrandFeatureTest.php +++ b/src/StarterKits/Stores/Lunar/Tests/Catalog/Products/Filters/Brand/BrandFeatureTest.php @@ -7,7 +7,7 @@ use function Pest\Laravel\getJson; -beforeEach(function () { +beforeEach(function (): void { Product::factory()->count(10)->create(); $this->brand = Brand::factory() @@ -23,8 +23,8 @@ ->create(); }); -describe('Brand Filter', function () { - test('can list all products by brand', function () { +describe('Brand Filter', function (): void { + test('can list all products by brand', function (): void { $filters = [ 'brand_id' => $this->brand->id, ]; diff --git a/src/StarterKits/Stores/Lunar/Tests/Catalog/Products/Filters/Brand/BrandUnitTest.php b/src/StarterKits/Stores/Lunar/Tests/Catalog/Products/Filters/Brand/BrandUnitTest.php index 106d337..4f19e13 100644 --- a/src/StarterKits/Stores/Lunar/Tests/Catalog/Products/Filters/Brand/BrandUnitTest.php +++ b/src/StarterKits/Stores/Lunar/Tests/Catalog/Products/Filters/Brand/BrandUnitTest.php @@ -6,7 +6,7 @@ use XtendPackages\RESTPresenter\Concerns\WithResourceFiltering; use XtendPackages\RESTPresenter\StarterKits\Stores\Lunar\Resources\Catalog\Products\Filters; -beforeEach(function () { +beforeEach(function (): void { $this->resourceController = new class() { use InteractsWithModel; use WithResourceFiltering; @@ -25,9 +25,9 @@ public function filters(): array }; }); -describe('Brand Filter', function () { +describe('Brand Filter', function (): void { test('Brand::handle modifies the query to filter by brand_id', - function () { + function (): void { $request = new Request(); $request->merge(['filters' => ['brand_id' => 1]]); app()->instance('request', $request); @@ -40,7 +40,7 @@ function () { }); test('Brand::handle does not modify the query if brand_id is not present in the request', - function () { + function (): void { $request = new Request(); app()->instance('request', $request); diff --git a/src/StarterKits/Stores/Lunar/Tests/Catalog/Products/Filters/Status/StatusFeatureTest.php b/src/StarterKits/Stores/Lunar/Tests/Catalog/Products/Filters/Status/StatusFeatureTest.php index af513ef..7a77137 100644 --- a/src/StarterKits/Stores/Lunar/Tests/Catalog/Products/Filters/Status/StatusFeatureTest.php +++ b/src/StarterKits/Stores/Lunar/Tests/Catalog/Products/Filters/Status/StatusFeatureTest.php @@ -5,7 +5,7 @@ use function Pest\Laravel\getJson; -beforeEach(function () { +beforeEach(function (): void { $this->publishedProducts = Product::factory() ->state(['status' => 'published']) ->count(10) @@ -16,8 +16,8 @@ ->create(); }); -describe('Status Filter', function () { - test('can list all products with published status', function () { +describe('Status Filter', function (): void { + test('can list all products with published status', function (): void { $filters = [ 'status' => 'published', ]; @@ -38,7 +38,7 @@ ); }); - test('can list all products with draft status', function () { + test('can list all products with draft status', function (): void { $filters = [ 'status' => 'draft', ]; diff --git a/src/StarterKits/Stores/Lunar/Tests/Catalog/Products/Filters/Status/StatusUnitTest.php b/src/StarterKits/Stores/Lunar/Tests/Catalog/Products/Filters/Status/StatusUnitTest.php index 5e47bd3..7fb74d3 100644 --- a/src/StarterKits/Stores/Lunar/Tests/Catalog/Products/Filters/Status/StatusUnitTest.php +++ b/src/StarterKits/Stores/Lunar/Tests/Catalog/Products/Filters/Status/StatusUnitTest.php @@ -6,7 +6,7 @@ use XtendPackages\RESTPresenter\Concerns\WithResourceFiltering; use XtendPackages\RESTPresenter\StarterKits\Stores\Lunar\Resources\Catalog\Products\Filters; -beforeEach(function () { +beforeEach(function (): void { $this->resourceController = new class() { use InteractsWithModel; use WithResourceFiltering; @@ -25,9 +25,9 @@ public function filters(): array }; }); -describe('Status Filter', function () { +describe('Status Filter', function (): void { test('Status::handle modifies the query to filter by status by published', - function () { + function (): void { $request = new Request(); $request->merge(['filters' => ['status' => 'published']]); app()->instance('request', $request); @@ -40,7 +40,7 @@ function () { }); test('Status::handle modifies the query to filter by status by draft', - function () { + function (): void { $request = new Request(); $request->merge(['filters' => ['status' => 'draft']]); app()->instance('request', $request); @@ -53,7 +53,7 @@ function () { }); test('Status::handle does not modify the query if status filter is not present in the request', - function () { + function (): void { $request = new Request(); app()->instance('request', $request); diff --git a/src/StarterKits/Stores/Lunar/Tests/Catalog/Products/Presenters/Detail/DetailFeatureTest.php b/src/StarterKits/Stores/Lunar/Tests/Catalog/Products/Presenters/Detail/DetailFeatureTest.php index 7c07177..8a54830 100644 --- a/src/StarterKits/Stores/Lunar/Tests/Catalog/Products/Presenters/Detail/DetailFeatureTest.php +++ b/src/StarterKits/Stores/Lunar/Tests/Catalog/Products/Presenters/Detail/DetailFeatureTest.php @@ -9,7 +9,7 @@ use function Pest\Laravel\getJson; -beforeEach(function () { +beforeEach(function (): void { Language::factory()->create(['code' => 'en']); $product = Product::factory() ->has(Url::factory()->state(['language_id' => 1])) @@ -29,8 +29,8 @@ $this->product = $product; }); -describe('Detail Presenter', function () { - test('transforms collection using Detail Presenter', function () { +describe('Detail Presenter', function (): void { + test('transforms collection using Detail Presenter', function (): void { $response = getJson( uri: route('api.v1.catalog:products.show', ['product' => 1]), headers: ['x-rest-presenter' => 'Detail'], diff --git a/src/StarterKits/Stores/Lunar/Tests/Catalog/Products/Presenters/Detail/DetailUnitTest.php b/src/StarterKits/Stores/Lunar/Tests/Catalog/Products/Presenters/Detail/DetailUnitTest.php index 348ba6f..629a713 100644 --- a/src/StarterKits/Stores/Lunar/Tests/Catalog/Products/Presenters/Detail/DetailUnitTest.php +++ b/src/StarterKits/Stores/Lunar/Tests/Catalog/Products/Presenters/Detail/DetailUnitTest.php @@ -13,7 +13,7 @@ use XtendPackages\RESTPresenter\StarterKits\Stores\Lunar\Resources\Catalog\Products\Presenters\Detail\Data\StyleData; use XtendPackages\RESTPresenter\StarterKits\Stores\Lunar\Resources\Catalog\Products\Presenters\Detail\Detail; -beforeEach(function () { +beforeEach(function (): void { $this->request = mock(Request::class); $this->currency = mock(Currency::class); $this->language = mock(Language::class) @@ -78,8 +78,8 @@ ])); }); -describe('Detail Presenter', function () { - test('Detail::transform returns the correct data', function () { +describe('Detail Presenter', function (): void { + test('Detail::transform returns the correct data', function (): void { $result = $this->detail->transform(); diff --git a/src/StarterKits/Stores/Lunar/Tests/Catalog/Products/Presenters/Item/ItemFeatureTest.php b/src/StarterKits/Stores/Lunar/Tests/Catalog/Products/Presenters/Item/ItemFeatureTest.php index 9ec6ff0..c968b07 100644 --- a/src/StarterKits/Stores/Lunar/Tests/Catalog/Products/Presenters/Item/ItemFeatureTest.php +++ b/src/StarterKits/Stores/Lunar/Tests/Catalog/Products/Presenters/Item/ItemFeatureTest.php @@ -10,7 +10,7 @@ use function Pest\Laravel\getJson; -beforeEach(function () { +beforeEach(function (): void { Language::factory()->create(['code' => 'en']); $product = Product::factory() ->has(Url::factory()->state(['language_id' => 1])) @@ -41,8 +41,8 @@ $this->product = $product; }); -describe('Item Presenter', function () { - test('transforms collection using Item Presenter', function () { +describe('Item Presenter', function (): void { + test('transforms collection using Item Presenter', function (): void { $response = getJson( uri: route('api.v1.catalog:products.show', ['product' => 1]), headers: ['x-rest-presenter' => 'Item'], diff --git a/src/StarterKits/Stores/Lunar/Tests/Catalog/Products/Presenters/Item/ItemUnitTest.php b/src/StarterKits/Stores/Lunar/Tests/Catalog/Products/Presenters/Item/ItemUnitTest.php index b45eb67..ea1f62f 100644 --- a/src/StarterKits/Stores/Lunar/Tests/Catalog/Products/Presenters/Item/ItemUnitTest.php +++ b/src/StarterKits/Stores/Lunar/Tests/Catalog/Products/Presenters/Item/ItemUnitTest.php @@ -15,7 +15,7 @@ use XtendPackages\RESTPresenter\StarterKits\Stores\Lunar\Resources\Catalog\Products\Presenters\Item\Data\ItemData; use XtendPackages\RESTPresenter\StarterKits\Stores\Lunar\Resources\Catalog\Products\Presenters\Item\Item; -beforeEach(function () { +beforeEach(function (): void { $this->request = mock(Request::class); $this->currency = mock(Currency::class) ->makePartial() @@ -85,8 +85,8 @@ ])); }); -describe('Item Presenter', function () { - test('Item::transform returns the correct data', function () { +describe('Item Presenter', function (): void { + test('Item::transform returns the correct data', function (): void { $result = $this->item->transform(); diff --git a/src/StarterKits/Stores/Lunar/Tests/Catalog/Products/ProductsFeatureTest.php b/src/StarterKits/Stores/Lunar/Tests/Catalog/Products/ProductsFeatureTest.php index 30c33d4..c74d0b1 100644 --- a/src/StarterKits/Stores/Lunar/Tests/Catalog/Products/ProductsFeatureTest.php +++ b/src/StarterKits/Stores/Lunar/Tests/Catalog/Products/ProductsFeatureTest.php @@ -7,7 +7,7 @@ use function Pest\Laravel\getJson; -beforeEach(function () { +beforeEach(function (): void { $this->collectionGroup = CollectionGroup::factory() ->state([ 'name' => 'Styles', @@ -18,13 +18,13 @@ $this->collections = $this->collectionGroup->collections; - $this->collections->each(function (Collection $collection) { + $this->collections->each(function (Collection $collection): void { $collection->products()->saveMany( Product::factory() ->state([ 'status' => 'published', ]) - ->count(rand(1, 5)) + ->count(random_int(1, 5)) ->create() ); }); @@ -49,8 +49,8 @@ } }); -describe('Products', function () { - test('can show a product', function (Product $product) { +describe('Products', function (): void { + test('can show a product', function (Product $product): void { $response = getJson( uri: route('api.v1.catalog:products.show', $product), )->assertOk()->json(); @@ -62,7 +62,7 @@ ); })->with('products'); - test('can list all products', function () { + test('can list all products', function (): void { $response = getJson( uri: route('api.v1.catalog:products.index'), )->assertOk()->json(); @@ -75,7 +75,7 @@ ->toHaveCount($this->products->count()); }); - test('can list all products with published status', function () { + test('can list all products with published status', function (): void { $filters = [ 'status' => 'published', ]; @@ -98,7 +98,7 @@ ); }); - test('can list all products with draft status', function () { + test('can list all products with draft status', function (): void { $filters = [ 'status' => 'draft', ]; diff --git a/src/StarterKits/Stores/Lunar/Tests/LunarTestCase.php b/src/StarterKits/Stores/Lunar/Tests/LunarTestCase.php index 0e0c8cb..bb21d7e 100644 --- a/src/StarterKits/Stores/Lunar/Tests/LunarTestCase.php +++ b/src/StarterKits/Stores/Lunar/Tests/LunarTestCase.php @@ -28,9 +28,7 @@ protected function getEnvironmentSetUp($app): void $this->registerBlueprintMacros(); - app()->singleton(ModelManifestInterface::class, function ($app) { - return $app->make(ModelManifest::class); - }); + app()->singleton(ModelManifestInterface::class, fn($app) => $app->make(ModelManifest::class)); $app['config']->set('lunar.database.connection', 'testbench'); $app['config']->set('lunar.database.table_prefix', 'lunar_'); @@ -50,15 +48,14 @@ protected function getPackageProviders($app): array protected function registerBlueprintMacros(): void { - Blueprint::macro('scheduling', function () { + Blueprint::macro('scheduling', function (): void { /** @var Blueprint $this */ $this->boolean('enabled')->default(false)->index(); $this->timestamp('starts_at')->nullable()->index(); $this->timestamp('ends_at')->nullable()->index(); }); - Blueprint::macro('dimensions', function () { - /** @var Blueprint $this */ + Blueprint::macro('dimensions', function (): void { $columns = ['length', 'width', 'height', 'weight', 'volume']; foreach ($columns as $column) { $this->decimal("{$column}_value", 10, 4)->default(0)->nullable()->index(); @@ -66,8 +63,7 @@ protected function registerBlueprintMacros(): void } }); - Blueprint::macro('userForeignKey', function ($field_name = 'user_id', $nullable = false) { - /** @var Blueprint $this */ + Blueprint::macro('userForeignKey', function ($field_name = 'user_id', $nullable = false): void { $userModel = config('auth.providers.users.model'); $type = config('lunar.database.users_id_type', 'bigint'); diff --git a/src/Support/XtendRouter.php b/src/Support/XtendRouter.php index 1c1aefe..57fe86e 100644 --- a/src/Support/XtendRouter.php +++ b/src/Support/XtendRouter.php @@ -31,7 +31,7 @@ public function routes(): void /** @var \Illuminate\Routing\Route[] $routes */ $routes = Route::getRoutes(); - return collect($routes)->map(fn (\Illuminate\Routing\Route $route) => [ + return collect($routes)->map(fn (\Illuminate\Routing\Route $route): array => [ 'uri' => $route->uri, 'methods' => $route->methods, 'name' => $route->action['as'] ?? null, @@ -78,8 +78,6 @@ public function resources(array $resources, array $options = []): void * @param $name * @param $controller * @param array $options - * - * @return \Illuminate\Routing\PendingResourceRegistration */ public function resource($name, $controller, array $options = []): PendingResourceRegistration { @@ -97,10 +95,6 @@ public function resource($name, $controller, array $options = []): PendingResour } /** - * @param string $httpVerb - * @param string $uri - * @param string $controller - * @param string $name * @param array|null $middleware */ public function auth(string $httpVerb, string $uri, string $controller, string $name, ?array $middleware = null): void diff --git a/tests/Helpers.php b/tests/Helpers.php index ada1142..bf4e606 100644 --- a/tests/Helpers.php +++ b/tests/Helpers.php @@ -20,7 +20,7 @@ function fixture(string $name): array filename: base_path("tests/Api/Fixtures/$name.json"), ); - if (! $file) { + if ($file === '' || $file === '0' || $file === false) { throw new InvalidArgumentException( message: "Cannot find fixture: [$name] at tests/Api/Fixtures/$name.json", ); @@ -34,7 +34,7 @@ function fixture(string $name): array function getApiHeaderPresenterName(): string { - return strtolower(config('rest-presenter.api.presenter_header')); + return strtolower((string) config('rest-presenter.api.presenter_header')); } function invokeNonPublicMethod(object $object, string $methodName, array $parameters = []): mixed @@ -51,7 +51,7 @@ function getValidationRule(string $field, string $key, array $rules): mixed ->mapWithKeys( fn ($rule, $field) => [ $field => collect($rule)->mapWithKeys( - fn ($value) => formatRule($value) + fn ($value): array => formatRule($value) ), ], ) diff --git a/tests/Resources/ResourcePresenterFeatureTest.php b/tests/Resources/ResourcePresenterFeatureTest.php index 77ae9ea..cf9207b 100644 --- a/tests/Resources/ResourcePresenterFeatureTest.php +++ b/tests/Resources/ResourcePresenterFeatureTest.php @@ -5,12 +5,12 @@ use function Pest\Laravel\getJson; -beforeEach(function () { +beforeEach(function (): void { $this->user = User::factory()->create(); }); -describe('ResourcePresenter', function () { - test('can transform user resource returning default presenter', function () { +describe('ResourcePresenter', function (): void { + test('can transform user resource returning default presenter', function (): void { authenticateApiUser($this->user); $response = getJson( uri: route('api.v1.users.show', $this->user), @@ -23,7 +23,7 @@ ); }); - test('If not authenticated return unauthorized', function () { + test('If not authenticated return unauthorized', function (): void { getJson( uri: route('api.v1.users.show', $this->user), )->assertUnauthorized(); diff --git a/tests/Resources/Users/Presenters/Profile/ProfileFeatureTest.php b/tests/Resources/Users/Presenters/Profile/ProfileFeatureTest.php index 5ebf0bf..2ff0c3c 100644 --- a/tests/Resources/Users/Presenters/Profile/ProfileFeatureTest.php +++ b/tests/Resources/Users/Presenters/Profile/ProfileFeatureTest.php @@ -4,12 +4,12 @@ use function Pest\Laravel\getJson; -beforeEach(function () { +beforeEach(function (): void { $this->user = authenticateApiUser(); }); -describe('Profile Presenter', function () { - test('transforms user using Profile Presenter', function () { +describe('Profile Presenter', function (): void { + test('transforms user using Profile Presenter', function (): void { $response = getJson( uri: route('api.v1.users.show', $this->user), headers: ['x-rest-presenter' => 'profile'], diff --git a/tests/Resources/Users/Presenters/Profile/ProfileUnitTest.php b/tests/Resources/Users/Presenters/Profile/ProfileUnitTest.php index 285c175..0be259c 100644 --- a/tests/Resources/Users/Presenters/Profile/ProfileUnitTest.php +++ b/tests/Resources/Users/Presenters/Profile/ProfileUnitTest.php @@ -6,7 +6,7 @@ use XtendPackages\RESTPresenter\Resources\Users\Data\Response\ProfileData; use XtendPackages\RESTPresenter\Resources\Users\Presenters; -beforeEach(function () { +beforeEach(function (): void { $this->request = mock(Request::class); $this->mockUser = mock(User::class) ->makePartial() @@ -32,8 +32,8 @@ $this->data = $this->response->toArray(); }); -describe('Profile Presenter', function () { - test('Profile::transform returns the correct data', function () { +describe('Profile Presenter', function (): void { + test('Profile::transform returns the correct data', function (): void { $this->response->validate($this->data); expect($this->response)->toBeInstanceOf(ProfileData::class) @@ -46,7 +46,7 @@ }); - test('Profile::transform data name validation fails', function () { + test('Profile::transform data name validation fails', function (): void { $this->data['firstName'] = 'ok'; $rules = $this->response->getValidationRules($this->data); @@ -58,7 +58,7 @@ $this->response->validate($this->data); }); - test('Profile::transform data email validation fails', function () { + test('Profile::transform data email validation fails', function (): void { $this->data['email'] = 'invalid-email'; $this->expectException(ValidationException::class); diff --git a/tests/Resources/Users/Presenters/User/UserFeatureTest.php b/tests/Resources/Users/Presenters/User/UserFeatureTest.php index 3a42475..78dd18f 100644 --- a/tests/Resources/Users/Presenters/User/UserFeatureTest.php +++ b/tests/Resources/Users/Presenters/User/UserFeatureTest.php @@ -4,12 +4,12 @@ use function Pest\Laravel\getJson; -beforeEach(function () { +beforeEach(function (): void { $this->user = authenticateApiUser(); }); -describe('User Presenter', function () { - test('transforms user using User Presenter', function () { +describe('User Presenter', function (): void { + test('transforms user using User Presenter', function (): void { $response = getJson( uri: route('api.v1.users.show', $this->user), headers: ['x-rest-presenter' => 'user'], diff --git a/tests/Resources/Users/Presenters/User/UserUnitTest.php b/tests/Resources/Users/Presenters/User/UserUnitTest.php index 6c11cb5..269b82a 100644 --- a/tests/Resources/Users/Presenters/User/UserUnitTest.php +++ b/tests/Resources/Users/Presenters/User/UserUnitTest.php @@ -6,7 +6,7 @@ use XtendPackages\RESTPresenter\Resources\Users\Data\Response\UserData; use XtendPackages\RESTPresenter\Resources\Users\Presenters; -beforeEach(function () { +beforeEach(function (): void { $this->request = mock(Request::class); $this->mockUser = mock(User::class) ->makePartial() @@ -32,8 +32,8 @@ $this->data = $this->response->toArray(); }); -describe('User Presenter', function () { - test('User::transform returns the correct data', function () { +describe('User Presenter', function (): void { + test('User::transform returns the correct data', function (): void { $this->response->validate($this->data); expect($this->response)->toBeInstanceOf(UserData::class) @@ -48,7 +48,7 @@ }); - test('User::transform data name validation fails', function () { + test('User::transform data name validation fails', function (): void { $this->data['name'] = 'ok'; $rules = $this->response->getValidationRules($this->data); @@ -60,7 +60,7 @@ $this->response->validate($this->data); }); - test('User::transform data email validation fails', function () { + test('User::transform data email validation fails', function (): void { $this->data['email'] = 'invalid-email'; $this->expectException(ValidationException::class); diff --git a/tests/Resources/Users/UsersFeatureTest.php b/tests/Resources/Users/UsersFeatureTest.php index e05fe1e..e514f51 100644 --- a/tests/Resources/Users/UsersFeatureTest.php +++ b/tests/Resources/Users/UsersFeatureTest.php @@ -5,7 +5,7 @@ use function Pest\Laravel\getJson; -beforeEach(function () { +beforeEach(function (): void { $this->users = User::factory()->count(10)->create()->fresh(); authenticateApiUser($this->users->first()); }); @@ -16,8 +16,8 @@ } }); -describe('Users', function () { - test('can show a user', function (User $user) { +describe('Users', function (): void { + test('can show a user', function (User $user): void { $response = getJson( uri: route('api.v1.users.show', $user), headers: ['x-rest-presenter' => 'user'], @@ -30,7 +30,7 @@ ); })->with('users'); - test('can list all users', function () { + test('can list all users', function (): void { $response = getJson( uri: route('api.v1.users.index'), headers: ['x-rest-presenter' => 'user'], diff --git a/tests/Support/Concerns/InteractsWithModelTest.php b/tests/Support/Concerns/InteractsWithModelTest.php index b460d6c..0f3db56 100644 --- a/tests/Support/Concerns/InteractsWithModelTest.php +++ b/tests/Support/Concerns/InteractsWithModelTest.php @@ -4,20 +4,19 @@ use Illuminate\Database\Eloquent\Model; use XtendPackages\RESTPresenter\Concerns\InteractsWithModel; -test('should return correct model modified query instance', function () { +test('should return correct model modified query instance', function (): void { $mock = new class { use InteractsWithModel; public function __construct() { - static::$model = get_class(new class extends Model{}); + static::$model = (new class extends Model{})::class; } }; $query = invokeNonPublicMethod($mock, 'getModelQuery'); expect($query)->toBeInstanceOf(Builder::class); - /** @var Builder $instance */ $queryModified = $query->where('column', 'value'); invokeNonPublicMethod($mock, 'setModelQuery', [$queryModified]); diff --git a/tests/Support/Concerns/InteractsWithPresenterTest.php b/tests/Support/Concerns/InteractsWithPresenterTest.php index 696add1..8a756f4 100644 --- a/tests/Support/Concerns/InteractsWithPresenterTest.php +++ b/tests/Support/Concerns/InteractsWithPresenterTest.php @@ -8,7 +8,7 @@ use XtendPackages\RESTPresenter\Resources\Users\Presenters; use XtendPackages\RESTPresenter\Support\ResourceDefaultPresenter; -beforeEach(function () { +beforeEach(function (): void { $this->resourceController = new class { use InteractsWithPresenter; @@ -22,8 +22,8 @@ public function presenters(): array }; }); -describe('InteractsWithPresenter', function () { - test('makePresenter returns Presentable', function () { +describe('InteractsWithPresenter', function (): void { + test('makePresenter returns Presentable', function (): void { $request = mock(Request::class); $model = mock(Model::class); @@ -36,7 +36,7 @@ public function presenters(): array expect($presenter)->toBeInstanceOf(ResourceDefaultPresenter::class); }); - test('present returns correct format', function () { + test('present returns correct format', function (): void { $request = mock(Request::class); $model = Mockery::spy(Model::class); $model->shouldReceive('toArray'); @@ -81,7 +81,7 @@ public function presenters(): array expect($result)->toBeInstanceOf(Data::class); }); - test('getPresenters merges default and resource presenters', function () { + test('getPresenters merges default and resource presenters', function (): void { $presenters = invokeNonPublicMethod( object: $this->resourceController, methodName: 'getPresenters', @@ -92,7 +92,7 @@ public function presenters(): array ->toBe(ResourceDefaultPresenter::class); }); - test('getPresenterFromRequestHeader returns correct presenter from user request header is set', function () { + test('getPresenterFromRequestHeader returns correct presenter from user request header is set', function (): void { request()->headers->set(getApiHeaderPresenterName(), 'user'); $presenter = invokeNonPublicMethod( @@ -103,7 +103,7 @@ public function presenters(): array expect($presenter)->toBe(Presenters\User::class); }); - test('getPresenterFromRequestHeader throws PresenterNotFoundException when presenter key is not found', function () { + test('getPresenterFromRequestHeader throws PresenterNotFoundException when presenter key is not found', function (): void { request()->headers->set(getApiHeaderPresenterName(), 'NonExistentPresenter'); $this->expectException(PresenterNotFoundException::class); @@ -114,7 +114,7 @@ public function presenters(): array ); }); - test('getPresenterFromRequestHeader returns default presenter when request header is not set', function () { + test('getPresenterFromRequestHeader returns default presenter when request header is not set', function (): void { request()->headers->remove(getApiHeaderPresenterName()); $presenter = invokeNonPublicMethod( diff --git a/tests/Support/Concerns/InteractsWithRequestTest.php b/tests/Support/Concerns/InteractsWithRequestTest.php index b65fa95..1de5271 100644 --- a/tests/Support/Concerns/InteractsWithRequestTest.php +++ b/tests/Support/Concerns/InteractsWithRequestTest.php @@ -3,7 +3,7 @@ use Illuminate\Http\Request; use XtendPackages\RESTPresenter\Concerns\InteractsWithRequest; -beforeEach(function () { +beforeEach(function (): void { $request = new Request(); $request->merge(['filters' => ['filterKey' => 'filterValue']]); app()->instance('request', $request); @@ -18,18 +18,18 @@ public function filters(): array }; }); -describe('InteractsWithRequest', function () { - test('filterBy returns correct value', function () { +describe('InteractsWithRequest', function (): void { + test('filterBy returns correct value', function (): void { $this->assertEquals('filterValue', $this->resourceController->filterBy('filterKey')); $this->assertNull($this->resourceController->filterBy('NotExistingKey')); }); - test('hasFilter returns correct value', function () { + test('hasFilter returns correct value', function (): void { $this->assertTrue($this->resourceController->hasFilter('filterKey')); $this->assertFalse($this->resourceController->hasFilter('NotExistingKey')); }); - test('filtersFromRequest checks request for filters', function () { + test('filtersFromRequest checks request for filters', function (): void { $this->assertEquals(['filterKey' => 'filterValue'], invokeNonPublicMethod($this->resourceController, 'filtersFromRequest')); }); }); diff --git a/tests/Support/Concerns/WithResourceFilteringTest.php b/tests/Support/Concerns/WithResourceFilteringTest.php index 42dd0f7..a230659 100644 --- a/tests/Support/Concerns/WithResourceFilteringTest.php +++ b/tests/Support/Concerns/WithResourceFilteringTest.php @@ -6,7 +6,7 @@ use XtendPackages\RESTPresenter\Models\User; use XtendPackages\RESTPresenter\Resources\Users\Filters\UserEmailVerified; -beforeEach(function () { +beforeEach(function (): void { $this->resourceController = new class() { use InteractsWithModel; use WithResourceFiltering; @@ -25,8 +25,8 @@ public function filters(): array }; }); -describe('WithResourceFiltering', function () { - test('applyFilters correctly modifies the query', function () { +describe('WithResourceFiltering', function (): void { + test('applyFilters correctly modifies the query', function (): void { $request = new Request(); $request->merge(['filters' => ['email_verified_at' => now()]]); app()->instance('request', $request); @@ -38,7 +38,7 @@ public function filters(): array ->and($newQuery->toSql())->not()->toBe($originalQuery->toSql()); }); - test('getFilters returns resource filters', function () { + test('getFilters returns resource filters', function (): void { $filters = invokeNonPublicMethod($this->resourceController, 'getFilters'); expect($filters)->toBeArray()