1010use PHPStan \Analyser \TypeSpecifierContext ;
1111use PHPStan \DependencyInjection \AutowiredService ;
1212use PHPStan \Reflection \FunctionReflection ;
13+ use PHPStan \Type \Constant \ConstantStringType ;
1314use PHPStan \Type \ErrorType ;
1415use PHPStan \Type \FunctionTypeSpecifyingExtension ;
1516use PHPStan \Type \NullType ;
1617use PHPStan \Type \ObjectType ;
18+ use PHPStan \Type \ObjectWithoutClassType ;
1719use PHPStan \Type \TypeCombinator ;
1820use stdClass ;
1921use function count ;
@@ -41,7 +43,15 @@ public function specifyTypes(FunctionReflection $functionReflection, FuncCall $n
4143
4244 $ constantStrings = $ castType ->getConstantStrings ();
4345 if (count ($ constantStrings ) < 1 ) {
44- return new SpecifiedTypes ();
46+ $ constantStrings = [
47+ new ConstantStringType ('bool ' ),
48+ new ConstantStringType ('int ' ),
49+ new ConstantStringType ('float ' ),
50+ new ConstantStringType ('string ' ),
51+ new ConstantStringType ('array ' ),
52+ new ConstantStringType ('object ' ),
53+ new ConstantStringType ('null ' ),
54+ ];
4555 }
4656
4757 $ types = [];
@@ -67,7 +77,17 @@ public function specifyTypes(FunctionReflection $functionReflection, FuncCall $n
6777 $ types [] = $ valueType ->toArray ();
6878 break ;
6979 case 'object ' :
70- $ types [] = new ObjectType (stdClass::class);
80+ $ isObject = $ valueType ->isObject ();
81+ if ($ isObject ->yes ()) {
82+ $ types [] = $ valueType ;
83+ } elseif ($ isObject ->no ()) {
84+ $ types [] = new ObjectType (stdClass::class);
85+ } else {
86+ $ types [] = TypeCombinator::union (
87+ TypeCombinator::intersect ($ valueType , new ObjectWithoutClassType ()),
88+ new ObjectType (stdClass::class),
89+ );
90+ }
7191 break ;
7292 case 'null ' :
7393 $ types [] = new NullType ();
0 commit comments