1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Infer literal string for __namespace__

This commit is contained in:
bugreportuser 2019-02-18 12:14:08 -06:00 committed by Matthew Brown
parent 6b045236e0
commit f603449745
2 changed files with 16 additions and 9 deletions

View File

@ -365,14 +365,6 @@ abstract class ClassLikeAnalyzer extends SourceAnalyzer implements StatementsSou
);
}
/**
* @return null|string
*/
public function getNamespace()
{
return $this->source->getNamespace();
}
/**
* @return array<string, string>
*/

View File

@ -147,12 +147,27 @@ class ExpressionAnalyzer
$stmt->inferredType = Type::getLiteralClassString($context->self);
break;
case '__namespace__':
$namespace = $statements_analyzer->getNamespace();
if ($namespace === null &&
IssueBuffer::accepts(
new UndefinedConstant(
'Cannot get __namespace__ outside a namespace',
new CodeLocation($statements_analyzer->getSource(), $stmt)
),
$statements_analyzer->getSuppressedIssues()
)) {
// fall through
}
$stmt->inferredType = Type::getString($namespace);
break;
case '__file__':
case '__dir__':
case '__function__':
case '__trait__':
case '__method__':
case '__namespace__':
$stmt->inferredType = Type::getString();
break;
}