Skip to content

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

Merged
samsonasik merged 9 commits intomainfrom
auto-import-handle-dupilcated-import
Mar 7, 2023
Merged

[AutoImport][PostRector] Handle duplicated import on namespaced class on UseAddingPostRector#3461
samsonasik merged 9 commits intomainfrom
auto-import-handle-dupilcated-import

Conversation

@samsonasik
Copy link
Copy Markdown
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
Copy Markdown
Member Author

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

@samsonasik
Copy link
Copy Markdown
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 <actions@github.com>
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