Skip to content

Commit f72b536

Browse files
phpstan-botclaude
andcommitted
Reorder if/elseif: check keyVar !== null before byRefWithoutKey
Per reviewer feedback, keep the original branch order so the existing keyVar path comes first and the new byRefWithoutKey path is the elseif. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 3e9304a commit f72b536

1 file changed

Lines changed: 15 additions & 15 deletions

File tree

src/Analyser/NodeScopeResolver.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,21 +1362,7 @@ public function processStmtNode(
13621362
$valueTypeChanged = false;
13631363
$keyTypeChanged = false;
13641364

1365-
if ($byRefWithoutKey) {
1366-
$arrayDimFetchLoopTypes = [];
1367-
foreach ($scopesWithIterableValueType as $scopeWithIterableValueType) {
1368-
$arrayDimFetchLoopTypes[] = $scopeWithIterableValueType->getType($stmt->valueVar);
1369-
}
1370-
$arrayDimFetchLoopType = TypeCombinator::union(...$arrayDimFetchLoopTypes);
1371-
1372-
$arrayDimFetchLoopNativeTypes = [];
1373-
foreach ($scopesWithIterableValueType as $scopeWithIterableValueType) {
1374-
$arrayDimFetchLoopNativeTypes[] = $scopeWithIterableValueType->getNativeType($stmt->valueVar);
1375-
}
1376-
$arrayDimFetchLoopNativeType = TypeCombinator::union(...$arrayDimFetchLoopNativeTypes);
1377-
1378-
$valueTypeChanged = !$arrayDimFetchLoopType->equals($exprType->getIterableValueType());
1379-
} elseif ($stmt->keyVar !== null) {
1365+
if ($stmt->keyVar !== null) {
13801366
$arrayExprDimFetch = new ArrayDimFetch($stmt->expr, $stmt->keyVar);
13811367
$originalValueExpr = null;
13821368
if ($stmt->valueVar instanceof Variable && is_string($stmt->valueVar->name)) {
@@ -1424,6 +1410,20 @@ public function processStmtNode(
14241410

14251411
$valueTypeChanged = !$arrayDimFetchLoopType->equals($exprType->getIterableValueType());
14261412
$keyTypeChanged = !$keyLoopType->equals($exprType->getIterableKeyType());
1413+
} elseif ($byRefWithoutKey) {
1414+
$arrayDimFetchLoopTypes = [];
1415+
foreach ($scopesWithIterableValueType as $scopeWithIterableValueType) {
1416+
$arrayDimFetchLoopTypes[] = $scopeWithIterableValueType->getType($stmt->valueVar);
1417+
}
1418+
$arrayDimFetchLoopType = TypeCombinator::union(...$arrayDimFetchLoopTypes);
1419+
1420+
$arrayDimFetchLoopNativeTypes = [];
1421+
foreach ($scopesWithIterableValueType as $scopeWithIterableValueType) {
1422+
$arrayDimFetchLoopNativeTypes[] = $scopeWithIterableValueType->getNativeType($stmt->valueVar);
1423+
}
1424+
$arrayDimFetchLoopNativeType = TypeCombinator::union(...$arrayDimFetchLoopNativeTypes);
1425+
1426+
$valueTypeChanged = !$arrayDimFetchLoopType->equals($exprType->getIterableValueType());
14271427
}
14281428

14291429
if ($valueTypeChanged || $keyTypeChanged) {

0 commit comments

Comments
 (0)