Closed
Labels
Description
Bug Report
| Subject | Details |
|---|---|
| Rector version | Rector 2.8.3 |
| PHP version | 8.5.12 |
Rector adds a \ in front of existing SortDirection uses even if the name is imported.
Minimal PHP Code Causing Issue
Sorry, I failed to reproduce it at https://getrector.com/demo/ since it needs things in composer.json.
test.php:
<?php
namespace MyCooolNamespace;
use Doctrine\ORM\QueryBuilder;
use SortDirection;
$x = new QueryBuilder(magic_get_em())->orderBy('field', SortDirection::Ascending);composer.json
{
"require": {
"doctrine/orm": "^3.7",
"symfony/polyfill-php86": "^1.43"
},
"require-dev": {
"rector/rector": "^2.8"
},
"config": {
"platform": {
"php": "^8.5.12"
}
}
}rector.php
<?php
use Rector\Config\RectorConfig;
return RectorConfig::configure()
->withRootFiles()
->withComposerBased(doctrine: true);Expected Behaviour
No change, code is already in the desired state
Actual Behaviour
Rector suggest the following change:
1) test.php:5
---------- begin diff ----------
@@ Line 5 @@
use Doctrine\ORM\QueryBuilder;
use SortDirection;
-$x = new QueryBuilder(magic_get_em())->orderBy('field', SortDirection::Ascending);
\ No newline at end of file
+$x = new QueryBuilder(magic_get_em())->orderBy('field', \SortDirection::Ascending);
\ No newline at end of file
----------- end diff -----------
Applied rules:
* DoctrineQueryBuilderSortDirectionRectorMinor grievance: it also requireds that symfony/poliyfill-php86 is explicitly listed in composer.json rather than it being pulled by doctrine/orm. Which is fine, I guess, but took a moment to figure out ;)
Activity
samsonasik commentedon Nov 2, 2026
That should already resolved at
Please try latest dev-main
themasch commentedon Nov 2, 2026
@samsonasik thanks, can confirm that
dev-mainfixes it!I did search for issues, but not for matching PRs on the rector-doctrine repo. I'll be better next time!
Thanks!