Skip to content

Commit de3ed66

Browse files
dongm2ezYuxiang Dong
authored and
Yuxiang Dong
committed
Fix #57
1 parent 4bb334f commit de3ed66

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/Rules/Exceptions/ThrowMustBundlePreviousExceptionRule.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function processNode(Node $node, Scope $scope): array
4545
*/
4646
private $unusedThrows = [];
4747

48-
public function __construct(string $catchedVariableName)
48+
public function __construct(?string $catchedVariableName)
4949
{
5050
$this->catchedVariableName = $catchedVariableName;
5151
}
@@ -66,6 +66,10 @@ public function leaveNode(Node $node)
6666
}
6767
}
6868

69+
if (PHP_VERSION_ID >= 80000 && is_null($this->catchedVariableName)) {
70+
$this->exceptionUsedCount--;
71+
}
72+
6973
if ($node instanceof Node\Stmt\Throw_ && $this->exceptionUsedCount === 0) {
7074
$this->unusedThrows[] = $node;
7175
}

tests/Rules/Exceptions/data/throw_must_bundle_previous_exception.php

+6
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,9 @@ class MyCatchException extends \Exception
2727
// This is not okay
2828
throw new \Exception('New exception '.$e->getMessage());
2929
}
30+
31+
try {
32+
}catch (\Exception) {
33+
// This is okay
34+
throw new \Exception();
35+
}

0 commit comments

Comments
 (0)