mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
Fix #1665 - allow -if-true & -if-false assertions on static methods
This commit is contained in:
parent
7601921ecf
commit
f728d797cf
@ -288,7 +288,9 @@ class AssertionFinder
|
||||
return;
|
||||
}
|
||||
|
||||
if ($conditional instanceof PhpParser\Node\Expr\MethodCall) {
|
||||
if ($conditional instanceof PhpParser\Node\Expr\MethodCall
|
||||
|| $conditional instanceof PhpParser\Node\Expr\StaticCall
|
||||
) {
|
||||
$conditional->assertions = self::processCustomAssertion($conditional, $this_class_name, $source, false);
|
||||
return;
|
||||
}
|
||||
|
@ -718,6 +718,48 @@ class AssertTest extends TestCase
|
||||
unset($options["a"], $options["b"]);
|
||||
}',
|
||||
],
|
||||
'assertStaticMethodIfFalse' => [
|
||||
'<?php
|
||||
class StringUtility {
|
||||
/**
|
||||
* @psalm-assert-if-false !null $yStr
|
||||
*/
|
||||
public static function isNull(?string $yStr): bool {
|
||||
if ($yStr === null) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function test(?string $in) : void {
|
||||
$str = "test";
|
||||
if(!StringUtility::isNull($in)) {
|
||||
$str .= $in;
|
||||
}
|
||||
}',
|
||||
],
|
||||
'assertStaticMethodIfTrue' => [
|
||||
'<?php
|
||||
class StringUtility {
|
||||
/**
|
||||
* @psalm-assert-if-true !null $yStr
|
||||
*/
|
||||
public static function isNotNull(?string $yStr): bool {
|
||||
if ($yStr === null) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function test(?string $in) : void {
|
||||
$str = "test";
|
||||
if(StringUtility::isNotNull($in)) {
|
||||
$str .= $in;
|
||||
}
|
||||
}',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user