12
12
use PHPStan \Type \BitwiseFlagHelper ;
13
13
use PHPStan \Type \Constant \ConstantBooleanType ;
14
14
use PHPStan \Type \Constant \ConstantStringType ;
15
- use PHPStan \Type \ConstantScalarType ;
16
15
use PHPStan \Type \ConstantTypeHelper ;
17
16
use PHPStan \Type \DynamicFunctionReturnTypeExtension ;
18
17
use PHPStan \Type \ObjectWithoutClassType ;
19
18
use PHPStan \Type \Type ;
20
19
use PHPStan \Type \TypeCombinator ;
20
+ use function count ;
21
21
use function is_bool ;
22
22
use function json_decode ;
23
23
@@ -87,8 +87,14 @@ private function narrowTypeForJsonDecode(FuncCall $funcCall, Scope $scope, Type
87
87
}
88
88
89
89
$ 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 );
92
98
}
93
99
94
100
if ($ isForceArray ) {
@@ -109,7 +115,7 @@ private function isForceArray(FuncCall $funcCall, Scope $scope): bool
109
115
}
110
116
111
117
$ secondArgType = $ scope ->getType ($ args [1 ]->value );
112
- $ secondArgValue = $ secondArgType instanceof ConstantScalarType ? $ secondArgType ->getValue () : null ;
118
+ $ secondArgValue = count ( $ secondArgType-> getConstantScalarValues ()) === 1 ? $ secondArgType ->getConstantScalarValues ()[ 0 ] : null ;
113
119
114
120
if (is_bool ($ secondArgValue )) {
115
121
return $ secondArgValue ;
0 commit comments