Skip to content
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

Multiple rule configurations with the same class name as identifier #8571

Closed
simonschaufi opened this issue Mar 22, 2024 · 4 comments
Closed
Labels

Comments

@simonschaufi
Copy link

Bug Report

Subject Details
Rector version any

We have several rule configurations that are loaded depending on the TYPO3 version. Each can potentially rename classes with the RenameClassConstFetchRector. Because the method $rectorConfig->ruleWithConfiguration can only register ONE configuration with one class name, any configuration loaded for older versions is ignored as it is overwritten with the last one.

Minimal PHP Code Causing Issue

File 1:

return static function (RectorConfig $rectorConfig): void {
    $rectorConfig->import(__DIR__ . '/../config.php');

    $rectorConfig->ruleWithConfiguration(
        RenameClassConstFetchRector::class,
        [
            new RenameClassAndConstFetch(
                'OldClass1',
                'NOTICE',
                'NewClass1',
                'NOTICE'
            ),
        ]
    );
};

File 2:

return static function (RectorConfig $rectorConfig): void {
    $rectorConfig->import(__DIR__ . '/../config.php');

    $rectorConfig->ruleWithConfiguration(
        RenameClassConstFetchRector::class,
        [
            new RenameClassAndConstFetch(
                'OldClass2',
                'NOTICE',
                'NewClass2',
                'NOTICE'
            ),
        ]
    );
};

Expected Behaviour

Both rules should be applied but only the constants from OldClass2 are replaced.

@samsonasik
Copy link
Member

samsonasik commented Mar 22, 2024

it seems working with single file config https://getrector.com/demo/d34bd8c2-6203-4b6e-832f-b4775c7ba0c0

could you create simple reproducible repo for it? Thank you.

@samsonasik
Copy link
Member

I created e2e test for it at PR:

it seems working ok.

@simonschaufi
Copy link
Author

Thank you for creating a test for it. It seams to be working fine. We had a problem in our TYPO3 Rector project but probably that was before the 1.0 release of Rector with the Symfony DI Container. With the Laravel Container it seams to work fine.

I'll talk again in the team if somebody still has an issue and will let you know.

@samsonasik
Copy link
Member

Ok, closing then ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants