@@ -49,6 +49,9 @@ |
||
| 49 | 49 | return new static($name); |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | + /** |
|
| 53 | + * @param string $name |
|
| 54 | + */ |
|
| 52 | 55 | public function __construct($name) { |
| 53 | 56 | parent::__construct($name); |
| 54 | 57 | $this->initParameters(); |
@@ -17,6 +17,9 @@ |
||
| 17 | 17 | private $visitors; |
| 18 | 18 | private $filename; |
| 19 | 19 | |
| 20 | + /** |
|
| 21 | + * @param string $filename |
|
| 22 | + */ |
|
| 20 | 23 | public function __construct($filename) { |
| 21 | 24 | $this->filename = $filename; |
| 22 | 25 | $this->visitors = new Set(); |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | * Returns whether this node is a boolean value |
| 75 | 75 | * |
| 76 | 76 | * @param Node $node |
| 77 | - * @return bool |
|
| 77 | + * @return boolean|null |
|
| 78 | 78 | */ |
| 79 | 79 | private function isBool(Node $node) { |
| 80 | 80 | if ($node instanceof ConstFetch) { |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | * Returns whether this node is a null value |
| 92 | 92 | * |
| 93 | 93 | * @param Node $node |
| 94 | - * @return bool |
|
| 94 | + * @return boolean|null |
|
| 95 | 95 | */ |
| 96 | 96 | private function isNull(Node $node) { |
| 97 | 97 | if ($node instanceof ConstFetch) { |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | * Returns the value from a node |
| 105 | 105 | * |
| 106 | 106 | * @param Node $node |
| 107 | - * @return mixed |
|
| 107 | + * @return string |
|
| 108 | 108 | */ |
| 109 | 109 | private function getExpression(Node $node) { |
| 110 | 110 | if ($node instanceof ConstFetch) { |
@@ -10,25 +10,25 @@ discard block |
||
| 10 | 10 | class PrettyPrinter extends Standard { |
| 11 | 11 | |
| 12 | 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 = ''; |
|
| 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(?!$|' . $this->noIndentToken . ')~', "\n ", $result); |
|
| 46 | - } else { |
|
| 47 | - return $result; |
|
| 48 | - } |
|
| 49 | - } |
|
| 45 | + return preg_replace('~\n(?!$|' . $this->noIndentToken . ')~', "\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) . ']'; |
@@ -31,7 +31,7 @@ |
||
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | if ($prevNode && $prevNode->getLine() && $node->getLine()) { |
| 34 | - $diff = $node->getLine()- $prevNode->getLine(); |
|
| 34 | + $diff = $node->getLine() - $prevNode->getLine(); |
|
| 35 | 35 | if ($diff > 0) { |
| 36 | 36 | $result .= str_repeat("\n", $diff - 1); |
| 37 | 37 | } |