77use PhpParser \Node ;
88use PhpParser \Node \Expr ;
99use PhpParser \Node \Expr \FuncCall ;
10+ use PhpParser \Node \Identifier ;
1011use PhpParser \Node \Name ;
1112use PhpParser \NodeVisitor ;
1213
@@ -30,18 +31,17 @@ public function beforeTraverse(array $nodes)
3031
3132 public function enterNode (Node $ node )
3233 {
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-
4434 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 ;
4545 case 'Stmt_Echo ' :
4646 case 'Stmt_Return ' :
4747 case 'Expr_Print ' :
@@ -67,10 +67,13 @@ public function getFunctions(): array
6767 return $ this ->functions ;
6868 }
6969
70- protected function createFunction (FuncCall $ node ): ParsedFunction
70+ /**
71+ * @param FuncCall|MethodCall $node
72+ */
73+ protected function createFunction (Expr $ node ): ParsedFunction
7174 {
7275 $ function = new ParsedFunction (
73- $ node-> name -> getLast ( ),
76+ static :: getName ( $ node ),
7477 $ this ->filename ,
7578 $ node ->getStartLine (),
7679 $ node ->getEndLine ()
@@ -114,6 +117,21 @@ protected static function getComment(Comment $comment): string
114117 return trim (implode ("\n" , $ lines ));
115118 }
116119
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+
117135 protected static function getValue (Expr $ value )
118136 {
119137 $ type = $ value ->getType ();
0 commit comments