From 8f3d76f6703c1b78d027cc29a924c6fa1ddcd61a Mon Sep 17 00:00:00 2001 From: Maxim Babichev Date: Wed, 1 Dec 2021 11:47:34 +0300 Subject: [PATCH 1/3] Update ThrowMustBundlePreviousExceptionRule.php --- src/Rules/Exceptions/ThrowMustBundlePreviousExceptionRule.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Rules/Exceptions/ThrowMustBundlePreviousExceptionRule.php b/src/Rules/Exceptions/ThrowMustBundlePreviousExceptionRule.php index 36fd5d2..d08782b 100644 --- a/src/Rules/Exceptions/ThrowMustBundlePreviousExceptionRule.php +++ b/src/Rules/Exceptions/ThrowMustBundlePreviousExceptionRule.php @@ -56,6 +56,9 @@ public function leaveNode(Node $node) if ($node->name === $this->catchedVariableName) { $this->exceptionUsedCount++; } + if ($node->getAttribute('parent') instanceof Node\Expr\New_) { + $this->exceptionUsedCount--; + } return null; } From 0ece3a93cda838e6ba68ed09e64766657c3bc719 Mon Sep 17 00:00:00 2001 From: Maxim Babichev Date: Wed, 1 Dec 2021 11:49:01 +0300 Subject: [PATCH 2/3] Update throw_must_bundle_previous_exception.php --- .../data/throw_must_bundle_previous_exception.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/Rules/Exceptions/data/throw_must_bundle_previous_exception.php b/tests/Rules/Exceptions/data/throw_must_bundle_previous_exception.php index 6d41e51..216dcb2 100644 --- a/tests/Rules/Exceptions/data/throw_must_bundle_previous_exception.php +++ b/tests/Rules/Exceptions/data/throw_must_bundle_previous_exception.php @@ -32,4 +32,10 @@ class MyCatchException extends \Exception }catch (\Exception) { // This is okay throw new \Exception(); -} \ No newline at end of file +} + +try { +} catch (\Exception $e) { + // This is not okay + throw new $e; +} From 62dd64b501bee871c5c622cd5f470a0597ff55cc Mon Sep 17 00:00:00 2001 From: Maxim Babichev Date: Wed, 1 Dec 2021 11:50:16 +0300 Subject: [PATCH 3/3] Update ThrowMustBundlePreviousExceptionRuleTest.php --- .../Exceptions/ThrowMustBundlePreviousExceptionRuleTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/Rules/Exceptions/ThrowMustBundlePreviousExceptionRuleTest.php b/tests/Rules/Exceptions/ThrowMustBundlePreviousExceptionRuleTest.php index 8e55138..ec754cc 100644 --- a/tests/Rules/Exceptions/ThrowMustBundlePreviousExceptionRuleTest.php +++ b/tests/Rules/Exceptions/ThrowMustBundlePreviousExceptionRuleTest.php @@ -19,6 +19,10 @@ public function testCheckCatchedException() 'Thrown exceptions in a catch block must bundle the previous exception (see throw statement line 28). More info: http://bit.ly/bundleexception', 26, ], + [ + 'Thrown exceptions in a catch block must bundle the previous exception (see throw statement line 40). More info: http://bit.ly/bundleexception', + 38, + ], ]); } }