File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 66
77class PrettyPrinter extends Standard {
88
9+ /**
10+ * Pretty prints an array of nodes (statements) and indents them optionally.
11+ *
12+ * @param Node[] $nodes Array of nodes
13+ * @param bool $indent Whether to indent the printed nodes
14+ *
15+ * @return string Pretty printed statements
16+ */
17+ protected function pStmts (array $ nodes , $ indent = true ) {
18+ $ result = '' ;
19+ $ nodeBefore = NULL ;
20+ foreach ($ nodes as $ node ) {
21+ $ comments = $ node ->getAttribute ('comments ' , array ());
22+ if ($ comments ) {
23+ $ result .= "\n" . $ this ->pComments ($ comments );
24+ if ($ node instanceof Stmt \Nop) {
25+ continue ;
26+ }
27+ }
28+
29+ if ($ nodeBefore && $ nodeBefore ->getLine () && $ node ->getLine ()) {
30+ $ diff = $ node ->getLine ()- $ nodeBefore ->getLine ();
31+ if ($ diff > 0 ) {
32+ $ result .= str_repeat ("\n" , $ diff - 1 );
33+ }
34+ }
35+
36+ $ result .= "\n" . $ this ->p ($ node ) . ($ node instanceof Expr ? '; ' : '' );
37+ $ nodeBefore = $ node ;
38+ }
39+
40+ if ($ indent ) {
41+ return preg_replace ('~\n(?!$| ' . $ this ->noIndentToken . ')~ ' , "\n " , $ result );
42+ } else {
43+ return $ result ;
44+ }
45+ }
46+
947 public function pExpr_Array (Array_ $ node ) {
1048 return '[ ' . $ this ->pCommaSeparated ($ node ->items ) . '] ' ;
1149 }
You can’t perform that action at this time.
0 commit comments