From 4793a0d4c1294645177a18710667c7b35bcaaca3 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 22 May 2023 21:23:57 +0700 Subject: [PATCH] [CodingStyle] Skip jump change variable name on CatchExceptionNameMatchingTypeRector (#3931) Co-authored-by: GitHub Action --- ...skip_change_variable_next_jump_try.php.inc | 20 +++++++++++++++++++ .../CatchExceptionNameMatchingTypeRector.php | 16 ++++++++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) 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 diff --git a/rules/CodingStyle/Rector/Catch_/CatchExceptionNameMatchingTypeRector.php b/rules/CodingStyle/Rector/Catch_/CatchExceptionNameMatchingTypeRector.php index 3b68b6f4037..2ac0a9b86c3 100644 --- a/rules/CodingStyle/Rector/Catch_/CatchExceptionNameMatchingTypeRector.php +++ b/rules/CodingStyle/Rector/Catch_/CatchExceptionNameMatchingTypeRector.php @@ -7,13 +7,17 @@ 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\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 +85,17 @@ public function run() */ public function getNodeTypes(): array { - return [StmtsAwareInterface::class]; + return [ + ClassMethod::class, + Function_::class, + Closure::class, + FileWithoutNamespace::class, + Namespace_::class, + ]; } /** - * @param StmtsAwareInterface $node + * @param ClassMethod|Function_|Closure|FileWithoutNamespace|Namespace_ $node */ public function refactor(Node $node): ?Node {