@@ -40,25 +40,40 @@ protected function getErrorOrNull(
4040 string $ class ,
4141 string $ methodName ,
4242 ): ?RuleError {
43+ $ callingClass = $ scope ->getClassReflection ()?->getName();
44+
4345 $ classReflection = $ this ->reflectionProvider ->getClass ($ class );
4446 $ className = $ classReflection ->getName ();
4547 $ nativeReflection = $ classReflection ->getNativeReflection ();
4648
4749 $ fullMethodName = "{$ className }:: {$ methodName }" ;
4850
51+ if ($ this ->cache ->hasEntry ($ className )) {
52+ $ isTestTagOnClass = $ this ->cache ->getEntry ($ className );
53+ } else {
54+ $ isTestTagOnClass = count ($ nativeReflection ->getAttributes (TestTag::class)) > 0 ;
55+ $ this ->cache ->addEntry ($ className , $ isTestTagOnClass );
56+ }
57+
4958 if ($ this ->cache ->hasEntry ($ fullMethodName )) {
50- $ isTestTag = $ this ->cache ->getEntry ($ fullMethodName );
59+ $ isTestTagOnMethod = $ this ->cache ->getEntry ($ fullMethodName );
5160 } else {
5261 if ($ nativeReflection ->hasMethod ($ methodName )) {
5362 $ methodReflection = $ nativeReflection ->getMethod ($ methodName );
54- $ isTestTag = count ($ methodReflection ->getAttributes (TestTag::class)) > 0 ;
63+ $ isTestTagOnMethod = count ($ methodReflection ->getAttributes (TestTag::class)) > 0 ;
5564 } else {
56- $ isTestTag = false ;
65+ $ isTestTagOnMethod = false ;
5766 }
58- $ this ->cache ->addEntry ($ fullMethodName , $ isTestTag );
67+ $ this ->cache ->addEntry ($ fullMethodName , $ isTestTagOnMethod );
68+ }
69+
70+ $ hasTestTag = $ isTestTagOnClass || $ isTestTagOnMethod ;
71+
72+ if (!$ hasTestTag ) {
73+ return null ;
5974 }
6075
61- if (! $ isTestTag ) {
76+ if ($ isTestTagOnClass && ( $ className === $ callingClass ) ) {
6277 return null ;
6378 }
6479
0 commit comments