Skip to content

Commit

Permalink
refactor: update rector (#612)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbarnsley authored Mar 19, 2024
1 parent bacc29c commit f3d5e19
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 106 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"phpstan/phpstan-strict-rules": "^1.5",
"phpunit/phpunit": "^9.2",
"pragmarx/google2fa-laravel": "^2.1",
"rector/rector": "^0.17",
"rector/rector": "^0.19",
"ruafozy/mersenne-twister": "^1.0",
"spatie/laravel-flash": "^1.9",
"spatie/laravel-honeypot": "^4.3",
Expand Down
33 changes: 14 additions & 19 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion icons.html

Large diffs are not rendered by default.

154 changes: 69 additions & 85 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,103 +2,87 @@

declare(strict_types=1);

use Rector\CodeQuality\Rector\BooleanAnd\SimplifyEmptyArrayCheckRector;
use Rector\CodeQuality\Rector\BooleanNot\ReplaceMultipleBooleanNotRector;
use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\CodeQuality\Rector\Identical\GetClassToInstanceOfRector;
use Rector\CodingStyle\Rector\Assign\SplitDoubleAssignRector;
use Rector\CodingStyle\Rector\ClassConst\RemoveFinalFromConstRector;
use Rector\CodingStyle\Rector\ClassConst\SplitGroupedClassConstantsRector;
use Rector\CodingStyle\Rector\ClassMethod\FuncGetArgsToVariadicParamRector;
use Rector\CodingStyle\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector;
use Rector\CodingStyle\Rector\ClassMethod\NewlineBeforeNewAssignSetRector;
use Rector\CodingStyle\Rector\Encapsed\WrapEncapsedVariableInCurlyBracesRector;
use Rector\CodingStyle\Rector\FuncCall\CallUserFuncArrayToVariadicRector;
use Rector\CodingStyle\Rector\FuncCall\CallUserFuncToMethodCallRector;
use Rector\CodingStyle\Rector\FuncCall\ConsistentImplodeRector;
use Rector\CodingStyle\Rector\FuncCall\StrictArraySearchRector;
use Rector\CodingStyle\Rector\FuncCall\VersionCompareFuncCallToConstantRector;
use Rector\CodingStyle\Rector\Plus\UseIncrementAssignRector;
use Rector\CodingStyle\Rector\Property\SplitGroupedPropertiesRector;
use Rector\CodingStyle\Rector\Stmt\NewlineAfterStatementRector;
use Rector\CodingStyle\Rector\String_\UseClassKeywordForClassNameResolutionRector;
use Rector\CodingStyle\Rector\Ternary\TernaryConditionVariableAssignmentRector;
use Rector\Config\RectorConfig;
use Rector\Core\ValueObject\PhpVersion;
use Rector\Set\ValueObject\SetList;
use RectorLaravel\Set\LaravelSetList;
use Rector\EarlyReturn\Rector\If_\RemoveAlwaysElseRector;
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
use Rector\Privatization\Rector\ClassMethod\PrivatizeFinalClassMethodRector;
use Rector\Privatization\Rector\MethodCall\PrivatizeLocalGetterToPropertyRector;
use Rector\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector;
use Rector\TypeDeclaration\Rector\Class_\PropertyTypeFromStrictSetterGetterRector;
use Rector\TypeDeclaration\Rector\Class_\ReturnTypeFromStrictTernaryRector;
use Rector\TypeDeclaration\Rector\ClassMethod\ParamTypeByMethodCallTypeRector;
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnNeverTypeRector;
use Rector\ValueObject\PhpVersion;

return static function (RectorConfig $rectorConfig): void {
$dir = getcwd();

$rectorConfig->sets([
SetList::PRIVATIZATION,
SetList::EARLY_RETURN,
SetList::CODING_STYLE,
LaravelSetList::LARAVEL_90,
LaravelSetList::LARAVEL_CODE_QUALITY,
LaravelSetList::LARAVEL_ARRAY_STR_FUNCTION_TO_STATIC_CALL,
]);

/*
* We added a custom bootstrap file to avoid Rector processing errors.
* For more info: https://github.com/rectorphp/rector/issues/6607#issuecomment-891677145
* and https://github.com/rectorphp/rector/issues/3902.
* Bootstrap file source: https://github.com/samsonasik/example-app/blob/922ea0e43a50d9b3eb9e71f57c0af41b8ad97226/rector-bootstrap.php
*/
$rectorConfig->bootstrapFiles([$dir.'/vendor/arkecosystem/foundation/rector-bootstrap.php']);

$rectorConfig->paths([
$dir.'/app',
]);

$rectorConfig->skip([
// skip Livewire
$dir.'/app/Http/Livewire',
$dir.'/app/App/Collaborator/Components',
$dir.'/app/App/Http/Components',
$dir.'/app/App/SecureShell/Components',
$dir.'/app/App/Server/Components',
$dir.'/app/App/Token/Components',
$dir.'/app/App/User/Components',
$dir.'/app/App/View/Components',

// skip Nova
$dir.'/app/App/Nova',
$rectorConfig->bootstrapFiles([
$dir.'/vendor/nunomaduro/larastan/bootstrap.php',
]);

$rectorConfig->phpVersion(PhpVersion::PHP_81);

$rectorConfig->phpVersion(PhpVersion::PHP_82);
$rectorConfig->importNames();
$rectorConfig->importShortClasses(false);

if (file_exists($neon = $dir.'/vendor/arkecosystem/foundation/phpstan.neon')) {
$rectorConfig->phpstanConfig($neon);
}

$rectorConfig->skip([
\Rector\Privatization\Rector\Class_\FinalizeClassesWithoutChildrenRector::class,
\Rector\Privatization\Rector\Class_\RepeatedLiteralToClassConstantRector::class,
\Rector\Privatization\Rector\Property\ChangeReadOnlyPropertyWithDefaultValueToConstantRector::class,
\Rector\Privatization\Rector\Class_\ChangeReadOnlyVariableWithDefaultValueToConstantRector::class,
\Rector\CodingStyle\Rector\Catch_\CatchExceptionNameMatchingTypeRector::class,
\Rector\CodingStyle\Rector\PostInc\PostIncDecToPreIncDecRector::class,
\Rector\CodingStyle\Rector\ClassConst\VarConstantCommentRector::class,
\Rector\CodingStyle\Rector\Encapsed\EncapsedStringsToSprintfRector::class,
\Rector\CodingStyle\Rector\ClassMethod\UnSpreadOperatorRector::class,
\Rector\CodingStyle\Rector\Encapsed\WrapEncapsedVariableInCurlyBracesRector::class,
\Rector\CodingStyle\Rector\FuncCall\ConsistentPregDelimiterRector::class,
$rectorConfig->phpstanConfig('./phpstan.neon');

$rectorConfig->rules([
NewlineAfterStatementRector::class,
RemoveFinalFromConstRector::class,
ConsistentImplodeRector::class,
TernaryConditionVariableAssignmentRector::class,
StringClassNameToClassConstantRector::class,
UseIncrementAssignRector::class,
SplitDoubleAssignRector::class,
WrapEncapsedVariableInCurlyBracesRector::class,
NewlineBeforeNewAssignSetRector::class,
MakeInheritedMethodVisibilitySameAsParentRector::class,
CallUserFuncArrayToVariadicRector::class,
VersionCompareFuncCallToConstantRector::class,
CallUserFuncToMethodCallRector::class,
FuncGetArgsToVariadicParamRector::class,
StrictArraySearchRector::class,
UseClassKeywordForClassNameResolutionRector::class,
SplitGroupedPropertiesRector::class,
SplitGroupedClassConstantsRector::class,
SimplifyEmptyArrayCheckRector::class,
ReplaceMultipleBooleanNotRector::class,
GetClassToInstanceOfRector::class,
PrivatizeLocalGetterToPropertyRector::class,
InlineConstructorDefaultToPropertyRector::class,
RemoveAlwaysElseRector::class,
PrivatizeFinalClassPropertyRector::class,
PrivatizeFinalClassMethodRector::class,
ParamTypeByMethodCallTypeRector::class,

// Types...
ReturnTypeFromStrictTernaryRector::class,
PropertyTypeFromStrictSetterGetterRector::class,
ReturnNeverTypeRector::class,
]);

// Restoration
$rectorConfig->rule(\Rector\Restoration\Rector\Property\MakeTypedPropertyNullableIfCheckedRector::class);

// php5.5
$rectorConfig->rule(\Rector\Php55\Rector\FuncCall\GetCalledClassToStaticClassRector::class);

// php7.4
$rectorConfig->rule(\Rector\Php74\Rector\FuncCall\ArrayKeyExistsOnPropertyRector::class);
$rectorConfig->rule(\Rector\Php74\Rector\Assign\NullCoalescingOperatorRector::class);
$rectorConfig->rule(\Rector\Php74\Rector\Property\RestoreDefaultNullToNullableTypePropertyRector::class);

// php8.0
$rectorConfig->rule(\Rector\Php80\Rector\FunctionLike\UnionTypesRector::class);
$rectorConfig->rule(\Rector\Php80\Rector\NotIdentical\StrContainsRector::class);
$rectorConfig->rule(\Rector\Php80\Rector\Identical\StrStartsWithRector::class);
$rectorConfig->rule(\Rector\Php80\Rector\Identical\StrEndsWithRector::class);
$rectorConfig->rule(\Rector\Php80\Rector\Class_\StringableForToStringRector::class);
$rectorConfig->rule(\Rector\Php80\Rector\FuncCall\ClassOnObjectRector::class);
$rectorConfig->rule(\Rector\Php80\Rector\Catch_\RemoveUnusedVariableInCatchRector::class);
$rectorConfig->rule(\Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector::class);
$rectorConfig->rule(\Rector\Php80\Rector\Switch_\ChangeSwitchToMatchRector::class);
$rectorConfig->rule(\Rector\DeadCode\Rector\StaticCall\RemoveParentCallWithoutParentRector::class);
$rectorConfig->rule(\Rector\Php80\Rector\ClassMethod\FinalPrivateToPrivateVisibilityRector::class);
$rectorConfig->rule(\Rector\CodeQuality\Rector\ClassMethod\OptionalParametersAfterRequiredRector::class);
$rectorConfig->rule(\Rector\Php80\Rector\FuncCall\Php8ResourceReturnToObjectRector::class);

// php8.1
$rectorConfig->rule(\Rector\Php81\Rector\ClassConst\FinalizePublicClassConstantRector::class);
$rectorConfig->rule(\Rector\Php81\Rector\Property\ReadOnlyPropertyRector::class);
$rectorConfig->rule(\Rector\Php81\Rector\Class_\SpatieEnumClassToEnumRector::class);
$rectorConfig->rule(\Rector\Php81\Rector\FuncCall\Php81ResourceReturnToObjectRector::class);
$rectorConfig->rule(\Rector\Php81\Rector\FunctionLike\IntersectionTypesRector::class);
};

0 comments on commit f3d5e19

Please sign in to comment.