Skip to content

Rector forces \ in front of SortDirection #9953

Closed

Description

@themasch

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:
 * DoctrineQueryBuilderSortDirectionRector

Minor 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

  1. samsonasik commented on Nov 2, 2026

    @samsonasik
    Member

    That should already resolved at

    Please try latest dev-main

  2. themasch commented on Nov 2, 2026

    @themasch
    Author

    @samsonasik thanks, can confirm that dev-main fixes it!

    I did search for issues, but not for matching PRs on the rector-doctrine repo. I'll be better next time!

    Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions