Skip to content

Commit a94df70

Browse files
phpstan-botclaude
authored andcommitted
Only count HasOffsetValueType accessories for complexity limit
Instead of counting all union type members, only count union members that contain HasOffsetValueType accessories. This more precisely targets the source of exponential growth while avoiding false positives on unions that are large for other reasons. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5f328aa commit a94df70

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

src/Analyser/MutatingScope.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2700,7 +2700,18 @@ public function specifyExpressionType(Expr $expr, Type $type, Type $nativeType,
27002700
}
27012701
}
27022702

2703-
$tooComplex = $exprVarType instanceof UnionType && count($exprVarType->getTypes()) > self::ARRAY_DIM_FETCH_UNION_TYPE_LIMIT;
2703+
$hasOffsetAccessoryCount = 0;
2704+
if ($exprVarType instanceof UnionType) {
2705+
foreach ($exprVarType->getTypes() as $innerType) {
2706+
foreach (TypeUtils::getAccessoryTypes($innerType) as $accessoryType) {
2707+
if ($accessoryType instanceof HasOffsetValueType) {
2708+
$hasOffsetAccessoryCount++;
2709+
break;
2710+
}
2711+
}
2712+
}
2713+
}
2714+
$tooComplex = $hasOffsetAccessoryCount > self::ARRAY_DIM_FETCH_UNION_TYPE_LIMIT;
27042715
if (!$tooComplex && ($dimType instanceof ConstantIntegerType || $dimType instanceof ConstantStringType)) {
27052716
$varType = TypeCombinator::intersect(
27062717
$varType,

0 commit comments

Comments
 (0)