1212use PHPStan \Type \BitwiseFlagHelper ;
1313use PHPStan \Type \Constant \ConstantBooleanType ;
1414use PHPStan \Type \Constant \ConstantStringType ;
15- use PHPStan \Type \ConstantScalarType ;
1615use PHPStan \Type \ConstantTypeHelper ;
1716use PHPStan \Type \DynamicFunctionReturnTypeExtension ;
1817use PHPStan \Type \ObjectWithoutClassType ;
1918use PHPStan \Type \Type ;
2019use PHPStan \Type \TypeCombinator ;
20+ use function count ;
2121use function is_bool ;
2222use function json_decode ;
2323
@@ -87,8 +87,14 @@ private function narrowTypeForJsonDecode(FuncCall $funcCall, Scope $scope, Type
8787 }
8888
8989 $ firstValueType = $ scope ->getType ($ args [0 ]->value );
90- if ($ firstValueType instanceof ConstantStringType) {
91- return $ this ->resolveConstantStringType ($ firstValueType , $ isForceArray );
90+ if ($ firstValueType ->getConstantStrings () !== []) {
91+ $ types = [];
92+
93+ foreach ($ firstValueType ->getConstantStrings () as $ constantString ) {
94+ $ types [] = $ this ->resolveConstantStringType ($ constantString , $ isForceArray );
95+ }
96+
97+ return TypeCombinator::union (...$ types );
9298 }
9399
94100 if ($ isForceArray ) {
@@ -109,7 +115,7 @@ private function isForceArray(FuncCall $funcCall, Scope $scope): bool
109115 }
110116
111117 $ secondArgType = $ scope ->getType ($ args [1 ]->value );
112- $ secondArgValue = $ secondArgType instanceof ConstantScalarType ? $ secondArgType ->getValue () : null ;
118+ $ secondArgValue = count ( $ secondArgType-> getConstantScalarValues ()) === 1 ? $ secondArgType ->getConstantScalarValues ()[ 0 ] : null ;
113119
114120 if (is_bool ($ secondArgValue )) {
115121 return $ secondArgValue ;
0 commit comments