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:
parent
78d5adb17d
commit
24f307d568
@ -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)
|
||||
|
@ -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;
|
||||
}',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user