@@ -65,20 +65,20 @@ public function getTypeFromFunctionCall(Type $inputType, ?Type $filterType, ?Typ
65
65
$ flagsType = new ConstantIntegerType (0 );
66
66
}
67
67
68
- $ defaultType = $ this ->hasFlag ($ this ->getConstant ('FILTER_NULL_ON_FAILURE ' ), $ flagsType )
68
+ $ hasOptions = $ this ->hasOptions ($ flagsType );
69
+ $ options = $ hasOptions ->yes () ? $ this ->getOptions ($ flagsType , $ filterValue ) : [];
70
+
71
+ $ defaultType = $ options ['default ' ] ?? ($ this ->hasFlag ($ this ->getConstant ('FILTER_NULL_ON_FAILURE ' ), $ flagsType )
69
72
? new NullType ()
70
- : new ConstantBooleanType (false );
73
+ : new ConstantBooleanType (false )) ;
71
74
72
75
if ($ inputType ->isScalar ()->no () && $ inputType ->isNull ()->no ()) {
73
76
return $ defaultType ;
74
77
}
75
78
76
79
$ exactType = $ this ->determineExactType ($ inputType , $ filterValue , $ defaultType , $ flagsType );
77
80
$ type = $ exactType ?? $ this ->getFilterTypeMap ()[$ filterValue ] ?? $ mixedType ;
78
-
79
- $ hasOptions = $ this ->hasOptions ($ flagsType );
80
- $ options = $ hasOptions ->yes () ? $ this ->getOptions ($ flagsType , $ filterValue ) : [];
81
- $ otherTypes = $ this ->getOtherTypes ($ flagsType , $ options , $ defaultType );
81
+ $ otherTypes = $ this ->getOtherTypes ($ flagsType , $ options );
82
82
83
83
if ($ inputType ->isNonEmptyString ()->yes ()
84
84
&& $ type ->isString ()->yes ()
@@ -93,21 +93,17 @@ public function getTypeFromFunctionCall(Type $inputType, ?Type $filterType, ?Typ
93
93
if (isset ($ otherTypes ['range ' ])) {
94
94
if ($ type instanceof ConstantScalarType) {
95
95
if ($ otherTypes ['range ' ]->isSuperTypeOf ($ type )->no ()) {
96
- $ type = $ otherTypes [ ' default ' ] ;
96
+ $ type = $ defaultType ;
97
97
}
98
-
99
- unset($ otherTypes ['default ' ]);
100
98
} else {
101
99
$ type = $ otherTypes ['range ' ];
102
100
}
103
101
}
104
102
105
- if ($ exactType !== null && !$ hasOptions ->maybe () && ($ inputType ->equals ($ type ) || !$ inputType ->isSuperTypeOf ($ type )->yes ())) {
106
- unset($ otherTypes ['default ' ]);
107
- }
108
-
109
- if (isset ($ otherTypes ['default ' ]) && $ otherTypes ['default ' ]->isSuperTypeOf ($ type )->no ()) {
110
- $ type = TypeCombinator::union ($ type , $ otherTypes ['default ' ]);
103
+ if ($ exactType === null || $ hasOptions ->maybe () || (!$ inputType ->equals ($ type ) && $ inputType ->isSuperTypeOf ($ type )->yes ())) {
104
+ if ($ defaultType ->isSuperTypeOf ($ type )->no ()) {
105
+ $ type = TypeCombinator::union ($ type , $ defaultType );
106
+ }
111
107
}
112
108
113
109
if ($ this ->hasFlag ($ this ->getConstant ('FILTER_FORCE_ARRAY ' ), $ flagsType )) {
@@ -252,17 +248,15 @@ private function determineExactType(Type $in, int $filterValue, Type $defaultTyp
252
248
253
249
/**
254
250
* @param array<string, ?Type> $typeOptions
255
- * @return array{default: Type, range?: Type}
251
+ * @return array{range?: Type}
256
252
*/
257
- private function getOtherTypes (?Type $ flagsType , array $ typeOptions, Type $ defaultType ): array
253
+ private function getOtherTypes (?Type $ flagsType , array $ typeOptions ): array
258
254
{
259
- $ falseType = new ConstantBooleanType (false );
260
255
if ($ flagsType === null ) {
261
- return [' default ' => $ falseType ];
256
+ return [];
262
257
}
263
258
264
- $ defaultType = $ typeOptions ['default ' ] ?? $ defaultType ;
265
- $ otherTypes = ['default ' => $ defaultType ];
259
+ $ otherTypes = [];
266
260
$ range = [];
267
261
if (isset ($ typeOptions ['min_range ' ])) {
268
262
if ($ typeOptions ['min_range ' ] instanceof ConstantScalarType) {
0 commit comments