@@ -65,20 +65,20 @@ public function getTypeFromFunctionCall(Type $inputType, ?Type $filterType, ?Typ
6565 $ flagsType = new ConstantIntegerType (0 );
6666 }
6767
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 )
6972 ? new NullType ()
70- : new ConstantBooleanType (false );
73+ : new ConstantBooleanType (false )) ;
7174
7275 if ($ inputType ->isScalar ()->no () && $ inputType ->isNull ()->no ()) {
7376 return $ defaultType ;
7477 }
7578
7679 $ exactType = $ this ->determineExactType ($ inputType , $ filterValue , $ defaultType , $ flagsType );
7780 $ 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 );
8282
8383 if ($ inputType ->isNonEmptyString ()->yes ()
8484 && $ type ->isString ()->yes ()
@@ -93,21 +93,17 @@ public function getTypeFromFunctionCall(Type $inputType, ?Type $filterType, ?Typ
9393 if (isset ($ otherTypes ['range ' ])) {
9494 if ($ type instanceof ConstantScalarType) {
9595 if ($ otherTypes ['range ' ]->isSuperTypeOf ($ type )->no ()) {
96- $ type = $ otherTypes [ ' default ' ] ;
96+ $ type = $ defaultType ;
9797 }
98-
99- unset($ otherTypes ['default ' ]);
10098 } else {
10199 $ type = $ otherTypes ['range ' ];
102100 }
103101 }
104102
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+ }
111107 }
112108
113109 if ($ this ->hasFlag ($ this ->getConstant ('FILTER_FORCE_ARRAY ' ), $ flagsType )) {
@@ -252,17 +248,15 @@ private function determineExactType(Type $in, int $filterValue, Type $defaultTyp
252248
253249 /**
254250 * @param array<string, ?Type> $typeOptions
255- * @return array{default: Type, range?: Type}
251+ * @return array{range?: Type}
256252 */
257- private function getOtherTypes (?Type $ flagsType , array $ typeOptions, Type $ defaultType ): array
253+ private function getOtherTypes (?Type $ flagsType , array $ typeOptions ): array
258254 {
259- $ falseType = new ConstantBooleanType (false );
260255 if ($ flagsType === null ) {
261- return [' default ' => $ falseType ];
256+ return [];
262257 }
263258
264- $ defaultType = $ typeOptions ['default ' ] ?? $ defaultType ;
265- $ otherTypes = ['default ' => $ defaultType ];
259+ $ otherTypes = [];
266260 $ range = [];
267261 if (isset ($ typeOptions ['min_range ' ])) {
268262 if ($ typeOptions ['min_range ' ] instanceof ConstantScalarType) {
0 commit comments