Skip to content

Commit 5fa3879

Browse files
authored
Merge branch refs/heads/1.9.x into 1.10.x
2 parents 3541382 + 224751c commit 5fa3879

File tree

1 file changed

+15
-21
lines changed

1 file changed

+15
-21
lines changed

src/Type/Php/FilterFunctionReturnTypeHelper.php

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function getTypeFromFunctionCall(Type $inputType, ?Type $filterType, ?Typ
7878

7979
$exactType = $this->determineExactType($inputType, $filterValue, $defaultType, $flagsType);
8080
$type = $exactType ?? $this->getFilterTypeMap()[$filterValue] ?? $mixedType;
81-
$otherTypes = $this->getOtherTypes($flagsType, $options);
81+
$type = $this->applyRangeOptions($type, $options, $defaultType);
8282

8383
if ($inputType->isNonEmptyString()->yes()
8484
&& $type->isString()->yes()
@@ -90,16 +90,6 @@ public function getTypeFromFunctionCall(Type $inputType, ?Type $filterType, ?Typ
9090
$type = TypeCombinator::intersect($type, $accessory);
9191
}
9292

93-
if (isset($otherTypes['range'])) {
94-
if ($type instanceof ConstantScalarType) {
95-
if ($otherTypes['range']->isSuperTypeOf($type)->no()) {
96-
$type = $defaultType;
97-
}
98-
} else {
99-
$type = $otherTypes['range'];
100-
}
101-
}
102-
10393
if ($exactType === null || $hasOptions->maybe() || (!$inputType->equals($type) && $inputType->isSuperTypeOf($type)->yes())) {
10494
if ($defaultType->isSuperTypeOf($type)->no()) {
10595
$type = TypeCombinator::union($type, $defaultType);
@@ -246,17 +236,13 @@ private function determineExactType(Type $in, int $filterValue, Type $defaultTyp
246236
return null;
247237
}
248238

249-
/**
250-
* @param array<string, ?Type> $typeOptions
251-
* @return array{range?: Type}
252-
*/
253-
private function getOtherTypes(?Type $flagsType, array $typeOptions): array
239+
/** @param array<string, ?Type> $typeOptions */
240+
private function applyRangeOptions(Type $type, array $typeOptions, Type $defaultType): Type
254241
{
255-
if ($flagsType === null) {
256-
return [];
242+
if (!$type->isInteger()->yes()) {
243+
return $type;
257244
}
258245

259-
$otherTypes = [];
260246
$range = [];
261247
if (isset($typeOptions['min_range'])) {
262248
if ($typeOptions['min_range'] instanceof ConstantScalarType) {
@@ -276,10 +262,18 @@ private function getOtherTypes(?Type $flagsType, array $typeOptions): array
276262
if (isset($range['min']) || isset($range['max'])) {
277263
$min = isset($range['min']) && is_int($range['min']) ? $range['min'] : null;
278264
$max = isset($range['max']) && is_int($range['max']) ? $range['max'] : null;
279-
$otherTypes['range'] = IntegerRangeType::fromInterval($min, $max);
265+
$rangeType = IntegerRangeType::fromInterval($min, $max);
266+
267+
if (!($type instanceof ConstantScalarType)) {
268+
return $rangeType;
269+
}
270+
271+
if ($rangeType->isSuperTypeOf($type)->no()) {
272+
return $defaultType;
273+
}
280274
}
281275

282-
return $otherTypes;
276+
return $type;
283277
}
284278

285279
private function hasOptions(Type $flagsType): TrinaryLogic

0 commit comments

Comments
 (0)