mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-18 05:48:21 +01:00
[NodeTypeResolver] fix tests
This commit is contained in:
parent
a193a3b6d0
commit
7fbb864f6d
@ -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;
|
||||
}
|
||||
|
@ -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 [];
|
||||
}
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user