diff --git a/packages/DeadCode/src/Rector/Assign/RemoveDoubleAssignRector.php b/packages/DeadCode/src/Rector/Assign/RemoveDoubleAssignRector.php index d4a154e26d1..470d62c3cb8 100644 --- a/packages/DeadCode/src/Rector/Assign/RemoveDoubleAssignRector.php +++ b/packages/DeadCode/src/Rector/Assign/RemoveDoubleAssignRector.php @@ -123,17 +123,34 @@ CODE_SAMPLE { $firstNodeParent = $this->betterNodeFinder->findFirstParentInstanceOf( $firstNode, - [Foreach_::class, If_::class, While_::class, Do_::class, Else_::class, ElseIf_::class] + [ + Foreach_::class, + If_::class, + While_::class, + Do_::class, + Else_::class, + ElseIf_::class, + Node\Stmt\Catch_::class, + ] ); $secondNodeParent = $this->betterNodeFinder->findFirstParentInstanceOf( $secondNode, - [Foreach_::class, If_::class, While_::class, Do_::class, If_::class, ElseIf_::class] + [ + Foreach_::class, + If_::class, + While_::class, + Do_::class, + If_::class, + ElseIf_::class, + Node\Stmt\Catch_::class, + ] ); if ($firstNodeParent === null || $secondNodeParent === null) { return false; } + return ! $this->areNodesEqual($firstNodeParent, $secondNodeParent); } diff --git a/packages/DeadCode/tests/Rector/Assign/RemoveDoubleAssignRector/Fixture/skip_double_catch.php.inc b/packages/DeadCode/tests/Rector/Assign/RemoveDoubleAssignRector/Fixture/skip_double_catch.php.inc new file mode 100644 index 00000000000..ccc5bc09dd3 --- /dev/null +++ b/packages/DeadCode/tests/Rector/Assign/RemoveDoubleAssignRector/Fixture/skip_double_catch.php.inc @@ -0,0 +1,19 @@ +doSomething(); + } catch (\InvalidArgumentException $e) { + $noException = false; + } catch (\Exception $e) { + $noException = false; + } + } +} diff --git a/packages/DeadCode/tests/Rector/Assign/RemoveDoubleAssignRector/RemoveDoubleAssignRectorTest.php b/packages/DeadCode/tests/Rector/Assign/RemoveDoubleAssignRector/RemoveDoubleAssignRectorTest.php index ec982bb8c65..01d14b7f537 100644 --- a/packages/DeadCode/tests/Rector/Assign/RemoveDoubleAssignRector/RemoveDoubleAssignRectorTest.php +++ b/packages/DeadCode/tests/Rector/Assign/RemoveDoubleAssignRector/RemoveDoubleAssignRectorTest.php @@ -18,6 +18,8 @@ final class RemoveDoubleAssignRectorTest extends AbstractRectorTestCase __DIR__ . '/Fixture/keep_property_assign_in_different_ifs.php.inc', __DIR__ . '/Fixture/inside_if_else.php.inc', __DIR__ . '/Fixture/inside_the_same_if.php.inc', + // skip + __DIR__ . '/Fixture/skip_double_catch.php.inc', ]); } diff --git a/packages/RemovingStatic/src/UniqueObjectOrServiceDetector.php b/packages/RemovingStatic/src/UniqueObjectOrServiceDetector.php index 90eead699d4..7042c3ce1f9 100644 --- a/packages/RemovingStatic/src/UniqueObjectOrServiceDetector.php +++ b/packages/RemovingStatic/src/UniqueObjectOrServiceDetector.php @@ -8,7 +8,7 @@ use PhpParser\Node\Stmt\Class_; final class UniqueObjectOrServiceDetector { - public function isUniqueObject(Class_ $class): bool + public function isUniqueObject(): bool { // ideas: // hook in container?