Skip to content

Commit

Permalink
[Renaming] Do not rename class with same name inside different namesp…
Browse files Browse the repository at this point in the history
…ace on RenameClassRector (#2455)

* Another failing test for #7209

* fixture

* fixture

* Closes #2452

* try

* try

* back

* Fixed 🎉

* final touch: add example used in union

Co-authored-by: Einar Gangsø <mail@einargangso.no>
  • Loading branch information
samsonasik and eigan authored Jun 9, 2022
1 parent ba48cd2 commit cb1473a
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use PhpParser\Node as PhpParserNode;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Stmt\GroupUse;
use PhpParser\Node\Stmt\Namespace_;
use PhpParser\Node\Stmt\Use_;
Expand Down Expand Up @@ -66,6 +67,11 @@ public function enterNode(Node $node): ?Node
return null;
}

$previousNode = $phpParserNode->getAttribute(AttributeKey::PREVIOUS_NODE);
if ($previousNode instanceof FullyQualified) {
return null;
}

$identifier = clone $node;
$namespacedName = $this->resolveNamespacedName($phpParserNode, $node->name);
$identifier->name = $namespacedName;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Foo;

class Foo extends FooBar
{
/**
* @param \DateTime $foo
*
* Storage here is Foo\Storage. Not \Storage.
* @return Storage
*/
public function bar($foo){}
}

?>
-----
<?php

namespace Foo;

use DateTime;
class Foo extends FooBar
{
/**
* @param DateTime $foo
*
* Storage here is Foo\Storage. Not \Storage.
* @return Storage
*/
public function bar($foo){}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Foo2;

class Foo2 extends FooBar
{
/**
* @param \DateTime $foo
*
* @return Storage|\Storage
*/
public function bar($foo){}
}

?>
-----
<?php

namespace Foo2;

use DateTime;
class Foo2 extends FooBar
{
/**
* @param DateTime $foo
*
* @return Storage|\Illuminate\Support\Facades\Storage
*/
public function bar($foo){}
}

?>

0 comments on commit cb1473a

Please sign in to comment.