Skip to content

Commit

Permalink
Fix #1555 - allow phantom class constants
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Feb 19, 2020
1 parent 520b646 commit aea3382
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ public static function analyze(
}
}

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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ public static function analyze(
);

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,
Expand Down
12 changes: 12 additions & 0 deletions tests/ClassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,18 @@ public function get(): A {
}
}',
],
'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;
}'
],
];
}

Expand Down

0 comments on commit aea3382

Please sign in to comment.