Skip to content

Commit 6633a95

Browse files
phpstan-botclaude
andcommitted
Refactor: inline computeGuaranteedValueType into computeNeedleNarrowingType
Remove the separate computeGuaranteedValueType method and move its implementation directly into computeNeedleNarrowingType, as suggested in review. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent b78be62 commit 6633a95

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

src/Type/Php/InArrayFunctionTypeSpecifyingExtension.php

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -187,22 +187,6 @@ private function computeNeedleNarrowingType(TypeSpecifierContext $context, Type
187187
return null;
188188
}
189189

190-
$guaranteedValueType = $this->computeGuaranteedValueType($arrayType, $arrayValueType);
191-
192-
if (count($guaranteedValueType->getFiniteTypes()) === 0) {
193-
return null;
194-
}
195-
196-
return $guaranteedValueType;
197-
}
198-
199-
/**
200-
* Computes the type of values guaranteed to be in every possible variant
201-
* of the array. For union types like array{A}|array{B}, we intersect the
202-
* value types so only values present in all variants are used for narrowing.
203-
*/
204-
private function computeGuaranteedValueType(Type $arrayType, Type $arrayValueType): Type
205-
{
206190
$innerTypes = $arrayType instanceof UnionType ? $arrayType->getTypes() : [$arrayType];
207191
$innerValueTypes = [];
208192
foreach ($innerTypes as $innerType) {
@@ -226,9 +210,15 @@ private function computeGuaranteedValueType(Type $arrayType, Type $arrayValueTyp
226210
}
227211
}
228212

229-
return count($innerValueTypes) > 0
213+
$guaranteedValueType = count($innerValueTypes) > 0
230214
? TypeCombinator::intersect(...$innerValueTypes)
231215
: $arrayValueType;
216+
217+
if (count($guaranteedValueType->getFiniteTypes()) === 0) {
218+
return null;
219+
}
220+
221+
return $guaranteedValueType;
232222
}
233223

234224
}

0 commit comments

Comments
 (0)