Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 67 additions & 87 deletions src/Analyser/MutatingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -2113,34 +2113,28 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
if ($node instanceof MethodCall) {
if ($node->name instanceof Node\Identifier) {
if ($this->nativeTypesPromoted) {
$typeCallback = function () use ($node): Type {
$methodReflection = $this->getMethodReflection(
$this->getNativeType($node->var),
$node->name->name,
);
if ($methodReflection === null) {
return new ErrorType();
}

return ParametersAcceptorSelector::combineAcceptors($methodReflection->getVariants())->getNativeReturnType();
};

return $this->getNullsafeShortCircuitingType($node->var, $typeCallback());
}

$typeCallback = function () use ($node): Type {
$returnType = $this->methodCallReturnType(
$this->getType($node->var),
$methodReflection = $this->getMethodReflection(
$this->getNativeType($node->var),
$node->name->name,
$node,
);
if ($returnType === null) {
return new ErrorType();
if ($methodReflection === null) {
$returnType = new ErrorType();
} else {
$returnType = ParametersAcceptorSelector::combineAcceptors($methodReflection->getVariants())->getNativeReturnType();
}
return $returnType;
};

return $this->getNullsafeShortCircuitingType($node->var, $typeCallback());
return $this->getNullsafeShortCircuitingType($node->var, $returnType);
}

$returnType = $this->methodCallReturnType(
$this->getType($node->var),
$node->name->name,
$node,
);
if ($returnType === null) {
$returnType = new ErrorType();
}
return $this->getNullsafeShortCircuitingType($node->var, $returnType);
}

$nameType = $this->getType($node->name);
Expand Down Expand Up @@ -2172,50 +2166,43 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
if ($node instanceof Expr\StaticCall) {
if ($node->name instanceof Node\Identifier) {
if ($this->nativeTypesPromoted) {
$typeCallback = function () use ($node): Type {
if ($node->class instanceof Name) {
$staticMethodCalledOnType = $this->resolveTypeByNameWithLateStaticBinding($node->class, $node->name);
} else {
$staticMethodCalledOnType = $this->getNativeType($node->class);
}
$methodReflection = $this->getMethodReflection(
$staticMethodCalledOnType,
$node->name->name,
);
if ($methodReflection === null) {
return new ErrorType();
}

return ParametersAcceptorSelector::combineAcceptors($methodReflection->getVariants())->getNativeReturnType();
};
if ($node->class instanceof Name) {
$staticMethodCalledOnType = $this->resolveTypeByNameWithLateStaticBinding($node->class, $node->name);
} else {
$staticMethodCalledOnType = $this->getNativeType($node->class);
}
$methodReflection = $this->getMethodReflection(
$staticMethodCalledOnType,
$node->name->name,
);
if ($methodReflection === null) {
$callType = new ErrorType();
} else {
$callType = ParametersAcceptorSelector::combineAcceptors($methodReflection->getVariants())->getNativeReturnType();
}

$callType = $typeCallback();
if ($node->class instanceof Expr) {
return $this->getNullsafeShortCircuitingType($node->class, $callType);
}

return $callType;
}

$typeCallback = function () use ($node): Type {
if ($node->class instanceof Name) {
$staticMethodCalledOnType = $this->resolveTypeByNameWithLateStaticBinding($node->class, $node->name);
} else {
$staticMethodCalledOnType = TypeCombinator::removeNull($this->getType($node->class))->getObjectTypeOrClassStringObjectType();
}
if ($node->class instanceof Name) {
$staticMethodCalledOnType = $this->resolveTypeByNameWithLateStaticBinding($node->class, $node->name);
} else {
$staticMethodCalledOnType = TypeCombinator::removeNull($this->getType($node->class))->getObjectTypeOrClassStringObjectType();
}

$returnType = $this->methodCallReturnType(
$staticMethodCalledOnType,
$node->name->toString(),
$node,
);
if ($returnType === null) {
return new ErrorType();
}
return $returnType;
};
$callType = $this->methodCallReturnType(
$staticMethodCalledOnType,
$node->name->toString(),
$node,
);
if ($callType === null) {
$callType = new ErrorType();
}

$callType = $typeCallback();
if ($node->class instanceof Expr) {
return $this->getNullsafeShortCircuitingType($node->class, $callType);
}
Expand Down Expand Up @@ -2250,19 +2237,16 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
return $this->getNullsafeShortCircuitingType($node->var, $nativeType);
}

$typeCallback = function () use ($node): Type {
$returnType = $this->propertyFetchType(
$this->getType($node->var),
$node->name->name,
$node,
);
if ($returnType === null) {
return new ErrorType();
}
return $returnType;
};
$returnType = $this->propertyFetchType(
$this->getType($node->var),
$node->name->name,
$node,
);
if ($returnType === null) {
$returnType = new ErrorType();
}

return $this->getNullsafeShortCircuitingType($node->var, $typeCallback());
return $this->getNullsafeShortCircuitingType($node->var, $returnType);
}

$nameType = $this->getType($node->name);
Expand Down Expand Up @@ -2313,25 +2297,21 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
return $nativeType;
}

$typeCallback = function () use ($node): Type {
if ($node->class instanceof Name) {
$staticPropertyFetchedOnType = $this->resolveTypeByName($node->class);
} else {
$staticPropertyFetchedOnType = TypeCombinator::removeNull($this->getType($node->class))->getObjectTypeOrClassStringObjectType();
}
if ($node->class instanceof Name) {
$staticPropertyFetchedOnType = $this->resolveTypeByName($node->class);
} else {
$staticPropertyFetchedOnType = TypeCombinator::removeNull($this->getType($node->class))->getObjectTypeOrClassStringObjectType();
}

$returnType = $this->propertyFetchType(
$staticPropertyFetchedOnType,
$node->name->toString(),
$node,
);
if ($returnType === null) {
return new ErrorType();
}
return $returnType;
};
$fetchType = $this->propertyFetchType(
$staticPropertyFetchedOnType,
$node->name->toString(),
$node,
);
if ($fetchType === null) {
$fetchType = new ErrorType();
}

$fetchType = $typeCallback();
if ($node->class instanceof Expr) {
return $this->getNullsafeShortCircuitingType($node->class, $fetchType);
}
Expand Down
Loading