@@ -78,7 +78,7 @@ public function getTypeFromFunctionCall(Type $inputType, ?Type $filterType, ?Typ
78
78
79
79
$ exactType = $ this ->determineExactType ($ inputType , $ filterValue , $ defaultType , $ flagsType );
80
80
$ type = $ exactType ?? $ this ->getFilterTypeMap ()[$ filterValue ] ?? $ mixedType ;
81
- $ otherTypes = $ this ->getOtherTypes ( $ flagsType , $ options );
81
+ $ type = $ this ->applyRangeOptions ( $ type , $ options, $ defaultType );
82
82
83
83
if ($ inputType ->isNonEmptyString ()->yes ()
84
84
&& $ type ->isString ()->yes ()
@@ -90,16 +90,6 @@ public function getTypeFromFunctionCall(Type $inputType, ?Type $filterType, ?Typ
90
90
$ type = TypeCombinator::intersect ($ type , $ accessory );
91
91
}
92
92
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
-
103
93
if ($ exactType === null || $ hasOptions ->maybe () || (!$ inputType ->equals ($ type ) && $ inputType ->isSuperTypeOf ($ type )->yes ())) {
104
94
if ($ defaultType ->isSuperTypeOf ($ type )->no ()) {
105
95
$ type = TypeCombinator::union ($ type , $ defaultType );
@@ -246,17 +236,13 @@ private function determineExactType(Type $in, int $filterValue, Type $defaultTyp
246
236
return null ;
247
237
}
248
238
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
254
241
{
255
- if ($ flagsType === null ) {
256
- return [] ;
242
+ if (! $ type -> isInteger ()-> yes () ) {
243
+ return $ type ;
257
244
}
258
245
259
- $ otherTypes = [];
260
246
$ range = [];
261
247
if (isset ($ typeOptions ['min_range ' ])) {
262
248
if ($ typeOptions ['min_range ' ] instanceof ConstantScalarType) {
@@ -276,10 +262,18 @@ private function getOtherTypes(?Type $flagsType, array $typeOptions): array
276
262
if (isset ($ range ['min ' ]) || isset ($ range ['max ' ])) {
277
263
$ min = isset ($ range ['min ' ]) && is_int ($ range ['min ' ]) ? $ range ['min ' ] : null ;
278
264
$ 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
+ }
280
274
}
281
275
282
- return $ otherTypes ;
276
+ return $ type ;
283
277
}
284
278
285
279
private function hasOptions (Type $ flagsType ): TrinaryLogic
0 commit comments