Skip to content

Commit 780b3d5

Browse files
committed
MutatingScope: remove unnecessary callback functions
1 parent adc504d commit 780b3d5

File tree

1 file changed

+45
-58
lines changed

1 file changed

+45
-58
lines changed

Diff for: src/Analyser/MutatingScope.php

+45-58
Original file line numberDiff line numberDiff line change
@@ -2042,34 +2042,28 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
20422042
if ($node instanceof MethodCall) {
20432043
if ($node->name instanceof Node\Identifier) {
20442044
if ($this->nativeTypesPromoted) {
2045-
$typeCallback = function () use ($node): Type {
2046-
$methodReflection = $this->getMethodReflection(
2047-
$this->getNativeType($node->var),
2048-
$node->name->name,
2049-
);
2050-
if ($methodReflection === null) {
2051-
return new ErrorType();
2052-
}
2053-
2054-
return ParametersAcceptorSelector::combineAcceptors($methodReflection->getVariants())->getNativeReturnType();
2055-
};
2056-
2057-
return $this->getNullsafeShortCircuitingType($node->var, $typeCallback());
2058-
}
2059-
2060-
$typeCallback = function () use ($node): Type {
2061-
$returnType = $this->methodCallReturnType(
2062-
$this->getType($node->var),
2045+
$methodReflection = $this->getMethodReflection(
2046+
$this->getNativeType($node->var),
20632047
$node->name->name,
2064-
$node,
20652048
);
2066-
if ($returnType === null) {
2067-
return new ErrorType();
2049+
if ($methodReflection === null) {
2050+
$returnType = new ErrorType();
2051+
} else {
2052+
$returnType = ParametersAcceptorSelector::combineAcceptors($methodReflection->getVariants())->getNativeReturnType();
20682053
}
2069-
return $returnType;
2070-
};
20712054

2072-
return $this->getNullsafeShortCircuitingType($node->var, $typeCallback());
2055+
return $this->getNullsafeShortCircuitingType($node->var, $returnType);
2056+
}
2057+
2058+
$returnType = $this->methodCallReturnType(
2059+
$this->getType($node->var),
2060+
$node->name->name,
2061+
$node,
2062+
);
2063+
if ($returnType === null) {
2064+
$returnType = new ErrorType();
2065+
}
2066+
return $this->getNullsafeShortCircuitingType($node->var, $returnType);
20732067
}
20742068

20752069
$nameType = $this->getType($node->name);
@@ -2101,50 +2095,43 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
21012095
if ($node instanceof Expr\StaticCall) {
21022096
if ($node->name instanceof Node\Identifier) {
21032097
if ($this->nativeTypesPromoted) {
2104-
$typeCallback = function () use ($node): Type {
2105-
if ($node->class instanceof Name) {
2106-
$staticMethodCalledOnType = $this->resolveTypeByNameWithLateStaticBinding($node->class, $node->name);
2107-
} else {
2108-
$staticMethodCalledOnType = $this->getNativeType($node->class);
2109-
}
2110-
$methodReflection = $this->getMethodReflection(
2111-
$staticMethodCalledOnType,
2112-
$node->name->name,
2113-
);
2114-
if ($methodReflection === null) {
2115-
return new ErrorType();
2116-
}
2117-
2118-
return ParametersAcceptorSelector::combineAcceptors($methodReflection->getVariants())->getNativeReturnType();
2119-
};
2098+
if ($node->class instanceof Name) {
2099+
$staticMethodCalledOnType = $this->resolveTypeByNameWithLateStaticBinding($node->class, $node->name);
2100+
} else {
2101+
$staticMethodCalledOnType = $this->getNativeType($node->class);
2102+
}
2103+
$methodReflection = $this->getMethodReflection(
2104+
$staticMethodCalledOnType,
2105+
$node->name->name,
2106+
);
2107+
if ($methodReflection === null) {
2108+
$callType = new ErrorType();
2109+
} else {
2110+
$callType = ParametersAcceptorSelector::combineAcceptors($methodReflection->getVariants())->getNativeReturnType();
2111+
}
21202112

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

21262117
return $callType;
21272118
}
21282119

2129-
$typeCallback = function () use ($node): Type {
2130-
if ($node->class instanceof Name) {
2131-
$staticMethodCalledOnType = $this->resolveTypeByNameWithLateStaticBinding($node->class, $node->name);
2132-
} else {
2133-
$staticMethodCalledOnType = TypeCombinator::removeNull($this->getType($node->class))->getObjectTypeOrClassStringObjectType();
2134-
}
2120+
if ($node->class instanceof Name) {
2121+
$staticMethodCalledOnType = $this->resolveTypeByNameWithLateStaticBinding($node->class, $node->name);
2122+
} else {
2123+
$staticMethodCalledOnType = TypeCombinator::removeNull($this->getType($node->class))->getObjectTypeOrClassStringObjectType();
2124+
}
21352125

2136-
$returnType = $this->methodCallReturnType(
2137-
$staticMethodCalledOnType,
2138-
$node->name->toString(),
2139-
$node,
2140-
);
2141-
if ($returnType === null) {
2142-
return new ErrorType();
2143-
}
2144-
return $returnType;
2145-
};
2126+
$callType = $this->methodCallReturnType(
2127+
$staticMethodCalledOnType,
2128+
$node->name->toString(),
2129+
$node,
2130+
);
2131+
if ($callType === null) {
2132+
$callType = new ErrorType();
2133+
}
21462134

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

0 commit comments

Comments
 (0)