77use PHPStan \Analyser \Scope ;
88use PHPStan \Collectors \Collector ;
99use PHPStan \Reflection \ReflectionProvider ;
10+ use ShipMonk \PHPStan \DeadCode \Enum \MemberType ;
1011use ShipMonk \PHPStan \DeadCode \Excluder \MemberUsageExcluder ;
1112use ShipMonk \PHPStan \DeadCode \Graph \ClassMemberUsage ;
1213use ShipMonk \PHPStan \DeadCode \Graph \CollectedUsage ;
@@ -85,7 +86,7 @@ private function validateUsage(
8586 {
8687 $ origin = $ usage ->getOrigin ();
8788 $ originClass = $ origin ->getClassName ();
88- $ originMethod = $ origin ->getMemberName ();
89+ $ originMember = $ origin ->getMemberName ();
8990
9091 $ context = sprintf (
9192 "It emitted usage of %s by %s for node '%s' in '%s' on line %s " ,
@@ -101,8 +102,14 @@ private function validateUsage(
101102 throw new LogicException ("Class ' {$ originClass }' does not exist. $ context " );
102103 }
103104
104- if ($ originMethod !== null && !$ this ->reflectionProvider ->getClass ($ originClass )->hasMethod ($ originMethod )) {
105- throw new LogicException ("Method ' {$ originMethod }' does not exist in class ' $ originClass'. $ context " );
105+ if ($ originMember !== null ) {
106+ if ($ origin ->getMemberType () === MemberType::METHOD && !$ this ->reflectionProvider ->getClass ($ originClass )->hasMethod ($ originMember )) {
107+ throw new LogicException ("Method ' {$ originMember }' does not exist in class ' $ originClass'. $ context " );
108+ }
109+
110+ if ($ origin ->getMemberType () === MemberType::PROPERTY && !$ this ->reflectionProvider ->getClass ($ originClass )->hasNativeProperty ($ originMember )) {
111+ throw new LogicException ("Property ' {$ originMember }' does not exist in class ' $ originClass'. $ context " );
112+ }
106113 }
107114 }
108115 }
0 commit comments