mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
Support backslash in is_a/is_subclass_of string name
This commit is contained in:
parent
11bfaaa5f7
commit
01e41951e7
@ -1404,7 +1404,11 @@ class AssertionFinder
|
||||
$is_a_prefix = $third_arg_value === 'true' ? 'isa-string-' : 'isa-';
|
||||
|
||||
if ($second_arg instanceof PhpParser\Node\Scalar\String_) {
|
||||
$if_types[$first_var_name] = [[$prefix . $is_a_prefix . $second_arg->value]];
|
||||
$fq_class_name = $second_arg->value;
|
||||
if ($fq_class_name[0] === '\\') {
|
||||
$fq_class_name = substr($fq_class_name, 1);
|
||||
}
|
||||
$if_types[$first_var_name] = [[$prefix . $is_a_prefix . $fq_class_name]];
|
||||
} elseif ($second_arg instanceof PhpParser\Node\Expr\ClassConstFetch
|
||||
&& $second_arg->class instanceof PhpParser\Node\Name
|
||||
&& $second_arg->name instanceof PhpParser\Node\Identifier
|
||||
|
@ -395,6 +395,25 @@ class ClassStringTest extends TestCase
|
||||
return $s;
|
||||
}',
|
||||
],
|
||||
'createClassOfTypeFromStringUsingIsSubclassOfString' => [
|
||||
'<?php
|
||||
class A {}
|
||||
|
||||
/**
|
||||
* @return class-string<A> $s
|
||||
*/
|
||||
function foo(string $s) : string {
|
||||
if (!class_exists($s)) {
|
||||
throw new \UnexpectedValueException("bad");
|
||||
}
|
||||
|
||||
if (!is_subclass_of($s, "\A")) {
|
||||
throw new \UnexpectedValueException("bad");
|
||||
}
|
||||
|
||||
return $s;
|
||||
}',
|
||||
],
|
||||
'checkSubclassOfAbstract' => [
|
||||
'<?php
|
||||
interface Foo {
|
||||
|
Loading…
x
Reference in New Issue
Block a user