-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate to PHP 8.1 #9772
Comments
In fact, we can generalize that issue to any PHP-8.0-specific feature. I've tried using Rector with the following config that I stole from Sonata: <?php
declare(strict_types=1);
use Rector\Config\RectorConfig;
use Rector\Php71\Rector\FuncCall\CountOnNullRector;
use Rector\Php81\Rector\ClassConst\FinalizePublicClassConstantRector;
use Rector\Set\ValueObject\LevelSetList;
use Rector\TypeDeclaration\Rector\FunctionLike\ParamTypeDeclarationRector;
use Rector\TypeDeclaration\Rector\FunctionLike\ReturnTypeDeclarationRector;
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/lib',
]);
$rectorConfig->sets([
LevelSetList::UP_TO_PHP_81,
]);
$rectorConfig->rule(ParamTypeDeclarationRector::class);
$rectorConfig->rule(ReturnTypeDeclarationRector::class);
$rectorConfig->skip([
CountOnNullRector::class, // I haven't reevaluated this rule
FinalizePublicClassConstantRector::class,
]);
}; Make sure to install a version of Rector that is compatible with that: The result breaks the test suite (there is a Fatal error at compilation time), and after fixing, one will see many errors caused by wrong phpdoc transformed in wrong type declarations.
I think the best strategy to tackle this issue is to proceed in reasonably small PRs, targeting a small number of classes every time. I can post a message to this thread every time progress is made. The workflow can be the following:
|
I have also created https://github.com/doctrine/orm/projects/6 to track progress and show examples |
Progress after #9776 🐌
|
Progress after #9828 and #9835
But that's without $rectorConfig->rule(ParamTypeDeclarationRector::class);
$rectorConfig->rule(ReturnTypeDeclarationRector::class); that I think we might use as well. Updated config file: <?php
declare(strict_types=1);
use Rector\Config\RectorConfig;
use Rector\Php71\Rector\FuncCall\CountOnNullRector;
use Rector\Set\ValueObject\LevelSetList;
use Rector\TypeDeclaration\Rector\FunctionLike\ParamTypeDeclarationRector;
use Rector\TypeDeclaration\Rector\FunctionLike\ReturnTypeDeclarationRector;
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/lib',
]);
$rectorConfig->sets([
LevelSetList::UP_TO_PHP_81,
]);
$rectorConfig->rule(ParamTypeDeclarationRector::class);
$rectorConfig->rule(ReturnTypeDeclarationRector::class);
$rectorConfig->skip([
CountOnNullRector::class, // I haven't reevaluated this rule
]);
}; Let's use it in the next PRs and see if it does what we think it does. |
updated list with the extra rules
|
updated list after #9551
|
Since #9925 we can use |
updated list after the 5 PRs above (spoiler, there's nice progress)
|
Close to 100 files
|
Note: without `importNames()`, the result is exactly 100 files, and there are about half as many changes
@derrabus what's your opinion on this? That rule removes things such as
EDIT: in case you're wondering, running
The use statement goes away.
Maybe I should report a bug? Or maybe it's not fixable? |
Shouldn't this be cleaned up by PHPCBF? |
PHPCBF wrongly removes the use statement (maybe because it wants to fix the first error). |
Reported at slevomat/coding-standard#1466 |
I wished I reported this earlier, @kukulich fixed it like was nothing! Let's definitely remove that |
down to 65 files 💪
|
Updated the above config file to disable As a result of that and recent PRs, we're down to 31 files if we include #10378
|
All done! 🎉 |
This is something that I think should go in milestone 3.0.0
A big difference between branches 2 and 3 is the
php
requirement:Now that support for PHP 7 has been dropped, we can use features that are specific to PHP 8.
@derrabus has already done a lot about that. When this is over, we should be able to get rid of lines mentioning native type declarations in
phpcs.xml.dist
. It can also be used to figure out what is left to do.We should rely on constructor property promotion when possible.
phpdoc that is found to be wrong on the way should be fixed on the next patch branch.
phpdoc that is found to be imprecise on the way should be improved on the next minor branch.
Here is an example for
AbstractQuery
and related classes:The text was updated successfully, but these errors were encountered: