diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/MagicConstAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/MagicConstAnalyzer.php index 4432087d9..481a5afa0 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/MagicConstAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/MagicConstAnalyzer.php @@ -16,6 +16,8 @@ use Psalm\Type\Atomic\TCallableString; use Psalm\Type\Atomic\TNonEmptyString; use Psalm\Type\Union; +use function dirname; + class MagicConstAnalyzer { public static function analyze( @@ -84,10 +86,16 @@ class MagicConstAnalyzer } else { $statements_analyzer->node_data->setType($stmt, new Union([new TCallableString])); } - } elseif ($stmt instanceof PhpParser\Node\Scalar\MagicConst\File - || $stmt instanceof PhpParser\Node\Scalar\MagicConst\Dir - ) { - $statements_analyzer->node_data->setType($stmt, new Union([new TNonEmptyString()])); + } elseif ($stmt instanceof PhpParser\Node\Scalar\MagicConst\Dir) { + $statements_analyzer->node_data->setType( + $stmt, + Type::getString(dirname($statements_analyzer->getSource()->getFilePath())) + ); + } elseif ($stmt instanceof PhpParser\Node\Scalar\MagicConst\File) { + $statements_analyzer->node_data->setType( + $stmt, + Type::getString($statements_analyzer->getSource()->getFilePath()) + ); } elseif ($stmt instanceof PhpParser\Node\Scalar\MagicConst\Trait_) { if ($statements_analyzer->getSource() instanceof TraitAnalyzer) { $statements_analyzer->node_data->setType($stmt, new Union([new TNonEmptyString()]));