Skip to content

Commit ca499cb

Browse files
committed
fix for throw is expression
1 parent bc2ea58 commit ca499cb

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/Rules/Expression/DisallowUnusedExpressionRule.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PhpParser\Node;
66
use PhpParser\Node\Stmt\Expression;
7+
use PhpParser\Node\Expr\Throw_;
78
use PHPStan\Analyser\Scope;
89
use PHPStan\Rules\Rule;
910
use PHPStan\Rules\RuleErrorBuilder;
@@ -38,6 +39,10 @@ public function processNode(Node $node, Scope $scope): array
3839
return [];
3940
}
4041

42+
if ($node->expr instanceof Throw_) {
43+
return [];
44+
}
45+
4146
return [
4247
RuleErrorBuilder::message('Enforce that an expression gets used')
4348
->identifier('phpstanFunctionalProgramming.disallowUnusedExpression')

tests/Rules/Expression/data/expressions.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,10 @@ function example()
3232

3333
for ($i = 0; 2 + 5; $i++) {
3434
}
35+
36+
function getFileData(string $filepath): void
37+
{
38+
if (!file_exists($filepath)) {
39+
throw new \Exception("File '$filepath' does not exist");
40+
}
41+
}

0 commit comments

Comments
 (0)