Repository navigation
Run post rectors after the rules reach a fixed point, so no rule sees an imported short name - #8909
SanderMuller wants to merge 1 commit into
Conversation
… an imported short name
|
It seems cause rector-doctrine unit test error https://github.com/rectorphp/rector-src/actions/runs/41433742105/job/125238402868?pr=8909 |
|
you also may need to rebase latest main, that's may needed to ensure all green |
|
Thanks, you were right about the rector-doctrine tests. Two helpers there compare a docblock name with rectorphp/rector-doctrine#548 adds The branch is already on the latest main (01a316d), so a rebase does not change this. |
|
I restarted the build 👍 |
With
withImportNames(),NameImportingPostRectorreplaces aFullyQualifiedname with a shortName. The file loop then runs the rules again, and PHPStan resolves that short name as written. When a global class has the same name, the rules get the wrong type.For example,
ExplicitNullableObjectInstanceRectorturns$directory === nullinto! $directory instanceof \Some\Directory. The import makes thatDirectory. In the next pass PHPStan reads it as the core\Directoryclass, so the condition is always true, andRemoveAlwaysTrueIfConditionRectorreplaces the method body withreturn;. I hit this with an enumLocaleand the intlLocaleclass. A final class does the same.Names in the parsed file stay
FullyQualifiedwith anoriginalName, so they resolve correctly. Only names that a post rector imports during the loop are affected.FileProcessornow runs the rules until they reach a fixed point, and only then the post rectors. The post rectors still repeat until the output is stable, because some imports need a second pass, for example after a conflicting unuseduseis removed. The rules do not run again after that.The new test fails on main for the enum and the final class fixtures, and passes with this change. The case with a short name in the source already passed. The full test suite and the e2e projects give the same result as on main.