From 85ebee36d4b70a5fb2cea9152cf5359bee85fbcb Mon Sep 17 00:00:00 2001 From: Simon Schaufelberger Date: Wed, 16 Oct 2024 01:50:33 +0200 Subject: [PATCH] [BUGFIX] Skip Exceptions without any parameters --- .../CodeQuality/General/AddErrorCodeToExceptionRector.php | 2 +- .../AddErrorCodeToExceptionRector/Fixture/fixture.php.inc | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/rules/CodeQuality/General/AddErrorCodeToExceptionRector.php b/rules/CodeQuality/General/AddErrorCodeToExceptionRector.php index 68344cb93..314b79cf5 100644 --- a/rules/CodeQuality/General/AddErrorCodeToExceptionRector.php +++ b/rules/CodeQuality/General/AddErrorCodeToExceptionRector.php @@ -68,6 +68,6 @@ private function shouldSkip(Throw_ $node): bool return true; } - return count($node->expr->args) > 1; + return count($node->expr->args) !== 1; } } diff --git a/tests/Rector/CodeQuality/General/AddErrorCodeToExceptionRector/Fixture/fixture.php.inc b/tests/Rector/CodeQuality/General/AddErrorCodeToExceptionRector/Fixture/fixture.php.inc index bf838a2f4..f8368526e 100644 --- a/tests/Rector/CodeQuality/General/AddErrorCodeToExceptionRector/Fixture/fixture.php.inc +++ b/tests/Rector/CodeQuality/General/AddErrorCodeToExceptionRector/Fixture/fixture.php.inc @@ -6,6 +6,10 @@ if ('a' === 'b') { throw new \RuntimeException('my message'); } +if ('b' === 'c') { + throw new \RuntimeException(); +} + throw new \RuntimeException('do not touch this', 564); ?> ----- @@ -17,5 +21,9 @@ if ('a' === 'b') { throw new \RuntimeException('my message', 1729021897); } +if ('b' === 'c') { + throw new \RuntimeException(); +} + throw new \RuntimeException('do not touch this', 564); ?>