Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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 <[email protected]>
  • Loading branch information
2 people authored and staabm committed Apr 1, 2026
commit 2692dabd86c4e02727f733ee2ed0b2b47c38cbe4
13 changes: 4 additions & 9 deletions src/Type/Php/InArrayFunctionTypeSpecifyingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,12 @@ public function specifyTypes(FunctionReflection $functionReflection, FuncCall $n
// array{A}|array{B}, getIterableValueType() returns A|B but neither
// value is guaranteed to be in every variant.
$innerTypes = $arrayType instanceof UnionType ? $arrayType->getTypes() : [$arrayType];
$guaranteedValueType = null;
$innerValueTypes = [];
foreach ($innerTypes as $innerType) {
$innerValueType = $innerType->getIterableValueType();
if ($guaranteedValueType === null) {
$guaranteedValueType = $innerValueType;
} else {
$guaranteedValueType = TypeCombinator::intersect($guaranteedValueType, $innerValueType);
}
$innerValueTypes[] = $innerType->getIterableValueType();
}
if ($guaranteedValueType !== null) {
$narrowingValueType = $guaranteedValueType;
if (count($innerValueTypes) > 0) {
$narrowingValueType = TypeCombinator::intersect(...$innerValueTypes);
}
}
if (
Expand Down