88use PHPStan \Reflection \ParametersAcceptorSelector ;
99use PHPStan \ShouldNotHappenException ;
1010use PHPStan \Type \ArrayType ;
11+ use PHPStan \Type \BooleanType ;
1112use PHPStan \Type \DynamicMethodReturnTypeExtension ;
13+ use PHPStan \Type \FloatType ;
14+ use PHPStan \Type \IntegerType ;
1215use PHPStan \Type \MixedType ;
1316use PHPStan \Type \NullType ;
1417use PHPStan \Type \StringType ;
1518use PHPStan \Type \Type ;
19+ use PHPStan \Type \TypeCombinator ;
1620use PHPStan \Type \UnionType ;
1721
1822final class InputBagDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension
@@ -54,10 +58,8 @@ private function getGetTypeFromMethodCall(
5458 if (isset ($ methodCall ->args [1 ])) {
5559 $ argType = $ scope ->getType ($ methodCall ->args [1 ]->value );
5660 $ 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 ());
6163 }
6264 }
6365
@@ -68,11 +70,18 @@ private function getAllTypeFromMethodCall(
6870 MethodCall $ methodCall
6971 ): Type
7072 {
73+ $ types = [
74+ new BooleanType (),
75+ new FloatType (),
76+ new IntegerType (),
77+ new StringType (),
78+ ];
79+ $ oneParameterType = new UnionType ($ types );
7180 if (isset ($ methodCall ->args [0 ])) {
72- return new ArrayType (new MixedType (), new StringType () );
81+ return new ArrayType (new MixedType (), $ oneParameterType );
7382 }
7483
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 ( )]));
7685 }
7786
7887}
0 commit comments