@@ -36,14 +36,14 @@ public function getUsages(Node $node, Scope $scope): array
3636 return [];
3737 }
3838
39- protected function shouldMarkMethodAsUsed (ReflectionMethod $ method ): bool
39+ protected function shouldMarkMethodAsUsed (ReflectionMethod $ method ): ? VirtualUsageData
4040 {
41- return false ; // Expected to be overridden by subclasses.
41+ return null ; // Expected to be overridden by subclasses.
4242 }
4343
44- protected function shouldMarkConstantAsUsed (ReflectionClassConstant $ constant ): bool
44+ protected function shouldMarkConstantAsUsed (ReflectionClassConstant $ constant ): ? VirtualUsageData
4545 {
46- return false ; // Expected to be overridden by subclasses.
46+ return null ; // Expected to be overridden by subclasses.
4747 }
4848
4949 /**
@@ -60,8 +60,10 @@ private function getMethodUsages(ClassReflection $classReflection): array
6060 continue ; // skip methods from ancestors
6161 }
6262
63- if ($ this ->shouldMarkMethodAsUsed ($ nativeMethodReflection )) {
64- $ usages [] = $ this ->createMethodUsage ($ nativeMethodReflection );
63+ $ usage = $ this ->shouldMarkMethodAsUsed ($ nativeMethodReflection );
64+
65+ if ($ usage !== null ) {
66+ $ usages [] = $ this ->createMethodUsage ($ nativeMethodReflection , $ usage );
6567 }
6668 }
6769
@@ -82,18 +84,20 @@ private function getConstantUsages(ClassReflection $classReflection): array
8284 continue ; // skip constants from ancestors
8385 }
8486
85- if ($ this ->shouldMarkConstantAsUsed ($ nativeConstantReflection )) {
86- $ usages [] = $ this ->createConstantUsage ($ nativeConstantReflection );
87+ $ usage = $ this ->shouldMarkConstantAsUsed ($ nativeConstantReflection );
88+
89+ if ($ usage !== null ) {
90+ $ usages [] = $ this ->createConstantUsage ($ nativeConstantReflection , $ usage );
8791 }
8892 }
8993
9094 return $ usages ;
9195 }
9296
93- private function createConstantUsage (ReflectionClassConstant $ constantReflection ): ClassConstantUsage
97+ private function createConstantUsage (ReflectionClassConstant $ constantReflection, VirtualUsageData $ data ): ClassConstantUsage
9498 {
9599 return new ClassConstantUsage (
96- UsageOrigin::createVirtual ($ this ),
100+ UsageOrigin::createVirtual ($ this , $ data ),
97101 new ClassConstantRef (
98102 $ constantReflection ->getDeclaringClass ()->getName (),
99103 $ constantReflection ->getName (),
@@ -102,10 +106,10 @@ private function createConstantUsage(ReflectionClassConstant $constantReflection
102106 );
103107 }
104108
105- private function createMethodUsage (ReflectionMethod $ methodReflection ): ClassMethodUsage
109+ private function createMethodUsage (ReflectionMethod $ methodReflection, VirtualUsageData $ data ): ClassMethodUsage
106110 {
107111 return new ClassMethodUsage (
108- UsageOrigin::createVirtual ($ this ),
112+ UsageOrigin::createVirtual ($ this , $ data ),
109113 new ClassMethodRef (
110114 $ methodReflection ->getDeclaringClass ()->getName (),
111115 $ methodReflection ->getName (),
0 commit comments