77use PHPStan \Reflection \MethodReflection ;
88use PHPStan \Type \DynamicMethodReturnTypeExtension ;
99use PHPStan \Type \Generic \GenericObjectType ;
10- use PHPStan \Type \IntersectionType ;
1110use PHPStan \Type \ObjectType ;
1211use PHPStan \Type \Type ;
1312use PHPUnit \Framework \MockObject \Builder \InvocationMocker ;
@@ -32,24 +31,15 @@ public function isMethodSupported(MethodReflection $methodReflection): bool
3231 public function getTypeFromMethodCall (MethodReflection $ methodReflection , MethodCall $ methodCall , Scope $ scope ): Type
3332 {
3433 $ type = $ scope ->getType ($ methodCall ->var );
35- if (!($ type instanceof IntersectionType)) {
36- return new ObjectType (InvocationMocker::class);
37- }
38-
39- $ mockClasses = array_values (array_filter ($ type ->getTypes (), static function (Type $ type ): bool {
40- $ classNames = $ type ->getObjectClassNames ();
41- if (count ($ classNames ) !== 1 ) {
42- return true ;
43- }
44-
45- return $ classNames [0 ] !== MockObject::class;
34+ $ mockClasses = array_values (array_filter ($ type ->getObjectClassNames (), static function (string $ class ): bool {
35+ return $ class !== MockObject::class;
4636 }));
4737
4838 if (count ($ mockClasses ) !== 1 ) {
4939 return new ObjectType (InvocationMocker::class);
5040 }
5141
52- return new GenericObjectType (InvocationMocker::class, $ mockClasses );
42+ return new GenericObjectType (InvocationMocker::class, [ new ObjectType ( $ mockClasses[ 0 ])] );
5343 }
5444
5545}
0 commit comments