Rule for safely prepare for upgrade to new version of PHP #8285
|
The pre-condition: the project uses PHP version it needs to migrate from. For the sake of discussion let's upgrade from 7.1 to 8.0. |
Replies: 7 comments 11 replies
|
Your question highly depends on the codebase. I would recommend adding a PHP8.0 PHPStan check, and pick rector rules based on the PHPStan errors you get |
|
You can do step by step, use The rules you want to skip will always depends on your needs. |
|
This is a very sensible request. I would argue that it would greatly add to rector's usefulness with older, large codebases. |
|
Is there a list of those rules ? We need to list all required rules to migrate from 7.2 to 8.2 (or version one-by-one). |
|
Is there any update on this? It's exactly what I'm looking for! |
|
Safe or not is always depends of project needs, philosophy, architectural, and personal preference, once we define the "safe" rules, other will argue that not that safe, so end up we are doing nothing :) Run php sets one by one, step by step, and just skip that what you don't want :) |
|
Just in case anyone stumbles upon same issue and until there's a sensible inbuilt set, here's what worked for me when migrating from 7.4 to 8.2: // define sets of rules
$rectorConfig->sets([
LevelSetList::UP_TO_PHP_82,
]);
$rectorConfig->skip([
// custom project rules
// ...
// Do not apply 8.1 rules until we're on actualy php81 binary
\Rector\Php80\Rector\FunctionLike\MixedTypeRector::class,
\Rector\Php80\Rector\Switch_\ChangeSwitchToMatchRector::class,
\Rector\Php80\Rector\Catch_\RemoveUnusedVariableInCatchRector::class,
\Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector::class,
\Rector\Php80\Rector\NotIdentical\StrContainsRector::class,
\Rector\Php80\Rector\Identical\StrStartsWithRector::class,
\Rector\Php80\Rector\Identical\StrEndsWithRector::class,
\Rector\Php80\Rector\FuncCall\ClassOnObjectRector::class,
\Rector\Php80\Rector\ClassConstFetch\ClassOnThisVariableObjectRector::class,
\Rector\Php81\Rector\Array_\FirstClassCallableRector::class,
\Rector\Php81\Rector\ClassMethod\NewInInitializerRector::class,
\Rector\Php81\Rector\Property\ReadOnlyPropertyRector::class,
// \Rector\Php81\Rector\ClassConst\FinalizePublicClassConstantRector::class, // this one was removed/renamed in rector
\Rector\TypeDeclaration\Rector\ClassMethod\ReturnNeverTypeRector::class,
\Rector\Arguments\Rector\FuncCall\FunctionArgumentDefaultValueReplacerRector::class,
]);This was correct for Rector 1.2.x probably, for migrating from 7.4 to 8.2. Feel free to start from here and decide which rules are obsolete or should be added |
Safe or not is always depends of project needs, philosophy, architectural, and personal preference, once we define the "safe" rules, other will argue that not that safe, so end up we are doing nothing :)
Run php sets one by one, step by step, and just skip that what you don't want :)