Skip to content

Commit c5824eb

Browse files
phpstan-botclaude
andcommitted
Rename and simplify isDimFetchPathReachable to absorb nested check
Move the `$assignedExpr->var instanceof ArrayDimFetch` guard into the method itself and rename from isNestedDimFetchPathValid to isDimFetchPathReachable for clarity. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 3200c9f commit c5824eb

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

src/Analyser/MutatingScope.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2597,8 +2597,7 @@ public function assignVariable(string $variableName, Type $type, Type $nativeTyp
25972597
$assignedExpr = $expressionType->getExpr()->getAssignedExpr();
25982598
if (
25992599
$assignedExpr instanceof Expr\ArrayDimFetch
2600-
&& $assignedExpr->var instanceof Expr\ArrayDimFetch
2601-
&& !$this->isNestedDimFetchPathValid($scope, $assignedExpr)
2600+
&& !$this->isDimFetchPathReachable($scope, $assignedExpr)
26022601
) {
26032602
unset($scope->expressionTypes[$exprString]);
26042603
unset($scope->nativeExpressionTypes[$exprString]);
@@ -2634,25 +2633,24 @@ public function assignVariable(string $variableName, Type $type, Type $nativeTyp
26342633
return $scope;
26352634
}
26362635

2637-
private function isNestedDimFetchPathValid(self $scope, Expr\ArrayDimFetch $dimFetch): bool
2636+
private function isDimFetchPathReachable(self $scope, Expr\ArrayDimFetch $dimFetch): bool
26382637
{
2639-
// Check that each intermediate ArrayDimFetch in the chain has the expected offset
26402638
if ($dimFetch->dim === null) {
26412639
return false;
26422640
}
26432641

2642+
if (!$dimFetch->var instanceof Expr\ArrayDimFetch) {
2643+
return true;
2644+
}
2645+
26442646
$varType = $scope->getType($dimFetch->var);
26452647
$dimType = $scope->getType($dimFetch->dim);
26462648

26472649
if (!$varType->hasOffsetValueType($dimType)->yes()) {
26482650
return false;
26492651
}
26502652

2651-
if ($dimFetch->var instanceof Expr\ArrayDimFetch) {
2652-
return $this->isNestedDimFetchPathValid($scope, $dimFetch->var);
2653-
}
2654-
2655-
return true;
2653+
return $this->isDimFetchPathReachable($scope, $dimFetch->var);
26562654
}
26572655

26582656
private function unsetExpression(Expr $expr): self

0 commit comments

Comments
 (0)