1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Fix #645 - add isa- prefix for strings as well as class constants

This commit is contained in:
Matt Brown 2018-04-05 12:03:36 -04:00
parent 78d5adb17d
commit 24f307d568
2 changed files with 21 additions and 1 deletions

View File

@ -829,7 +829,7 @@ class AssertionFinder
}
if ($first_arg instanceof PhpParser\Node\Scalar\String_) {
$if_types[$first_var_name] = $prefix . $first_arg->value;
$if_types[$first_var_name] = $prefix . $is_a_prefix . $first_arg->value;
} elseif ($first_arg instanceof PhpParser\Node\Expr\ClassConstFetch
&& $first_arg->class instanceof PhpParser\Node\Name
&& is_string($first_arg->name)

View File

@ -133,6 +133,26 @@ class ClassTest extends TestCase
$foo->bar();
}',
],
'returnStringAfterIsACheckWithClassConst' => [
'<?php
class Foo{}
function bar(string $maybeBaz) : string {
if (!is_a($maybeBaz, Foo::class, true)) {
throw new Exception("not Foo");
}
return $maybeBaz;
}',
],
'returnStringAfterIsACheckWithString' => [
'<?php
class Foo{}
function bar(string $maybeBaz) : string {
if (!is_a($maybeBaz, "Foo", true)) {
throw new Exception("not Foo");
}
return $maybeBaz;
}',
],
];
}