Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MutatingScope: remove unnecessary callback functions #3916

Open
wants to merge 2 commits into
base: 2.1.x
Choose a base branch
from
Open
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 @@ -2042,34 +2042,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 @@ -2101,50 +2095,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 @@ -2179,19 +2166,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 @@ -2242,25 +2226,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