@@ -9,26 +9,26 @@ discard block |
||
9 | 9 | |
10 | 10 | class PrettyPrinter extends Standard { |
11 | 11 | |
12 | - /** |
|
13 | - * Pretty prints an array of nodes (statements) and indents them optionally. |
|
14 | - * |
|
15 | - * @param Node[] $nodes Array of nodes |
|
16 | - * @param bool $indent Whether to indent the printed nodes |
|
17 | - * |
|
18 | - * @return string Pretty printed statements |
|
19 | - */ |
|
20 | - protected function pStmts(array $nodes, bool $indent = true): string { |
|
21 | - $result = ''; |
|
12 | + /** |
|
13 | + * Pretty prints an array of nodes (statements) and indents them optionally. |
|
14 | + * |
|
15 | + * @param Node[] $nodes Array of nodes |
|
16 | + * @param bool $indent Whether to indent the printed nodes |
|
17 | + * |
|
18 | + * @return string Pretty printed statements |
|
19 | + */ |
|
20 | + protected function pStmts(array $nodes, bool $indent = true): string { |
|
21 | + $result = ''; |
|
22 | 22 | $prevNode = null; |
23 | 23 | |
24 | - foreach ($nodes as $node) { |
|
25 | - $comments = $node->getAttribute('comments', []); |
|
26 | - if ($comments) { |
|
27 | - $result .= "\n" . $this->pComments($comments); |
|
28 | - if ($node instanceof Stmt\Nop) { |
|
29 | - continue; |
|
30 | - } |
|
31 | - } |
|
24 | + foreach ($nodes as $node) { |
|
25 | + $comments = $node->getAttribute('comments', []); |
|
26 | + if ($comments) { |
|
27 | + $result .= "\n" . $this->pComments($comments); |
|
28 | + if ($node instanceof Stmt\Nop) { |
|
29 | + continue; |
|
30 | + } |
|
31 | + } |
|
32 | 32 | |
33 | 33 | if ($prevNode && $prevNode->getLine() && $node->getLine()) { |
34 | 34 | $diff = $node->getLine()- $prevNode->getLine(); |
@@ -37,16 +37,16 @@ discard block |
||
37 | 37 | } |
38 | 38 | } |
39 | 39 | |
40 | - $result .= "\n" . $this->p($node) . ($node instanceof Expr ? ';' : ''); |
|
40 | + $result .= "\n" . $this->p($node) . ($node instanceof Expr ? ';' : ''); |
|
41 | 41 | $prevNode = $node; |
42 | - } |
|
42 | + } |
|
43 | 43 | |
44 | 44 | if ($indent) { |
45 | - return preg_replace('~\n(?!$)~', "\n ", $result); |
|
46 | - } else { |
|
47 | - return $result; |
|
48 | - } |
|
49 | - } |
|
45 | + return preg_replace('~\n(?!$)~', "\n ", $result); |
|
46 | + } else { |
|
47 | + return $result; |
|
48 | + } |
|
49 | + } |
|
50 | 50 | |
51 | 51 | public function pExpr_Array(Array_ $node) { |
52 | 52 | return '[' . $this->pCommaSeparated($node->items) . ']'; |