@@ -48,7 +48,7 @@ public function processNode(Node $node, Scope $scope): array
4848 $ method = $ constantString ->getValue ();
4949 $ type = $ scope ->getType ($ node ->var );
5050
51- $ error = $ this ->checkCallOnType ($ type , $ method );
51+ $ error = $ this ->checkCallOnType ($ scope , $ type , $ method );
5252 if ($ error !== null ) {
5353 $ errors [] = $ error ;
5454 continue ;
@@ -67,7 +67,7 @@ public function processNode(Node $node, Scope $scope): array
6767 }
6868
6969 $ varType = $ scope ->getType ($ node ->var ->var );
70- $ error = $ this ->checkCallOnType ($ varType , $ method );
70+ $ error = $ this ->checkCallOnType ($ scope , $ varType , $ method );
7171 if ($ error === null ) {
7272 continue ;
7373 }
@@ -78,14 +78,16 @@ public function processNode(Node $node, Scope $scope): array
7878 return $ errors ;
7979 }
8080
81- private function checkCallOnType (Type $ type , string $ method ): ?IdentifierRuleError
81+ private function checkCallOnType (Scope $ scope , Type $ type , string $ method ): ?IdentifierRuleError
8282 {
83+ $ methodReflection = $ scope ->getMethodReflection ($ type , $ method );
84+ if ($ methodReflection !== null ) {
85+ return null ;
86+ }
87+
8388 if (
84- (
85- in_array (MockObject::class, $ type ->getObjectClassNames (), true )
86- || in_array (Stub::class, $ type ->getObjectClassNames (), true )
87- )
88- && !$ type ->hasMethod ($ method )->yes ()
89+ in_array (MockObject::class, $ type ->getObjectClassNames (), true )
90+ || in_array (Stub::class, $ type ->getObjectClassNames (), true )
8991 ) {
9092 $ mockClasses = array_filter ($ type ->getObjectClassNames (), static fn (string $ class ): bool => $ class !== MockObject::class && $ class !== Stub::class);
9193 if (count ($ mockClasses ) === 0 ) {
0 commit comments