14
14
use PHPStan \Type \ConstantScalarType ;
15
15
use PHPStan \Type \ConstantTypeHelper ;
16
16
use PHPStan \Type \DynamicFunctionReturnTypeExtension ;
17
- use PHPStan \Type \ObjectType ;
17
+ use PHPStan \Type \ObjectWithoutClassType ;
18
18
use PHPStan \Type \Type ;
19
19
use PHPStan \Type \TypeCombinator ;
20
- use stdClass ;
21
20
use function is_bool ;
22
21
use function json_decode ;
23
22
@@ -76,18 +75,18 @@ public function getTypeFromFunctionCall(
76
75
private function narrowTypeForJsonDecode (FuncCall $ funcCall , Scope $ scope , Type $ fallbackType ): Type
77
76
{
78
77
$ args = $ funcCall ->getArgs ();
79
- $ isArrayWithoutStdClass = $ this ->isForceArrayWithoutStdClass ($ funcCall , $ scope );
78
+ $ isForceArray = $ this ->isForceArray ($ funcCall , $ scope );
80
79
if (!isset ($ args [0 ])) {
81
80
return $ fallbackType ;
82
81
}
83
82
84
83
$ firstValueType = $ scope ->getType ($ args [0 ]->value );
85
84
if ($ firstValueType instanceof ConstantStringType) {
86
- return $ this ->resolveConstantStringType ($ firstValueType , $ isArrayWithoutStdClass );
85
+ return $ this ->resolveConstantStringType ($ firstValueType , $ isForceArray );
87
86
}
88
87
89
- if ($ isArrayWithoutStdClass ) {
90
- return TypeCombinator::remove ($ fallbackType , new ObjectType (stdClass::class ));
88
+ if ($ isForceArray ) {
89
+ return TypeCombinator::remove ($ fallbackType , new ObjectWithoutClassType ( ));
91
90
}
92
91
93
92
return $ fallbackType ;
@@ -96,7 +95,7 @@ private function narrowTypeForJsonDecode(FuncCall $funcCall, Scope $scope, Type
96
95
/**
97
96
* Is "json_decode(..., true)"?
98
97
*/
99
- private function isForceArrayWithoutStdClass (FuncCall $ funcCall , Scope $ scope ): bool
98
+ private function isForceArray (FuncCall $ funcCall , Scope $ scope ): bool
100
99
{
101
100
$ args = $ funcCall ->getArgs ();
102
101
if (!isset ($ args [1 ])) {
0 commit comments