Skip to content

Commit

Permalink
fix: Setup strict pint rules + apply fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-code-labx committed Apr 17, 2024
1 parent e305e0c commit a607023
Show file tree
Hide file tree
Showing 134 changed files with 877 additions and 590 deletions.
15 changes: 10 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,19 @@
},
"scripts": {
"post-autoload-dump": "@php ./vendor/bin/testbench package:discover --ansi",
"analyse": "vendor/bin/phpstan",
"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",
"pest": "vendor/bin/pest --testsuite=RESTPresenter",
"pest-coverage": "vendor/bin/pest --testsuite=RESTPresenter --coverage",
"pest-starter-kit:lunar": "vendor/bin/pest --testsuite=starter-kit:lunar",
"test:format": "pint --test",
"test:refactor": "rector --dry-run",
"test:types": "phpstan analyse",
"format": "vendor/bin/pint",
"refactor": "rector"
"refactor": "rector",
"test": [
"@test:format",
"@test:refactor",
"@test:types"
]
},
"config": {
"sort-packages": true,
Expand Down
2 changes: 2 additions & 0 deletions config/rest-presenter.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

use Illuminate\Routing\Middleware\SubstituteBindings;
use XtendPackages\RESTPresenter\Data\Response\DefaultResponse;
use XtendPackages\RESTPresenter\Resources\Users\Filters;
Expand Down
4 changes: 3 additions & 1 deletion database/factories/UserFactory.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?php

declare(strict_types=1);

namespace XtendPackages\RESTPresenter\Factories;

use XtendPackages\RESTPresenter\Models\User;

class UserFactory extends \Orchestra\Testbench\Factories\UserFactory
final class UserFactory extends \Orchestra\Testbench\Factories\UserFactory
{
protected $model = User::class;
}
52 changes: 37 additions & 15 deletions pint.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,43 @@
{
"preset": "laravel",
"rules": {
"braces": false,
"binary_operator_spaces": false,
"class_definition": false,
"braces_position": false,
"curly_braces_position": false,
"simplified_null_return": false,
"no_unused_imports": false,
"blank_line_before_statement": true,
"self_static_accessor": false,
"concat_space": {
"spacing": "one"
"array_push": true,
"backtick_to_shell_exec": true,
"declare_strict_types": true,
"fully_qualified_strict_types": true,
"global_namespace_import": {
"import_classes": true,
"import_constants": true,
"import_functions": true
},
"single_trait_insert_per_statement": true,
"types_spaces": {
"space": "single"
}
"ordered_class_elements": {
"order": [
"use_trait",
"case",
"constant",
"constant_public",
"constant_protected",
"constant_private",
"property_public",
"property_protected",
"property_private",
"construct",
"destruct",
"magic",
"phpunit",
"method_abstract",
"method_public_static",
"method_public",
"method_protected_static",
"method_protected",
"method_private_static",
"method_private"
],
"sort_algorithm": "none"
},
"ordered_interfaces": true,
"ordered_traits": true,
"protected_to_private": true,
"strict_comparison": true
}
}
6 changes: 4 additions & 2 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@

use Rector\Config\RectorConfig;
use Rector\Php83\Rector\ClassMethod\AddOverrideAttributeToOverriddenMethodsRector;
use Rector\Strict\Rector\BooleanNot\BooleanInBooleanNotRuleFixerRector;
use RectorLaravel\Set\LaravelSetList;

return RectorConfig::configure()
->withPaths([
__DIR__ . '/src',
__DIR__ . '/tests',
__DIR__.'/src',
__DIR__.'/tests',
])
->withSkip([
AddOverrideAttributeToOverriddenMethodsRector::class,
BooleanInBooleanNotRuleFixerRector::class,
])
->withAttributesSets(
symfony: true,
Expand Down
2 changes: 2 additions & 0 deletions resources/lang/en/auth.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

return [
'logout_device_message' => 'You have been logged out from this device.',
'logout_message' => 'You have been logged out from all devices.',
Expand Down
10 changes: 6 additions & 4 deletions src/Base/RESTPresenter.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<?php

declare(strict_types=1);

namespace XtendPackages\RESTPresenter\Base;

use Illuminate\Contracts\Foundation\Application;

class RESTPresenter
final class RESTPresenter
{
protected Application $app;
private Application $app;

public function register(Application $app): self
{
Expand All @@ -27,14 +29,14 @@ public function starterKits(array $starterKits): self
return $this;
}

protected function registerKit(string $kit): void
private function registerKit(string $kit): void
{
if (! $this->isKitRegistered($kit)) {
$this->app->register($kit);
}
}

protected function isKitRegistered(string $kit): bool
private function isKitRegistered(string $kit): bool
{
return $this->app->providerIsLoaded($kit);
}
Expand Down
6 changes: 5 additions & 1 deletion src/Base/StarterKit.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
<?php

declare(strict_types=1);

namespace XtendPackages\RESTPresenter\Base;

use Illuminate\Filesystem\Filesystem;

abstract class StarterKit
{
public function __construct(protected Filesystem $filesystem) {}
public function __construct(protected Filesystem $filesystem)
{
}

/**
* @return array<string, array<string, string>>
Expand Down
50 changes: 26 additions & 24 deletions src/Commands/Generator/MakeAction.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace XtendPackages\RESTPresenter\Commands\Generator;

use Illuminate\Console\GeneratorCommand;
Expand All @@ -8,7 +10,7 @@
use Symfony\Component\Console\Input\InputArgument;

#[AsCommand(name: 'rest-presenter:make-action')]
class MakeAction extends GeneratorCommand
final class MakeAction extends GeneratorCommand
{
protected $name = 'rest-presenter:make-action';

Expand All @@ -29,12 +31,12 @@ protected function qualifyClass($name)
return $name;
}

return $this->getDefaultNamespace($rootNamespace) . '\\' . $name;
return $this->getDefaultNamespace($rootNamespace).'\\'.$name;
}

protected function getStub(): string
{
return __DIR__ . '/stubs/' . type($this->argument('type'))->asString() . '/action.php.stub';
return __DIR__.'/stubs/'.type($this->argument('type'))->asString().'/action.php.stub';
}

protected function getDefaultNamespace($rootNamespace): string
Expand All @@ -44,10 +46,10 @@ protected function getDefaultNamespace($rootNamespace): string
$namespace = type(config('rest-presenter.generator.namespace'))->asString();

if ($this->argument('kit_namespace')) {
return $namespace . '\\' . type($this->argument('kit_namespace'))->asString() . '\\Actions';
return $namespace.'\\'.type($this->argument('kit_namespace'))->asString().'\\Actions';
}

return $namespace . '\\Resources\\' . $resourceDirectory . '\\Actions';
return $namespace.'\\Resources\\'.$resourceDirectory.'\\Actions';
}

protected function getNameInput(): string
Expand All @@ -65,35 +67,35 @@ protected function buildClass($name): string
}

/**
* @return array<string, string>
* @return array<int, array<int, int|string>>
*/
protected function buildResourceReplacements(): array
protected function getArguments(): array
{
$kitNamespace = type($this->argument('kit_namespace'))->asString();
$resourceName = type($this->argument('name'))->asString();

return [
'{{ 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',
'{{ relationship }}' => strtolower($resourceName),
'{{ relationship_search_key }}' => type($this->argument('relation_search_key') ?? '')->asString(),
['name', InputArgument::REQUIRED, 'The name of the '.strtolower($this->type)],
['resource', InputArgument::REQUIRED, 'The resource of the '.strtolower($this->type)],
['type', InputArgument::REQUIRED, 'The type of action to create'],
['relation', InputArgument::OPTIONAL, 'The relation of the '.strtolower($this->type)],
['relation_search_key', InputArgument::OPTIONAL, 'The search key of the '.strtolower($this->type)],
['kit_namespace', InputArgument::OPTIONAL, 'The namespace of the '.strtolower($this->type)],
];
}

/**
* @return array<int, array<int, int|string>>
* @return array<string, string>
*/
protected function getArguments(): array
private function buildResourceReplacements(): array
{
$kitNamespace = type($this->argument('kit_namespace'))->asString();
$resourceName = type($this->argument('name'))->asString();

return [
['name', InputArgument::REQUIRED, 'The name of the ' . strtolower($this->type)],
['resource', InputArgument::REQUIRED, 'The resource of the ' . strtolower($this->type)],
['type', InputArgument::REQUIRED, 'The type of action to create'],
['relation', InputArgument::OPTIONAL, 'The relation of the ' . strtolower($this->type)],
['relation_search_key', InputArgument::OPTIONAL, 'The search key of the ' . strtolower($this->type)],
['kit_namespace', InputArgument::OPTIONAL, 'The namespace of the ' . strtolower($this->type)],
'{{ 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',
'{{ relationship }}' => strtolower($resourceName),
'{{ relationship_search_key }}' => type($this->argument('relation_search_key') ?? '')->asString(),
];
}
}
46 changes: 24 additions & 22 deletions src/Commands/Generator/MakeController.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace XtendPackages\RESTPresenter\Commands\Generator;

use Illuminate\Console\GeneratorCommand;
Expand All @@ -12,7 +14,7 @@
use function Laravel\Prompts\select;

#[AsCommand(name: 'rest-presenter:make-controller')]
class MakeController extends GeneratorCommand
final class MakeController extends GeneratorCommand
{
protected $name = 'rest-presenter:make-controller';

Expand All @@ -22,7 +24,7 @@ class MakeController extends GeneratorCommand

protected function getStub(): string
{
return __DIR__ . '/stubs/' . type($this->argument('type'))->asString() . '/controller.php.stub';
return __DIR__.'/stubs/'.type($this->argument('type'))->asString().'/controller.php.stub';
}

protected function getDefaultNamespace($rootNamespace): string
Expand All @@ -33,10 +35,10 @@ protected function getDefaultNamespace($rootNamespace): string
$kitNamespace = type($this->argument('kit_namespace'))->asString();

if ($kitNamespace !== '' && $kitNamespace !== '0') {
return $namespace . '\\' . $kitNamespace;
return $namespace.'\\'.$kitNamespace;
}

return $namespace . '\\Controllers\\' . $controllerDirectory;
return $namespace.'\\Controllers\\'.$controllerDirectory;
}

protected function getNameInput(): string
Expand All @@ -53,30 +55,15 @@ protected function buildClass($name): string
);
}

/**
* @return array<string, string>
*/
protected function buildControllerReplacements(): array
{
$controllerName = type($this->argument('name'))->asString();

return [
'{{ controllerNamespace }}' => $this->argument('kit_namespace')
? 'XtendPackages\\RESTPresenter\\' . type($this->argument('kit_namespace'))->asString() . '\\' . $this->getNameInput()
: 'XtendPackages\\RESTPresenter\\Controllers\\' . $controllerName . '\\' . $this->getNameInput(),
'{{ aliasController }}' => 'Xtend' . $this->getNameInput(),
];
}

/**
* @return array<int, array<int, int|string>>
*/
protected function getArguments(): array
{
return [
['name', InputArgument::REQUIRED, 'The name of the ' . strtolower($this->type)],
['type', InputArgument::REQUIRED, 'The type of the ' . strtolower($this->type)],
['kit_namespace', InputArgument::OPTIONAL, 'The namespace of the ' . strtolower($this->type)],
['name', InputArgument::REQUIRED, 'The name of the '.strtolower($this->type)],
['type', InputArgument::REQUIRED, 'The type of the '.strtolower($this->type)],
['kit_namespace', InputArgument::OPTIONAL, 'The namespace of the '.strtolower($this->type)],
];
}

Expand Down Expand Up @@ -108,4 +95,19 @@ protected function afterPromptingForMissingArguments(InputInterface $input, Outp
$input->setOption(type($type)->asString(), true);
}
}

/**
* @return array<string, string>
*/
private function buildControllerReplacements(): array
{
$controllerName = type($this->argument('name'))->asString();

return [
'{{ controllerNamespace }}' => $this->argument('kit_namespace')
? 'XtendPackages\\RESTPresenter\\'.type($this->argument('kit_namespace'))->asString().'\\'.$this->getNameInput()
: 'XtendPackages\\RESTPresenter\\Controllers\\'.$controllerName.'\\'.$this->getNameInput(),
'{{ aliasController }}' => 'Xtend'.$this->getNameInput(),
];
}
}
Loading

0 comments on commit a607023

Please sign in to comment.