8
8
use PHPStan \Reflection \ParametersAcceptorSelector ;
9
9
use PHPStan \ShouldNotHappenException ;
10
10
use PHPStan \Type \ArrayType ;
11
+ use PHPStan \Type \BooleanType ;
11
12
use PHPStan \Type \DynamicMethodReturnTypeExtension ;
13
+ use PHPStan \Type \FloatType ;
14
+ use PHPStan \Type \IntegerType ;
12
15
use PHPStan \Type \MixedType ;
13
16
use PHPStan \Type \NullType ;
14
17
use PHPStan \Type \StringType ;
15
18
use PHPStan \Type \Type ;
19
+ use PHPStan \Type \TypeCombinator ;
16
20
use PHPStan \Type \UnionType ;
17
21
18
22
final class InputBagDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension
@@ -54,10 +58,8 @@ private function getGetTypeFromMethodCall(
54
58
if (isset ($ methodCall ->args [1 ])) {
55
59
$ argType = $ scope ->getType ($ methodCall ->args [1 ]->value );
56
60
$ isNull = (new NullType ())->isSuperTypeOf ($ argType );
57
- $ isString = (new StringType ())->isSuperTypeOf ($ argType );
58
- $ compare = $ isNull ->compareTo ($ isString );
59
- if ($ compare === $ isString ) {
60
- return new StringType ();
61
+ if ($ isNull ->no ()) {
62
+ return TypeCombinator::removeNull (ParametersAcceptorSelector::selectSingle ($ methodReflection ->getVariants ())->getReturnType ());
61
63
}
62
64
}
63
65
@@ -68,11 +70,18 @@ private function getAllTypeFromMethodCall(
68
70
MethodCall $ methodCall
69
71
): Type
70
72
{
73
+ $ types = [
74
+ new BooleanType (),
75
+ new FloatType (),
76
+ new IntegerType (),
77
+ new StringType (),
78
+ ];
79
+ $ oneParameterType = new UnionType ($ types );
71
80
if (isset ($ methodCall ->args [0 ])) {
72
- return new ArrayType (new MixedType (), new StringType () );
81
+ return new ArrayType (new MixedType (), $ oneParameterType );
73
82
}
74
83
75
- return new ArrayType (new StringType (), new UnionType ([new StringType ( ), new ArrayType ( new MixedType (), new StringType () )]));
84
+ return new ArrayType (new StringType (), new UnionType ([new ArrayType ( new MixedType ( ), $ oneParameterType ), new BooleanType (), new FloatType (), new IntegerType (), new StringType ( )]));
76
85
}
77
86
78
87
}
0 commit comments