From 25f1791c85c9104deef946e4f5d4139d89aaa540 Mon Sep 17 00:00:00 2001 From: "Phil E. Taylor" Date: Mon, 13 Dec 2021 19:14:50 +0000 Subject: [PATCH 1/8] testWithRouteAttribute test case --- .../rename_class_preceeding_attribute.php.inc | 31 +++++++++++++++++++ .../config/configured_rule.php | 1 + 2 files changed, 32 insertions(+) create mode 100644 rules-tests/Renaming/Rector/Name/RenameClassRector/Fixture/rename_class_preceeding_attribute.php.inc diff --git a/rules-tests/Renaming/Rector/Name/RenameClassRector/Fixture/rename_class_preceeding_attribute.php.inc b/rules-tests/Renaming/Rector/Name/RenameClassRector/Fixture/rename_class_preceeding_attribute.php.inc new file mode 100644 index 00000000000..2840ae97d12 --- /dev/null +++ b/rules-tests/Renaming/Rector/Name/RenameClassRector/Fixture/rename_class_preceeding_attribute.php.inc @@ -0,0 +1,31 @@ + +----- + diff --git a/rules-tests/Renaming/Rector/Name/RenameClassRector/config/configured_rule.php b/rules-tests/Renaming/Rector/Name/RenameClassRector/config/configured_rule.php index 47d45144bb4..e36ff8f8964 100644 --- a/rules-tests/Renaming/Rector/Name/RenameClassRector/config/configured_rule.php +++ b/rules-tests/Renaming/Rector/Name/RenameClassRector/config/configured_rule.php @@ -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', ]); }; From 8752896a32f32af37d68ca817d8bd486b2393f36 Mon Sep 17 00:00:00 2001 From: "Phil E. Taylor" Date: Mon, 13 Dec 2021 19:32:46 +0000 Subject: [PATCH 2/8] revert --- .../rename_class_preceeding_attribute.php.inc | 31 ------------------- .../config/configured_rule.php | 1 - 2 files changed, 32 deletions(-) delete mode 100644 rules-tests/Renaming/Rector/Name/RenameClassRector/Fixture/rename_class_preceeding_attribute.php.inc diff --git a/rules-tests/Renaming/Rector/Name/RenameClassRector/Fixture/rename_class_preceeding_attribute.php.inc b/rules-tests/Renaming/Rector/Name/RenameClassRector/Fixture/rename_class_preceeding_attribute.php.inc deleted file mode 100644 index 2840ae97d12..00000000000 --- a/rules-tests/Renaming/Rector/Name/RenameClassRector/Fixture/rename_class_preceeding_attribute.php.inc +++ /dev/null @@ -1,31 +0,0 @@ - ------ - diff --git a/rules-tests/Renaming/Rector/Name/RenameClassRector/config/configured_rule.php b/rules-tests/Renaming/Rector/Name/RenameClassRector/config/configured_rule.php index e36ff8f8964..47d45144bb4 100644 --- a/rules-tests/Renaming/Rector/Name/RenameClassRector/config/configured_rule.php +++ b/rules-tests/Renaming/Rector/Name/RenameClassRector/config/configured_rule.php @@ -45,6 +45,5 @@ \Acme\Foo\DoNotUpdateExistingTargetNamespace::class => DoNotUpdateExistingTargetNamespace::class, SomeNonFinalClass::class => SomeFinalClass::class, 'Foo\Bar' => 'Foo\Bar\BarInterface', - 'Doctrine\DBAL\DBALException' => 'Doctrine\DBAL\Exception', ]); }; From cd4359a2917bbeca826f65adfe43041a4556c0d2 Mon Sep 17 00:00:00 2001 From: "Phil E. Taylor" Date: Mon, 13 Dec 2021 19:32:52 +0000 Subject: [PATCH 3/8] Add unit test --- .../Issues/Issue6861/Fixture/fixture.php.inc | 31 +++++++++++++++++++ .../RenameClassRectorBeforeAttributeTest.php | 30 ++++++++++++++++++ .../Issue6861/config/configured_rule.php | 14 +++++++++ 3 files changed, 75 insertions(+) create mode 100644 tests/Issues/Issue6861/Fixture/fixture.php.inc create mode 100644 tests/Issues/Issue6861/RenameClassRectorBeforeAttributeTest.php create mode 100644 tests/Issues/Issue6861/config/configured_rule.php diff --git a/tests/Issues/Issue6861/Fixture/fixture.php.inc b/tests/Issues/Issue6861/Fixture/fixture.php.inc new file mode 100644 index 00000000000..e2ed7ca669b --- /dev/null +++ b/tests/Issues/Issue6861/Fixture/fixture.php.inc @@ -0,0 +1,31 @@ + +----- + diff --git a/tests/Issues/Issue6861/RenameClassRectorBeforeAttributeTest.php b/tests/Issues/Issue6861/RenameClassRectorBeforeAttributeTest.php new file mode 100644 index 00000000000..6e6f67c515f --- /dev/null +++ b/tests/Issues/Issue6861/RenameClassRectorBeforeAttributeTest.php @@ -0,0 +1,30 @@ +doTestFileInfo($fileInfo); + } + + /** + * @return Iterator + */ + public function provideData(): Iterator + { + return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); + } + + public function provideConfigFilePath(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/tests/Issues/Issue6861/config/configured_rule.php b/tests/Issues/Issue6861/config/configured_rule.php new file mode 100644 index 00000000000..5036409af2f --- /dev/null +++ b/tests/Issues/Issue6861/config/configured_rule.php @@ -0,0 +1,14 @@ +services(); + $services->set(RenameClassRector::class) + ->configure([ + 'Doctrine\DBAL\DBALException' => 'Doctrine\DBAL\Exception', + ]); +}; From cf77f7f99fcbdfafad7a0b74ee482087064edea7 Mon Sep 17 00:00:00 2001 From: "Phil E. Taylor" Date: Mon, 13 Dec 2021 19:39:11 +0000 Subject: [PATCH 4/8] fix namespace/imports --- .../Issues/Issue6861/RenameClassRectorBeforeAttributeTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/Issues/Issue6861/RenameClassRectorBeforeAttributeTest.php b/tests/Issues/Issue6861/RenameClassRectorBeforeAttributeTest.php index 6e6f67c515f..2c8a1c96356 100644 --- a/tests/Issues/Issue6861/RenameClassRectorBeforeAttributeTest.php +++ b/tests/Issues/Issue6861/RenameClassRectorBeforeAttributeTest.php @@ -2,6 +2,9 @@ declare(strict_types=1); +namespace Rector\Core\Tests\Issues\Issue6861; + +use Iterator; use Rector\Testing\PHPUnit\AbstractRectorTestCase; use Symplify\SmartFileSystem\SmartFileInfo; From 121def1a7aa933f35dba3e0918e367ffb1ca27dd Mon Sep 17 00:00:00 2001 From: "Phil E. Taylor" Date: Mon, 13 Dec 2021 19:40:28 +0000 Subject: [PATCH 5/8] Add namespace --- tests/Issues/Issue6861/Fixture/fixture.php.inc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/Issues/Issue6861/Fixture/fixture.php.inc b/tests/Issues/Issue6861/Fixture/fixture.php.inc index e2ed7ca669b..ae68778601f 100644 --- a/tests/Issues/Issue6861/Fixture/fixture.php.inc +++ b/tests/Issues/Issue6861/Fixture/fixture.php.inc @@ -1,5 +1,7 @@ Date: Tue, 14 Dec 2021 09:37:10 +0700 Subject: [PATCH 6/8] move fixture and config --- .../Fixture/rename_before_attribute.php.inc | 8 ++--- .../config/configured_rule.php | 1 + .../RenameClassRectorBeforeAttributeTest.php | 33 ------------------- .../Issue6861/config/configured_rule.php | 14 -------- 4 files changed, 5 insertions(+), 51 deletions(-) rename tests/Issues/Issue6861/Fixture/fixture.php.inc => rules-tests/Renaming/Rector/Name/RenameClassRector/Fixture/rename_before_attribute.php.inc (70%) delete mode 100644 tests/Issues/Issue6861/RenameClassRectorBeforeAttributeTest.php delete mode 100644 tests/Issues/Issue6861/config/configured_rule.php diff --git a/tests/Issues/Issue6861/Fixture/fixture.php.inc b/rules-tests/Renaming/Rector/Name/RenameClassRector/Fixture/rename_before_attribute.php.inc similarity index 70% rename from tests/Issues/Issue6861/Fixture/fixture.php.inc rename to rules-tests/Renaming/Rector/Name/RenameClassRector/Fixture/rename_before_attribute.php.inc index ae68778601f..6f51b706462 100644 --- a/tests/Issues/Issue6861/Fixture/fixture.php.inc +++ b/rules-tests/Renaming/Rector/Name/RenameClassRector/Fixture/rename_before_attribute.php.inc @@ -1,10 +1,10 @@ DoNotUpdateExistingTargetNamespace::class, SomeNonFinalClass::class => SomeFinalClass::class, 'Foo\Bar' => 'Foo\Bar\BarInterface', + 'Doctrine\DBAL\DBALException' => 'Doctrine\DBAL\Exception', ]); }; diff --git a/tests/Issues/Issue6861/RenameClassRectorBeforeAttributeTest.php b/tests/Issues/Issue6861/RenameClassRectorBeforeAttributeTest.php deleted file mode 100644 index 2c8a1c96356..00000000000 --- a/tests/Issues/Issue6861/RenameClassRectorBeforeAttributeTest.php +++ /dev/null @@ -1,33 +0,0 @@ -doTestFileInfo($fileInfo); - } - - /** - * @return Iterator - */ - public function provideData(): Iterator - { - return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); - } - - public function provideConfigFilePath(): string - { - return __DIR__ . '/config/configured_rule.php'; - } -} diff --git a/tests/Issues/Issue6861/config/configured_rule.php b/tests/Issues/Issue6861/config/configured_rule.php deleted file mode 100644 index 5036409af2f..00000000000 --- a/tests/Issues/Issue6861/config/configured_rule.php +++ /dev/null @@ -1,14 +0,0 @@ -services(); - $services->set(RenameClassRector::class) - ->configure([ - 'Doctrine\DBAL\DBALException' => 'Doctrine\DBAL\Exception', - ]); -}; From 8d8c6a8bae43b57a24a880f874484eaca5d78f05 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 14 Dec 2021 09:52:42 +0700 Subject: [PATCH 7/8] debug --- rules/Renaming/NodeManipulator/ClassRenamer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rules/Renaming/NodeManipulator/ClassRenamer.php b/rules/Renaming/NodeManipulator/ClassRenamer.php index b105aeba43b..25413730818 100644 --- a/rules/Renaming/NodeManipulator/ClassRenamer.php +++ b/rules/Renaming/NodeManipulator/ClassRenamer.php @@ -95,7 +95,7 @@ private function refactorPhpDoc(Node $node, array $oldToNewTypes, array $oldToNe return; } - $this->docBlockClassRenamer->renamePhpDocType($phpDocInfo, $oldToNewTypes); + //$this->docBlockClassRenamer->renamePhpDocType($phpDocInfo, $oldToNewTypes); $this->phpDocClassRenamer->changeTypeInAnnotationTypes($node, $phpDocInfo, $oldToNewClasses); } From 70134e73abf5e59e78f91662933d92c8d238a276 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 14 Dec 2021 10:39:29 +0700 Subject: [PATCH 8/8] Closes #1479 Fixes /~https://github.com/rectorphp/rector/issues/6861 --- .../Fixture/rename_before_attribute.php.inc | 2 ++ rules/Renaming/NodeManipulator/ClassRenamer.php | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/rules-tests/Renaming/Rector/Name/RenameClassRector/Fixture/rename_before_attribute.php.inc b/rules-tests/Renaming/Rector/Name/RenameClassRector/Fixture/rename_before_attribute.php.inc index 6f51b706462..110ccaa1bbf 100644 --- a/rules-tests/Renaming/Rector/Name/RenameClassRector/Fixture/rename_before_attribute.php.inc +++ b/rules-tests/Renaming/Rector/Name/RenameClassRector/Fixture/rename_before_attribute.php.inc @@ -21,6 +21,8 @@ class RenameBeforeAttribute namespace Rector\Tests\Renaming\Rector\Name\RenameClassRector\Fixture; +use Doctrine\DBAL\DBALException; + class RenameBeforeAttribute { /** diff --git a/rules/Renaming/NodeManipulator/ClassRenamer.php b/rules/Renaming/NodeManipulator/ClassRenamer.php index 25413730818..a309beb7bc3 100644 --- a/rules/Renaming/NodeManipulator/ClassRenamer.php +++ b/rules/Renaming/NodeManipulator/ClassRenamer.php @@ -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; @@ -95,7 +96,11 @@ private function refactorPhpDoc(Node $node, array $oldToNewTypes, array $oldToNe return; } - //$this->docBlockClassRenamer->renamePhpDocType($phpDocInfo, $oldToNewTypes); + if ($node instanceof AttributeGroup) { + return; + } + + $this->docBlockClassRenamer->renamePhpDocType($phpDocInfo, $oldToNewTypes); $this->phpDocClassRenamer->changeTypeInAnnotationTypes($node, $phpDocInfo, $oldToNewClasses); }