1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

prevent Psalm from considering throwing methods as unused just because they're immutable

This commit is contained in:
orklah 2021-11-22 21:29:57 +01:00
parent 6d21288d31
commit 1c1e352e5f
2 changed files with 23 additions and 0 deletions

View File

@ -112,6 +112,7 @@ class MethodCallPurityAnalyzer
&& !$method_storage->assertions
&& !$method_storage->if_true_assertions
&& !$method_storage->if_false_assertions
&& !$method_storage->throws
) {
if (IssueBuffer::accepts(
new \Psalm\Issue\UnusedMethodCall(

View File

@ -1162,6 +1162,28 @@ class UnusedCodeTest extends TestCase
$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);