mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
don't consider calls to methods with assertions as Unused
This commit is contained in:
parent
f327c986d0
commit
9c9669ea44
@ -106,7 +106,13 @@ class MethodCallPurityAnalyzer
|
||||
&& !$context->inside_general_use
|
||||
&& !$context->inside_throw
|
||||
) {
|
||||
if (!$context->inside_assignment && !$context->inside_call && !$context->inside_return) {
|
||||
if (!$context->inside_assignment
|
||||
&& !$context->inside_call
|
||||
&& !$context->inside_return
|
||||
&& !$method_storage->assertions
|
||||
&& !$method_storage->if_true_assertions
|
||||
&& !$method_storage->if_false_assertions
|
||||
) {
|
||||
if (IssueBuffer::accepts(
|
||||
new \Psalm\Issue\UnusedMethodCall(
|
||||
'The call to ' . $cased_method_id . ' is not used',
|
||||
|
@ -1069,6 +1069,30 @@ class UnusedCodeTest extends TestCase
|
||||
echo "hello";
|
||||
}',
|
||||
],
|
||||
'NotUnusedWhenAssert' => [
|
||||
'<?php
|
||||
|
||||
class A {
|
||||
public function getVal(?string $val): string {
|
||||
$this->assert($val);
|
||||
|
||||
return $val;
|
||||
}
|
||||
|
||||
/**
|
||||
* @psalm-assert string $val
|
||||
* @psalm-mutation-free
|
||||
*/
|
||||
private function assert(?string $val): void {
|
||||
if (null === $val) {
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$a = new A();
|
||||
$a->getVal(null);',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user