[NodeTypeResolver] fix tests

This commit is contained in:
TomasVotruba 2017-09-11 15:54:15 +02:00
parent a193a3b6d0
commit 7fbb864f6d
3 changed files with 15 additions and 9 deletions

View File

@ -92,7 +92,9 @@ final class TypeResolver extends NodeVisitorAbstract
$variableName = $newNode->class->name;
return $this->typeContext->getTypeForVariable($variableName);
} elseif ($newNode->class instanceof Name) {
}
if ($newNode->class instanceof Name) {
/** @var FullyQualified $fqnName */
$fqnName = $newNode->class->getAttribute(Attribute::RESOLVED_NAME);
@ -117,6 +119,8 @@ final class TypeResolver extends NodeVisitorAbstract
$variableType = $this->getTypeFromNewNode($parentNode->expr);
$this->typeContext->addVariableWithType($variableName, $variableType);
} else {
$variableType = $this->typeContext->getTypeForVariable((string) $variableNode->name);
}
} else {
$variableType = $this->typeContext->getTypeForVariable((string) $variableNode->name);
@ -141,13 +145,6 @@ final class TypeResolver extends NodeVisitorAbstract
private function processPropertyFetch(PropertyFetch $propertyFetchNode): void
{
if ($propertyFetchNode->var instanceof New_) {
$propertyType = $propertyFetchNode->var->class->toString();
$propertyFetchNode->setAttribute(Attribute::TYPE, $propertyType);
return;
}
// e.g. $r->getParameters()[0]->name
if ($propertyFetchNode->var instanceof ArrayDimFetch) {
if ($propertyFetchNode->var->var instanceof MethodCall) {
@ -162,6 +159,14 @@ final class TypeResolver extends NodeVisitorAbstract
return;
}
if ($propertyFetchNode->var instanceof New_) {
$propertyType = $propertyFetchNode->var->class->toString();
$propertyFetchNode->setAttribute(Attribute::TYPE, $propertyType);
return;
}
if ($propertyFetchNode->var->name !== 'this') {
return;
}

View File

@ -40,7 +40,7 @@ final class ConstructorPropertyTypesExtractor
private function getConstructorParametersWithTypes(Class_ $classNode): array
{
$className = $classNode->namespacedName->toString();
if (! class_exists($className, false)) {
if (! class_exists($className)) {
return [];
}

View File

@ -43,6 +43,7 @@ final class PropertyTest extends AbstractContainerAwareTestCase
{
/** @var PropertyFetch $propertyFetchNode */
$propertyFetchNode = $this->nodes[1]->stmts[1]->stmts[2]->stmts[0]->expr;
$this->assertSame(Html::class, $propertyFetchNode->getAttribute(Attribute::TYPE));
}