1
0
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:
Brown 2019-05-22 17:49:38 -04:00
parent 7601921ecf
commit f728d797cf
2 changed files with 45 additions and 1 deletions

View File

@ -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;
}

View File

@ -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;
}
}',
],
];
}