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

Fix #3607 - constant string class reference with leading backslash (#3612)

This commit is contained in:
Ilija Tovilo 2020-06-20 00:02:39 +02:00 committed by GitHub
parent 5bc657504d
commit 2f646d29db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View File

@ -641,7 +641,9 @@ class FunctionCallAnalyzer extends CallAnalyzer
if (strpos($var_type_part->value, '::')) {
$parts = explode('::', strtolower($var_type_part->value));
$potential_method_id = new \Psalm\Internal\MethodIdentifier($parts[0], $parts[1]);
$fq_class_name = $parts[0];
$fq_class_name = \preg_replace('/^\\\\/', '', $fq_class_name);
$potential_method_id = new \Psalm\Internal\MethodIdentifier($fq_class_name, $parts[1]);
} else {
$explicit_function_name = new PhpParser\Node\Name\FullyQualified(
$var_type_part->value,

View File

@ -703,6 +703,22 @@ class UnusedCodeTest extends TestCase
createFoo(Foo::class)->baz();'
],
'usedMethodReferencedByString' => [
'<?php
class A {
static function b(): void {}
}
$methodRef = "A::b";
$methodRef();',
],
'usedMethodReferencedByStringWithLeadingBackslash' => [
'<?php
class A {
static function b(): void {}
}
$methodRef = "\A::b";
$methodRef();',
],
];
}