Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
leMaur committed Dec 16, 2021
1 parent 0bef527 commit b56c46d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 15 deletions.
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@
"rector/rector": "^0.12",
"spatie/laravel-package-tools": "^1.4.3",
"spatie/laravel-ray": "^1.9",
"spatie/pest-plugin-snapshots": "^1.0"
"spatie/pest-plugin-snapshots": "^1.0",
"thecodingmachine/phpstan-safe-rule": "^1.1",
"thecodingmachine/safe": "^1.3"
},
"autoload": {
"psr-4": {
Expand Down
17 changes: 12 additions & 5 deletions src/Commands/stubs/phpstan.neon.stub
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
parameters:
level: 8
checkMissingIterableValueType: false
paths:
- app
excludePaths:
- app/Nova/*
level: 8
includes:
- vendor/thecodingmachine/phpstan-safe-rule/phpstan-safe-rule.neon
ignoreErrors:
- '#is not allowed to extend#'
- '#has a nullable return type declaration#'
- '#should return string\|null but return statement is missing#'
checkMissingIterableValueType: false
- '#is not allowed to extend.#'
- '#Dynamic call to static method.#'
- '#has a nullable return type declaration.#'
- '#has parameter \$[a-zA-Z]+ with default value.#'
- '#has parameter \$[a-zA-Z]+ with null as default value.#'
- '#has parameter \$[a-zA-Z]+ with a nullable type declaration.#'
- '#Parameter \#[0-9] \$column of method Illuminate\\Database\\Eloquent\\Builder\<Illuminate\\Database\\Eloquent\\Model\>\:\:whereIn\(\) expects string, Illuminate\\Database\\Query\\Expression given.#'
- '#is protected, but since the containing class is final, it can be private.#'
38 changes: 29 additions & 9 deletions src/Commands/stubs/rector.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,41 @@ return static function (ContainerConfigurator $containerConfigurator): void {
// __DIR__.'/tests',
]);
$parameters->set(Option::SKIP, [
__DIR__.'/app/Nova',
// __DIR__.'/app/Actions/Fortify',
__DIR__.'/app/Exceptions',
__DIR__.'/app/Providers',
// __DIR__.'/app/Nova',
// __DIR__.'/app/Actions/Jetstream',
// __DIR__.'/app/Actions/Fortify',
// __DIR__.'/app/Http/Livewire',
]);
$parameters->set(Option::AUTO_IMPORT_NAMES, true);
$parameters->set(Option::IMPORT_SHORT_CLASSES, false);
$parameters->set(Option::IMPORT_DOC_BLOCKS, false);
$parameters->set(Option::ENABLE_CACHE, true);

if (file_exists(getcwd().'/phpstan.neon')) {
$parameters->set(Option::PHPSTAN_FOR_RECTOR_PATH, getcwd().'/phpstan.neon');
if (file_exists($neon = getcwd().'/phpstan.neon')) {
$parameters->set(Option::PHPSTAN_FOR_RECTOR_PATH, $neon);
}

$parameters->set(Option::SETS, [
SetList::CARBON_2,
SetList::CODE_QUALITY,
SetList::EARLY_RETURN,
LaravelSetList::ARRAY_STR_FUNCTIONS_TO_STATIC_CALL,
LaravelSetList::LARAVEL_ARRAY_STR_FUNCTION_TO_STATIC_CALL,
LaravelSetList::LARAVEL_CODE_QUALITY,
SetList::NAMING,
// SetList::NAMING,
SetList::ORDER,
SetList::PHP_74,
SetList::PSR_4,
SetList::SAFE_07,
SetList::TYPE_DECLARATION,
// SetList::TYPE_DECLARATION,
SetList::PRIVATIZATION,
]);

$containerConfigurator->import(PHPUnitSetList::PHPUNIT_CODE_QUALITY);
$containerConfigurator->import(PHPUnitSetList::PHPUNIT_90);
$containerConfigurator->import(PHPUnitSetList::PHPUNIT_91);
// $containerConfigurator->import(PHPUnitSetList::PHPUNIT_CODE_QUALITY);
// $containerConfigurator->import(PHPUnitSetList::PHPUNIT_90);
// $containerConfigurator->import(PHPUnitSetList::PHPUNIT_91);

$services = $containerConfigurator->services();

Expand Down Expand Up @@ -100,6 +104,16 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(\Rector\DeadCode\Rector\Assign\RemoveUnusedAssignVariableRector::class);
$services->set(\Rector\DeadCode\Rector\Ternary\TernaryToBooleanOrFalseToBooleanAndRector::class);

// Naming
// $services->set(\Rector\Naming\Rector\ClassMethod\RenameParamToMatchTypeRector::class);
// $services->set(\Rector\Naming\Rector\Class_\RenamePropertyToMatchTypeRector::class);
$services->set(\Rector\Naming\Rector\ClassMethod\RenameVariableToMatchNewTypeRector::class);
$services->set(\Rector\Naming\Rector\Assign\RenameVariableToMatchMethodCallReturnTypeRector::class);
$services->set(\Rector\Naming\Rector\ClassMethod\MakeIsserClassMethodNameStartWithIsRector::class);
$services->set(\Rector\Naming\Rector\Foreach_\RenameForeachValueVariableToMatchMethodCallReturnTypeRector::class);
$services->set(\Rector\Naming\Rector\Property\MakeBoolPropertyRespectIsHasWasMethodNamingRector::class);
$services->set(\Rector\Naming\Rector\Foreach_\RenameForeachValueVariableToMatchExprVariableRector::class);

// Php70
// https://github.com/rectorphp/rector/blob/master/docs/rector_rules_overview.md#php70
$services->set(\Rector\Php70\Rector\Ternary\TernaryToNullCoalescingRector::class);
Expand Down Expand Up @@ -159,6 +173,12 @@ return static function (ContainerConfigurator $containerConfigurator): void {
],
]]);

// Type Declaration
$services->set(\Rector\TypeDeclaration\Rector\FunctionLike\ParamTypeDeclarationRector::class);
$services->set(\Rector\TypeDeclaration\Rector\FunctionLike\ReturnTypeDeclarationRector::class);
$services->set(\Rector\TypeDeclaration\Rector\Property\PropertyTypeDeclarationRector::class);
$services->set(\Rector\TypeDeclaration\Rector\Closure\AddClosureReturnTypeRector::class);

// Restoration
// https://github.com/rectorphp/rector/blob/master/docs/rector_rules_overview.md#restoration
$services->set(\Rector\Restoration\Rector\Property\MakeTypedPropertyNullableIfCheckedRector::class);
Expand Down

0 comments on commit b56c46d

Please sign in to comment.