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

Fix #1555 - allow phantom class constants

This commit is contained in:
Matthew Brown 2020-02-18 19:46:05 -05:00
parent 520b646ef6
commit aea33824e6
3 changed files with 18 additions and 2 deletions

View File

@ -145,7 +145,9 @@ class StaticCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\
}
}
if (!$does_class_exist) {
if (!isset($context->phantom_classes[strtolower($fq_class_name)])
&& !$does_class_exist
) {
$does_class_exist = ClassLikeAnalyzer::checkFullyQualifiedClassLikeName(
$statements_analyzer,
$fq_class_name,

View File

@ -74,7 +74,9 @@ class ClassConstFetchAnalyzer
);
if ($stmt->name instanceof PhpParser\Node\Identifier) {
if (!$context->inside_class_exists || $stmt->name->name !== 'class') {
if ((!$context->inside_class_exists || $stmt->name->name !== 'class')
&& !isset($context->phantom_classes[strtolower($fq_class_name)])
) {
if (ClassLikeAnalyzer::checkFullyQualifiedClassLikeName(
$statements_analyzer,
$fq_class_name,

View File

@ -513,6 +513,18 @@ class ClassTest extends TestCase
}
}',
],
'noErrorsAfterClassExists' => [
'<?php
if (class_exists(A::class)) {
if (method_exists(A::class, "method")) {
echo A::method();
}
echo A::class;
/** @psalm-suppress MixedArgument */
echo A::SOME_CONST;
}'
],
];
}