44
55use DOMDocument ;
66use PhpParser \Node \Expr ;
7+ use PhpParser \Node \Identifier ;
78use PhpParser \Node \Name ;
89use PHPStan \Analyser \NullsafeOperatorHelper ;
910use PHPStan \Analyser \Scope ;
@@ -61,6 +62,7 @@ public function check(
6162 Scope $ scope ,
6263 string $ methodName ,
6364 $ class ,
65+ Identifier |Expr $ astName ,
6466 ): array
6567 {
6668 $ errors = [];
@@ -81,7 +83,9 @@ public function check(
8183 'Calling %s::%s() outside of class scope. ' ,
8284 $ className ,
8385 $ methodName ,
84- ))->identifier (sprintf ('outOfClass.%s ' , $ lowercasedClassName ))->build (),
86+ ))
87+ ->line ($ astName ->getStartLine ())
88+ ->identifier (sprintf ('outOfClass.%s ' , $ lowercasedClassName ))->build (),
8589 ],
8690 null ,
8791 ];
@@ -95,7 +99,10 @@ public function check(
9599 'Calling %s::%s() outside of class scope. ' ,
96100 $ className ,
97101 $ methodName ,
98- ))->identifier (sprintf ('outOfClass.parent ' ))->build (),
102+ ))
103+ ->line ($ astName ->getStartLine ())
104+ ->identifier (sprintf ('outOfClass.parent ' ))
105+ ->build (),
99106 ],
100107 null ,
101108 ];
@@ -110,7 +117,10 @@ public function check(
110117 $ scope ->getFunctionName (),
111118 $ methodName ,
112119 $ scope ->getClassReflection ()->getDisplayName (),
113- ))->identifier ('class.noParent ' )->build (),
120+ ))
121+ ->line ($ astName ->getStartLine ())
122+ ->identifier ('class.noParent ' )
123+ ->build (),
114124 ],
115125 null ,
116126 ];
@@ -132,6 +142,7 @@ public function check(
132142 $ methodName ,
133143 $ className ,
134144 ))
145+ ->line ($ astName ->getStartLine ())
135146 ->identifier ('class.notFound ' );
136147
137148 if ($ this ->discoveringSymbolsTip ) {
@@ -206,7 +217,10 @@ public function check(
206217 'Cannot call static method %s() on %s. ' ,
207218 $ methodName ,
208219 $ typeForDescribe ->describe (VerbosityLevel::typeOnly ()),
209- ))->identifier ('staticMethod.nonObject ' )->build (),
220+ ))
221+ ->line ($ astName ->getStartLine ())
222+ ->identifier ('staticMethod.nonObject ' )
223+ ->build (),
210224 ]),
211225 null ,
212226 ];
@@ -232,7 +246,10 @@ public function check(
232246 'Call to an undefined static method %s::%s(). ' ,
233247 $ typeForDescribe ->describe (VerbosityLevel::typeOnly ()),
234248 $ methodName ,
235- ))->identifier ('staticMethod.notFound ' )->build (),
249+ ))
250+ ->line ($ astName ->getStartLine ())
251+ ->identifier ('staticMethod.notFound ' )
252+ ->build (),
236253 ]),
237254 null ,
238255 ];
@@ -265,7 +282,10 @@ public function check(
265282 'Static call to instance method %s::%s(). ' ,
266283 $ method ->getDeclaringClass ()->getDisplayName (),
267284 $ method ->getName (),
268- ))->identifier ('method.staticCall ' )->build (),
285+ ))
286+ ->line ($ astName ->getStartLine ())
287+ ->identifier ('method.staticCall ' )
288+ ->build (),
269289 ]),
270290 $ method ,
271291 ];
@@ -281,6 +301,7 @@ public function check(
281301 $ method ->getName (),
282302 $ method ->getDeclaringClass ()->getDisplayName (),
283303 ))
304+ ->line ($ astName ->getStartLine ())
284305 ->identifier (sprintf ('staticMethod.%s ' , $ method ->isPrivate () ? 'private ' : 'protected ' ))
285306 ->build (),
286307 ]);
@@ -294,10 +315,12 @@ public function check(
294315 $ method ->isStatic () ? ' static ' : '' ,
295316 $ method ->getDeclaringClass ()->getDisplayName (),
296317 $ method ->getName (),
297- ))->identifier (sprintf (
298- '%s.callToAbstract ' ,
299- $ method ->isStatic () ? 'staticMethod ' : 'method ' ,
300- ))->build (),
318+ ))
319+ ->line ($ astName ->getStartLine ())
320+ ->identifier (sprintf (
321+ '%s.callToAbstract ' ,
322+ $ method ->isStatic () ? 'staticMethod ' : 'method ' ,
323+ ))->build (),
301324 ],
302325 $ method ,
303326 ];
@@ -317,7 +340,10 @@ public function check(
317340 'Call to %s with incorrect case: %s ' ,
318341 $ lowercasedMethodName ,
319342 $ methodName ,
320- ))->identifier ('staticMethod.nameCase ' )->build ();
343+ ))
344+ ->line ($ astName ->getStartLine ())
345+ ->identifier ('staticMethod.nameCase ' )
346+ ->build ();
321347 }
322348
323349 return [$ errors , $ method ];
0 commit comments