TypeResolver: add check for new ->property

This commit is contained in:
TomasVotruba 2017-09-28 20:18:05 +02:00
parent b83da2fb20
commit 1b66285ab3

View File

@ -87,6 +87,7 @@ final class TypeResolver extends NodeVisitorAbstract
private function getTypeFromNewNode(New_ $newNode): string
{
// e.g. new $someClass;
if ($newNode->class instanceof Variable) {
// can be anything (dynamic)
$variableName = $newNode->class->name;
@ -94,6 +95,7 @@ final class TypeResolver extends NodeVisitorAbstract
return $this->typeContext->getTypeForVariable($variableName);
}
// e.g. new SomeClass;
if ($newNode->class instanceof Name) {
/** @var FullyQualified $fqnName */
$fqnName = $newNode->class->getAttribute(Attribute::RESOLVED_NAME);
@ -101,6 +103,22 @@ final class TypeResolver extends NodeVisitorAbstract
return $fqnName->toString();
}
// e.g. new $this->templateClass;
if ($newNode->class instanceof PropertyFetch) {
if ($newNode->class->var->name !== 'this') {
throw new NotImplementedException(sprintf(
'Not implemented yet. Go to "%s()" and add check for "%s" node for external dependency.',
__METHOD__,
get_class($newNode->class)
));
}
// can be anything (dynamic)
$propertyName = (string) $newNode->class->name;
return $this->typeContext->getTypeForProperty($propertyName);
}
throw new NotImplementedException(sprintf(
'Not implemented yet. Go to "%s()" and add check for "%s" node.',
__METHOD__,