From 9a1e830a7f85e97ea73835a8f14aa4efa5ea124c Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 22 May 2023 21:15:22 +0700 Subject: [PATCH 1/5] [CodingStyle] Skip jump change variable name on CatchExceptionNameMatchingTypeRector --- ...skip_change_variable_next_jump_try.php.inc | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 rules-tests/CodingStyle/Rector/Catch_/CatchExceptionNameMatchingTypeRector/Fixture/skip_change_variable_next_jump_try.php.inc diff --git a/rules-tests/CodingStyle/Rector/Catch_/CatchExceptionNameMatchingTypeRector/Fixture/skip_change_variable_next_jump_try.php.inc b/rules-tests/CodingStyle/Rector/Catch_/CatchExceptionNameMatchingTypeRector/Fixture/skip_change_variable_next_jump_try.php.inc new file mode 100644 index 00000000000..12d08f85707 --- /dev/null +++ b/rules-tests/CodingStyle/Rector/Catch_/CatchExceptionNameMatchingTypeRector/Fixture/skip_change_variable_next_jump_try.php.inc @@ -0,0 +1,20 @@ +verify($typoException); + $this->verify2($typoException); + } + } +} \ No newline at end of file From b6724eee3aaa2873813b34fa392cd917b349983b Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 22 May 2023 21:17:57 +0700 Subject: [PATCH 2/5] Fixed :tada: --- .../CatchExceptionNameMatchingTypeRector.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/rules/CodingStyle/Rector/Catch_/CatchExceptionNameMatchingTypeRector.php b/rules/CodingStyle/Rector/Catch_/CatchExceptionNameMatchingTypeRector.php index 3b68b6f4037..deb1e06657d 100644 --- a/rules/CodingStyle/Rector/Catch_/CatchExceptionNameMatchingTypeRector.php +++ b/rules/CodingStyle/Rector/Catch_/CatchExceptionNameMatchingTypeRector.php @@ -7,13 +7,19 @@ use Nette\Utils\Strings; use PhpParser\Node; use PhpParser\Node\Expr\Assign; +use PhpParser\Node\Expr\Closure; use PhpParser\Node\Expr\Variable; use PhpParser\Node\Stmt; use PhpParser\Node\Stmt\Catch_; +use PhpParser\Node\Stmt\ClassMethod; +use PhpParser\Node\Stmt\Foreach_; +use PhpParser\Node\Stmt\Function_; +use PhpParser\Node\Stmt\Namespace_; use PhpParser\Node\Stmt\TryCatch; use PHPStan\Analyser\Scope; use PHPStan\Type\ObjectType; use Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface; +use Rector\Core\PhpParser\Node\CustomNode\FileWithoutNamespace; use Rector\Core\Rector\AbstractRector; use Rector\Naming\Naming\AliasNameResolver; use Rector\Naming\Naming\PropertyNaming; @@ -81,11 +87,16 @@ public function run() */ public function getNodeTypes(): array { - return [StmtsAwareInterface::class]; + return [ + ClassMethod::class, + Function_::class, + FileWithoutNamespace::class, + Namespace_::class, + ]; } /** - * @param StmtsAwareInterface $node + * @param ClassMethod|Function_|FileWithoutNamespace|Namespace_ $node */ public function refactor(Node $node): ?Node { From 7d7e6e15a536a41cca4b25f6b8b792d30ad28d86 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 22 May 2023 21:18:50 +0700 Subject: [PATCH 3/5] add closure as well --- .../Rector/Catch_/CatchExceptionNameMatchingTypeRector.php | 1 + 1 file changed, 1 insertion(+) diff --git a/rules/CodingStyle/Rector/Catch_/CatchExceptionNameMatchingTypeRector.php b/rules/CodingStyle/Rector/Catch_/CatchExceptionNameMatchingTypeRector.php index deb1e06657d..41c25290628 100644 --- a/rules/CodingStyle/Rector/Catch_/CatchExceptionNameMatchingTypeRector.php +++ b/rules/CodingStyle/Rector/Catch_/CatchExceptionNameMatchingTypeRector.php @@ -90,6 +90,7 @@ public function getNodeTypes(): array return [ ClassMethod::class, Function_::class, + Closure::class, FileWithoutNamespace::class, Namespace_::class, ]; From d32603d5590084117f68742e9d269257a46a5f2d Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 22 May 2023 21:19:06 +0700 Subject: [PATCH 4/5] add closure as well --- .../Rector/Catch_/CatchExceptionNameMatchingTypeRector.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rules/CodingStyle/Rector/Catch_/CatchExceptionNameMatchingTypeRector.php b/rules/CodingStyle/Rector/Catch_/CatchExceptionNameMatchingTypeRector.php index 41c25290628..977adf86254 100644 --- a/rules/CodingStyle/Rector/Catch_/CatchExceptionNameMatchingTypeRector.php +++ b/rules/CodingStyle/Rector/Catch_/CatchExceptionNameMatchingTypeRector.php @@ -97,7 +97,7 @@ public function getNodeTypes(): array } /** - * @param ClassMethod|Function_|FileWithoutNamespace|Namespace_ $node + * @param ClassMethod|Function_|Closure|FileWithoutNamespace|Namespace_ $node */ public function refactor(Node $node): ?Node { From 7e647e0cd7f02913a1356c55e579a5b8a733811f Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Mon, 22 May 2023 14:21:57 +0000 Subject: [PATCH 5/5] [ci-review] Rector Rectify --- .../Rector/Catch_/CatchExceptionNameMatchingTypeRector.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/rules/CodingStyle/Rector/Catch_/CatchExceptionNameMatchingTypeRector.php b/rules/CodingStyle/Rector/Catch_/CatchExceptionNameMatchingTypeRector.php index 977adf86254..2ac0a9b86c3 100644 --- a/rules/CodingStyle/Rector/Catch_/CatchExceptionNameMatchingTypeRector.php +++ b/rules/CodingStyle/Rector/Catch_/CatchExceptionNameMatchingTypeRector.php @@ -12,13 +12,11 @@ use PhpParser\Node\Stmt; use PhpParser\Node\Stmt\Catch_; use PhpParser\Node\Stmt\ClassMethod; -use PhpParser\Node\Stmt\Foreach_; use PhpParser\Node\Stmt\Function_; use PhpParser\Node\Stmt\Namespace_; use PhpParser\Node\Stmt\TryCatch; use PHPStan\Analyser\Scope; use PHPStan\Type\ObjectType; -use Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface; use Rector\Core\PhpParser\Node\CustomNode\FileWithoutNamespace; use Rector\Core\Rector\AbstractRector; use Rector\Naming\Naming\AliasNameResolver;