Skip to content

Commit

Permalink
[Renaming] Handle Rename before AttributeGroup on RenameClassRector (#…
Browse files Browse the repository at this point in the history
…1481)

* testWithRouteAttribute test case

* revert

* Add unit test

* fix namespace/imports

* Add namespace

* move fixture and config

* debug

* Closes #1479 Fixes rectorphp/rector#6861

Co-authored-by: Phil E. Taylor <phil@phil-taylor.com>
  • Loading branch information
samsonasik and PhilETaylor committed Dec 14, 2021
1 parent 528d6dd commit a7fe982
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

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

use Doctrine\DBAL\DBALException;

class RenameBeforeAttribute
{
/**
* @throws DBALException
*/
#[Route(path: '/top/', name: 'top')]
public function testWithRouteAttribute(){
// something throws the exception deep down here....
}
}

?>
-----
<?php

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

use Doctrine\DBAL\DBALException;

class RenameBeforeAttribute
{
/**
* @throws \Doctrine\DBAL\Exception
*/
#[Route(path: '/top/', name: 'top')]
public function testWithRouteAttribute(){
// something throws the exception deep down here....
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@
\Acme\Foo\DoNotUpdateExistingTargetNamespace::class => DoNotUpdateExistingTargetNamespace::class,
SomeNonFinalClass::class => SomeFinalClass::class,
'Foo\Bar' => 'Foo\Bar\BarInterface',
'Doctrine\DBAL\DBALException' => 'Doctrine\DBAL\Exception',
]);
};
5 changes: 5 additions & 0 deletions rules/Renaming/NodeManipulator/ClassRenamer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Nette\Utils\Strings;
use PhpParser\Node;
use PhpParser\Node\AttributeGroup;
use PhpParser\Node\Expr\New_;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
Expand Down Expand Up @@ -95,6 +96,10 @@ private function refactorPhpDoc(Node $node, array $oldToNewTypes, array $oldToNe
return;
}

if ($node instanceof AttributeGroup) {
return;
}

$this->docBlockClassRenamer->renamePhpDocType($phpDocInfo, $oldToNewTypes);

$this->phpDocClassRenamer->changeTypeInAnnotationTypes($node, $phpDocInfo, $oldToNewClasses);
Expand Down

0 comments on commit a7fe982

Please sign in to comment.