Skip to content

Commit 470fec0

Browse files
authored
Merge pull request #34 from moufmouf/throw_in_catch_ok
A throw Exception in a catch statement is ok
2 parents 4171d44 + f24ad7b commit 470fec0

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/Rules/Exceptions/DoNotThrowExceptionBaseClassRule.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ public function getNodeType(): string
2626
*/
2727
public function processNode(Node $node, Scope $scope): array
2828
{
29+
if (!$node->expr instanceof Node\Expr\New_) {
30+
// Only catch "throw new ..."
31+
return [];
32+
}
33+
2934
$type = $scope->getType($node->expr);
3035

3136
if ($type instanceof ObjectType) {

tests/Rules/Exceptions/data/throw_exception.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,13 @@ function bar()
1515
{
1616
throw new \Exception('');
1717
}
18+
19+
function baz()
20+
{
21+
try {
22+
//...
23+
} catch (\Exception $e) {
24+
// This is ok
25+
throw $e;
26+
}
27+
}

0 commit comments

Comments
 (0)