Skip to content

Commit

Permalink
[Renaming] Do not Rename Docblock inner Namespace on RenameClassRector (
Browse files Browse the repository at this point in the history
#2441)

* Add failing test for rector/rector#7209

* update fixture

* Closes #2440

* fixture

Co-authored-by: Einar Gangsø <mail@einargangso.no>
  • Loading branch information
samsonasik and eigan authored Jun 6, 2022
1 parent b1583c7 commit 40d9102
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ public function enterNode(Node $node): ?Node
throw new ShouldNotHappenException();
}

$virtualNode = $phpParserNode->getAttribute(AttributeKey::VIRTUAL_NODE);
if ($virtualNode === true) {
return null;
}

$identifier = clone $node;

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

namespace Rector\Tests\Renaming\Rector\Name\RenameClassRector\FixtureAutoImportNames;

use CompanyB\Storage;

class DoNotRenameDocblockInnerNamespace
{
/**
* @var Storage
*/
protected $storage;

public function __construct(
Storage $storage
) {
\Log::error('Some loggin');

$this->storage = $storage;
}

private function foo(): string
{
new Foo($this->storage);
}
}

?>
-----
<?php

namespace Rector\Tests\Renaming\Rector\Name\RenameClassRector\FixtureAutoImportNames;

use Log;
use CompanyB\Storage;

class DoNotRenameDocblockInnerNamespace
{
/**
* @var Storage
*/
protected $storage;

public function __construct(
Storage $storage
) {
Log::error('Some loggin');

$this->storage = $storage;
}

private function foo(): string
{
new Foo($this->storage);
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
$rectorConfig->ruleWithConfiguration(RenameClassRector::class, [
OldClass::class => NewClass::class,
SomeServiceClassFirstNamespace::class => SomeServiceClass::class,
'Storage' => 'Illuminate\Support\Facades\Storage',
]);
};

0 comments on commit 40d9102

Please sign in to comment.