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

[Renaming] Handle Rename before AttributeGroup on RenameClassRector #1481

Merged
merged 8 commits into from
Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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