8
8
use PHPStan \Analyser \Scope ;
9
9
use PHPStan \Internal \SprintfHelper ;
10
10
use PHPStan \Node \InClassMethodNode ;
11
- use PHPStan \Reflection \MethodReflection ;
12
11
use PHPStan \Rules \Rule ;
13
12
use PHPStan \Rules \UnusedFunctionParametersCheck ;
14
13
use PHPStan \ShouldNotHappenException ;
@@ -37,15 +36,7 @@ public function getNodeType(): string
37
36
38
37
public function processNode (Node $ node , Scope $ scope ): array
39
38
{
40
- if (!$ scope ->isInClass ()) {
41
- throw new ShouldNotHappenException ();
42
- }
43
-
44
- $ method = $ scope ->getFunction ();
45
- if (!$ method instanceof MethodReflection) {
46
- return [];
47
- }
48
-
39
+ $ method = $ node ->getMethodReflection ();
49
40
$ originalNode = $ node ->getOriginalNode ();
50
41
if (strtolower ($ method ->getName ()) !== '__construct ' || $ originalNode ->stmts === null ) {
51
42
return [];
@@ -57,9 +48,9 @@ public function processNode(Node $node, Scope $scope): array
57
48
58
49
$ message = sprintf (
59
50
'Constructor of class %s has an unused parameter $%%s. ' ,
60
- SprintfHelper::escapeFormatString ($ scope ->getClassReflection ()->getDisplayName ()),
51
+ SprintfHelper::escapeFormatString ($ node ->getClassReflection ()->getDisplayName ()),
61
52
);
62
- if ($ scope ->getClassReflection ()->isAnonymous ()) {
53
+ if ($ node ->getClassReflection ()->isAnonymous ()) {
63
54
$ message = 'Constructor of an anonymous class has an unused parameter $%s. ' ;
64
55
}
65
56
0 commit comments