Skip to content

Commit 7e864e4

Browse files
phpstan-botclaude
andcommitted
Simplify resolveCallUserFuncCalleeReflection to only support single-value callbacks
Instead of iterating and returning the first match (which incorrectly handles union types like 'foo'|'bar' by only considering 'foo'), only resolve the callee when there is exactly one constant string or one constant array callback value. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent e30122d commit 7e864e4

1 file changed

Lines changed: 10 additions & 13 deletions

File tree

src/Analyser/ExprHandler/FuncCallHandler.php

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -882,24 +882,21 @@ private function resolveCallUserFuncCalleeReflection(FuncCall $innerFuncCall, Mu
882882

883883
$callbackType = $scope->getType($innerFuncCall->name);
884884

885-
foreach ($callbackType->getConstantStrings() as $constantString) {
886-
if ($constantString->getValue() === '') {
887-
continue;
888-
}
889-
$funcName = new Name($constantString->getValue());
885+
$constantStrings = $callbackType->getConstantStrings();
886+
if (count($constantStrings) === 1 && $constantStrings[0]->getValue() !== '') {
887+
$funcName = new Name($constantStrings[0]->getValue());
890888
if ($this->reflectionProvider->hasFunction($funcName, $scope)) {
891889
return $this->reflectionProvider->getFunction($funcName, $scope);
892890
}
893891
}
894892

895-
foreach ($callbackType->getConstantArrays() as $constantArray) {
896-
foreach ($constantArray->findTypeAndMethodNames() as $typeAndMethod) {
897-
if ($typeAndMethod->isUnknown() || !$typeAndMethod->getCertainty()->yes()) {
898-
continue;
899-
}
900-
$methodType = $typeAndMethod->getType();
901-
if ($methodType->hasMethod($typeAndMethod->getMethod())->yes()) {
902-
return $methodType->getMethod($typeAndMethod->getMethod(), $scope);
893+
$constantArrays = $callbackType->getConstantArrays();
894+
if (count($constantArrays) === 1) {
895+
$typeAndMethods = $constantArrays[0]->findTypeAndMethodNames();
896+
if (count($typeAndMethods) === 1 && !$typeAndMethods[0]->isUnknown() && $typeAndMethods[0]->getCertainty()->yes()) {
897+
$methodType = $typeAndMethods[0]->getType();
898+
if ($methodType->hasMethod($typeAndMethods[0]->getMethod())->yes()) {
899+
return $methodType->getMethod($typeAndMethods[0]->getMethod(), $scope);
903900
}
904901
}
905902
}

0 commit comments

Comments
 (0)