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

[Renaming][PostRector] Handle skip path after defined at RenameClassRector #3243

Merged
merged 3 commits into from Jan 18, 2023

Conversation

samsonasik
Copy link
Member

@samsonasik samsonasik commented Dec 23, 2022

Given the following config in tests:

use Rector\Config\RectorConfig;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Tests\Renaming\Rector\Name\RenameClassRector\Source\NewClass;
use Rector\Tests\Renaming\Rector\Name\RenameClassRector\Source\OldClass;

return static function (RectorConfig $rectorConfig): void {
    $rectorConfig
        ->ruleWithConfiguration(RenameClassRector::class, [
            OldClass::class => NewClass::class,
        ]);

    // skip the path after defined
    $rectorConfig->skip([
        RenameClassRector::class => [sys_get_temp_dir() . '/rector/tests_fixture_'],
    ]);
};

It not properly skipped, as there are 2 services:

  • RenameClassRector
  • ClassRenamingPostRector

The ClassRenamingPostRector apply the change already before it actually skipped because that read the configs:

public function enterNode(Node $node): ?Node
{
$oldToNewClasses = $this->renamedClassesDataCollector->getOldToNewClasses();
if ($oldToNewClasses === []) {
return $node;
}
return $this->classRenamer->renameNode($node, $oldToNewClasses);
}

This PR try to fix it with add new interface: PostRectorDependencyInterface to define the dependencies of the PostRector when needed.

Fixes rectorphp/rector#7417

@samsonasik
Copy link
Member Author

Fixed 🎉 /cc @grandmaster44

@samsonasik
Copy link
Member Author

All checks have passed 🎉 @TomasVotruba it is ready for review.

@samsonasik samsonasik force-pushed the handle-skip-path-after-defined-rename-class-rector branch from 7cd9e3c to f5c8ac0 Compare December 23, 2022 17:19
@samsonasik
Copy link
Member Author

Rebased.

@samsonasik
Copy link
Member Author

All checks have passed 🎉 @TomasVotruba I think it is ready.

@TomasVotruba TomasVotruba merged commit c546aa7 into main Jan 18, 2023
@TomasVotruba TomasVotruba deleted the handle-skip-path-after-defined-rename-class-rector branch January 18, 2023 11:54
@TomasVotruba
Copy link
Member

Thank you 👏

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