Skip to content

Commit b18deb5

Browse files
phpstan-botclaude
andcommitted
Refactor: use single TypeCombinator::intersect call for performance
Instead of incrementally intersecting types in a loop, collect all inner value types and pass them to a single TypeCombinator::intersect() call. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent e66e5fb commit b18deb5

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

src/Type/Php/InArrayFunctionTypeSpecifyingExtension.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,17 +121,12 @@ public function specifyTypes(FunctionReflection $functionReflection, FuncCall $n
121121
// array{A}|array{B}, getIterableValueType() returns A|B but neither
122122
// value is guaranteed to be in every variant.
123123
$innerTypes = $arrayType instanceof UnionType ? $arrayType->getTypes() : [$arrayType];
124-
$guaranteedValueType = null;
124+
$innerValueTypes = [];
125125
foreach ($innerTypes as $innerType) {
126-
$innerValueType = $innerType->getIterableValueType();
127-
if ($guaranteedValueType === null) {
128-
$guaranteedValueType = $innerValueType;
129-
} else {
130-
$guaranteedValueType = TypeCombinator::intersect($guaranteedValueType, $innerValueType);
131-
}
126+
$innerValueTypes[] = $innerType->getIterableValueType();
132127
}
133-
if ($guaranteedValueType !== null) {
134-
$narrowingValueType = $guaranteedValueType;
128+
if (count($innerValueTypes) > 0) {
129+
$narrowingValueType = TypeCombinator::intersect(...$innerValueTypes);
135130
}
136131
}
137132
if (

0 commit comments

Comments
 (0)