File tree Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Original file line number Diff line number Diff line change 33
44use PhpParser \PrettyPrinter \Standard ;
55use PhpParser \Node \Expr \Array_ ;
6+ use PhpParser \Node \Stmt ;
7+ use PhpParser \Node ;
8+ use PhpParser \Node \Expr ;
69
710class PrettyPrinter extends Standard {
811
@@ -14,27 +17,28 @@ class PrettyPrinter extends Standard {
1417 *
1518 * @return string Pretty printed statements
1619 */
17- protected function pStmts (array $ nodes , $ indent = true ) {
20+ protected function pStmts (array $ nodes , bool $ indent = true ): string {
1821 $ result = '' ;
19- $ nodeBefore = NULL ;
22+ $ prevNode = null ;
23+
2024 foreach ($ nodes as $ node ) {
21- $ comments = $ node ->getAttribute ('comments ' , array () );
25+ $ comments = $ node ->getAttribute ('comments ' , [] );
2226 if ($ comments ) {
2327 $ result .= "\n" . $ this ->pComments ($ comments );
2428 if ($ node instanceof Stmt \Nop) {
2529 continue ;
2630 }
2731 }
2832
29- if ($ nodeBefore && $ nodeBefore ->getLine () && $ node ->getLine ()) {
30- $ diff = $ node ->getLine ()- $ nodeBefore ->getLine ();
33+ if ($ prevNode && $ prevNode ->getLine () && $ node ->getLine ()) {
34+ $ diff = $ node ->getLine ()- $ prevNode ->getLine ();
3135 if ($ diff > 0 ) {
3236 $ result .= str_repeat ("\n" , $ diff - 1 );
3337 }
3438 }
3539
36- $ result .= "\n" . $ this ->p ($ node ) . ($ node instanceof Expr ? '; ' : '' );
37- $ nodeBefore = $ node ;
40+ $ result .= "\n" . $ this ->p ($ node ) . ($ node instanceof Expr ? '; ' : '' );
41+ $ prevNode = $ node ;
3842 }
3943
4044 if ($ indent ) {
You can’t perform that action at this time.
0 commit comments