diff --git a/composer.json b/composer.json index 87833d3..8938230 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/src/Commands/stubs/phpstan.neon.stub b/src/Commands/stubs/phpstan.neon.stub index 0790c6f..813294a 100644 --- a/src/Commands/stubs/phpstan.neon.stub +++ b/src/Commands/stubs/phpstan.neon.stub @@ -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\\:\:whereIn\(\) expects string, Illuminate\\Database\\Query\\Expression given.#' + - '#is protected, but since the containing class is final, it can be private.#' diff --git a/src/Commands/stubs/rector.php.stub b/src/Commands/stubs/rector.php.stub index 6898927..207c4be 100644 --- a/src/Commands/stubs/rector.php.stub +++ b/src/Commands/stubs/rector.php.stub @@ -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(); @@ -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); @@ -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);