3
3
namespace PHPStan \Rules \Methods ;
4
4
5
5
use PHPStan \Analyser \Scope ;
6
+ use PHPStan \Node \InClassMethodNode ;
6
7
use PHPStan \Reflection \ClassReflection ;
8
+ use PHPStan \Reflection \MethodReflection ;
7
9
8
10
class WrongCaseOfInheritedMethodRule implements \PHPStan \Rules \Rule
9
11
{
10
12
11
13
public function getNodeType (): string
12
14
{
13
- return \ PhpParser \ Node \ Stmt \ClassMethod ::class;
15
+ return InClassMethodNode ::class;
14
16
}
15
17
16
18
/**
@@ -23,19 +25,19 @@ public function processNode(
23
25
Scope $ scope
24
26
): array
25
27
{
26
- if (!$ scope ->isInClass ()) {
27
- throw new \PHPStan \ShouldNotHappenException ();
28
+ $ methodReflection = $ scope ->getFunction ();
29
+ if (!$ methodReflection instanceof MethodReflection) {
30
+ return [];
28
31
}
29
32
30
- $ methodReflection = $ scope ->getClassReflection ()->getNativeMethod ($ node ->name ->name );
31
33
$ declaringClass = $ methodReflection ->getDeclaringClass ();
32
34
33
35
$ messages = [];
34
36
if ($ declaringClass ->getParentClass () !== false ) {
35
37
$ parentMessage = $ this ->findMethod (
36
38
$ declaringClass ,
37
39
$ declaringClass ->getParentClass (),
38
- $ node -> name -> name
40
+ $ methodReflection -> getName ()
39
41
);
40
42
if ($ parentMessage !== null ) {
41
43
$ messages [] = $ parentMessage ;
@@ -46,7 +48,7 @@ public function processNode(
46
48
$ interfaceMessage = $ this ->findMethod (
47
49
$ declaringClass ,
48
50
$ interface ,
49
- $ node -> name -> name
51
+ $ methodReflection -> getName ()
50
52
);
51
53
if ($ interfaceMessage === null ) {
52
54
continue ;
0 commit comments