Skip to content

Commit

Permalink
Merge pull request #6972 from orklah/unused-throws
Browse files Browse the repository at this point in the history
prevent Psalm from considering throwing methods as unused just because they're immutable
  • Loading branch information
orklah committed Nov 22, 2021
2 parents e13c48a + d8fcd78 commit eca56c0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Expand Up @@ -112,6 +112,7 @@ public static function analyze(
&& !$method_storage->assertions
&& !$method_storage->if_true_assertions
&& !$method_storage->if_false_assertions
&& !$method_storage->throws
) {
if (IssueBuffer::accepts(
new \Psalm\Issue\UnusedMethodCall(
Expand Down
21 changes: 21 additions & 0 deletions tests/UnusedCodeTest.php
Expand Up @@ -1162,6 +1162,27 @@ private function assert(?string $val): void {
$a = new A();
echo $a->getVal(null);',
],
'NotUnusedWhenThrows' => [
'<?php
declare(strict_types=1);
/** @psalm-immutable */
final class UserList
{
/**
* @throws InvalidArgumentException
*/
public function validate(): void
{
// Some validation happens here
throw new \InvalidArgumentException();
}
}
$a = new UserList();
$a->validate();
',
],
'__halt_compiler_no_usage_check' => [
'<?php
exit(0);
Expand Down

0 comments on commit eca56c0

Please sign in to comment.