7
7
use PhpParser \Node ;
8
8
use PhpParser \Node \Expr ;
9
9
use PhpParser \Node \Expr \FuncCall ;
10
+ use PhpParser \Node \Identifier ;
10
11
use PhpParser \Node \Name ;
11
12
use PhpParser \NodeVisitor ;
12
13
@@ -30,18 +31,17 @@ public function beforeTraverse(array $nodes)
30
31
31
32
public function enterNode (Node $ node )
32
33
{
33
- if ($ node instanceof FuncCall) {
34
- $ name = ($ node ->name instanceof Name) ? $ node ->name ->getLast () : null ;
35
-
36
- if ($ name && ($ this ->validFunctions === null || in_array ($ name , $ this ->validFunctions ))) {
37
- $ this ->functions [] = $ this ->createFunction ($ node );
38
- } elseif ($ node ->getComments ()) {
39
- $ this ->bufferComments = $ node ;
40
- }
41
- return null ;
42
- }
43
-
44
34
switch ($ node ->getType ()) {
35
+ case 'Expr_MethodCall ' :
36
+ case 'Expr_FuncCall ' :
37
+ $ name = static ::getName ($ node );
38
+
39
+ if ($ name && ($ this ->validFunctions === null || in_array ($ name , $ this ->validFunctions ))) {
40
+ $ this ->functions [] = $ this ->createFunction ($ node );
41
+ } elseif ($ node ->getComments ()) {
42
+ $ this ->bufferComments = $ node ;
43
+ }
44
+ return null ;
45
45
case 'Stmt_Echo ' :
46
46
case 'Stmt_Return ' :
47
47
case 'Expr_Print ' :
@@ -67,10 +67,13 @@ public function getFunctions(): array
67
67
return $ this ->functions ;
68
68
}
69
69
70
- protected function createFunction (FuncCall $ node ): ParsedFunction
70
+ /**
71
+ * @param FuncCall|MethodCall $node
72
+ */
73
+ protected function createFunction (Expr $ node ): ParsedFunction
71
74
{
72
75
$ function = new ParsedFunction (
73
- $ node-> name -> getLast ( ),
76
+ static :: getName ( $ node ),
74
77
$ this ->filename ,
75
78
$ node ->getStartLine (),
76
79
$ node ->getEndLine ()
@@ -114,6 +117,21 @@ protected static function getComment(Comment $comment): string
114
117
return trim (implode ("\n" , $ lines ));
115
118
}
116
119
120
+ protected static function getName (Node $ node ): ?string
121
+ {
122
+ $ name = $ node ->name ;
123
+
124
+ if ($ name instanceof Name) {
125
+ return $ name ->getLast ();
126
+ }
127
+
128
+ if ($ name instanceof Identifier) {
129
+ return (string ) $ name ;
130
+ }
131
+
132
+ return null ;
133
+ }
134
+
117
135
protected static function getValue (Expr $ value )
118
136
{
119
137
$ type = $ value ->getType ();
0 commit comments