Skip to content

Commit

Permalink
Merge pull request #7585 from tomasz-kusy/magic-const-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
weirdan committed Feb 4, 2022
2 parents f82a70e + 124aa22 commit b06fb93
Showing 1 changed file with 12 additions and 4 deletions.
Expand Up @@ -16,6 +16,8 @@
use Psalm\Type\Atomic\TNonEmptyString;
use Psalm\Type\Union;

use function dirname;

class MagicConstAnalyzer
{
public static function analyze(
Expand Down Expand Up @@ -84,10 +86,16 @@ public static function analyze(
} 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()]));
Expand Down

0 comments on commit b06fb93

Please sign in to comment.