@@ -20,17 +20,17 @@ public function __construct()
2020 public function enterNode (Node $ node ): ?Node
2121 {
2222 if ($ node instanceof Node \Stmt \Function_) {
23- $ node ->stmts = $ this ->keepVariadicsAndYields ($ node ->stmts );
23+ $ node ->stmts = $ this ->keepVariadicsAndYieldsAndInlineVars ($ node ->stmts );
2424 return $ node ;
2525 }
2626
2727 if ($ node instanceof Node \Stmt \ClassMethod && $ node ->stmts !== null ) {
28- $ node ->stmts = $ this ->keepVariadicsAndYields ($ node ->stmts );
28+ $ node ->stmts = $ this ->keepVariadicsAndYieldsAndInlineVars ($ node ->stmts );
2929 return $ node ;
3030 }
3131
3232 if ($ node instanceof Node \Expr \Closure) {
33- $ node ->stmts = $ this ->keepVariadicsAndYields ($ node ->stmts );
33+ $ node ->stmts = $ this ->keepVariadicsAndYieldsAndInlineVars ($ node ->stmts );
3434 return $ node ;
3535 }
3636
@@ -41,7 +41,7 @@ public function enterNode(Node $node): ?Node
4141 * @param Node\Stmt[] $stmts
4242 * @return Node\Stmt[]
4343 */
44- private function keepVariadicsAndYields (array $ stmts ): array
44+ private function keepVariadicsAndYieldsAndInlineVars (array $ stmts ): array
4545 {
4646 $ results = $ this ->nodeFinder ->find ($ stmts , static function (Node $ node ): bool {
4747 if ($ node instanceof Node \Expr \YieldFrom || $ node instanceof Node \Expr \Yield_) {
@@ -50,6 +50,9 @@ private function keepVariadicsAndYields(array $stmts): array
5050 if ($ node instanceof Node \Expr \FuncCall && $ node ->name instanceof Node \Name) {
5151 return in_array ($ node ->name ->toLowerString (), ParametersAcceptor::VARIADIC_FUNCTIONS , true );
5252 }
53+ if ($ node instanceof Node \Stmt && $ node ->getDocComment () !== null ) {
54+ return strpos ($ node ->getDocComment ()->getText (), '@var ' ) !== false ;
55+ }
5356
5457 return false ;
5558 });
@@ -59,11 +62,12 @@ private function keepVariadicsAndYields(array $stmts): array
5962 $ newStmts [] = new Node \Stmt \Expression ($ result );
6063 continue ;
6164 }
62- if (!$ result instanceof Node \Expr \FuncCall) {
65+ if ($ result instanceof Node \Expr \FuncCall && $ result ->name instanceof Node \Name) {
66+ $ newStmts [] = new Node \Stmt \Expression (new Node \Expr \FuncCall (new Node \Name \FullyQualified ($ result ->name ), [], $ result ->getAttributes ()));
6367 continue ;
6468 }
6569
66- $ newStmts [] = new Node \Stmt \Expression ( new Node \ Expr \ FuncCall ( new Node \ Name \ FullyQualified ( ' func_get_args ' ) ));
70+ $ newStmts [] = new Node \Stmt \Nop ( $ result -> getAttributes ( ));
6771 }
6872
6973 return $ newStmts ;
0 commit comments