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

[AutoImport][PostRector] Handle duplicated import on namespaced class on UseAddingPostRector #3461

Merged
merged 9 commits into from
Mar 7, 2023

Conversation

samsonasik
Copy link
Member

Continue of PR:

When auto import is namespaced, the old classname should be cleaned up before add to avoid duplicated import.

Given the following config:

<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Symfony\Rector\ClassMethod\ReplaceSensioRouteAnnotationWithSymfonyRector;

return static function (RectorConfig $rectorConfig): void {
    $rectorConfig->importNames();
    $rectorConfig->rule(ReplaceSensioRouteAnnotationWithSymfonyRector::class);
};

with class:

<?php

namespace App;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

/**
 * @Route("/someUrl")
 */
class SomeController extends Controller
{
}

It currently produce duplicated use statement.

 namespace App;
 
+use Symfony\Component\Routing\Annotation\Route;
 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
 use Symfony\Bundle\FrameworkBundle\Controller\Controller;

This PR try to fix it.

@samsonasik samsonasik requested a review from TomasVotruba as a code owner March 6, 2023 22:42
@samsonasik
Copy link
Member Author

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

@samsonasik
Copy link
Member Author

@TomasVotruba I am merging it ;)

@samsonasik samsonasik merged commit f9900dd into main Mar 7, 2023
@samsonasik samsonasik deleted the auto-import-handle-dupilcated-import branch March 7, 2023 00:50
samsonasik added a commit that referenced this pull request May 8, 2023
… on UseAddingPostRector (#3461)

* [AutoImport] Handle duplicated import on namespaced class on ReplaceSensioRouteAnnotationWithSymfonyRector

* [ci-review] Rector Rectify

* moving to early clean before add to namespace or non-namespace

* [ci-review] Rector Rectify

* removing use under namespace

* Fixed 🎉

* Fix phpstan

* Final touch: clean up

* Final touch: clean up

---------

Co-authored-by: GitHub Action <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants