-
Notifications
You must be signed in to change notification settings - Fork 43
Update PrettyPrinter.php #62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -6,6 +6,44 @@ | |||||
|
|
||||||
| class PrettyPrinter extends Standard { | ||||||
|
|
||||||
| /** | ||||||
| * Pretty prints an array of nodes (statements) and indents them optionally. | ||||||
| * | ||||||
| * @param Node[] $nodes Array of nodes | ||||||
| * @param bool $indent Whether to indent the printed nodes | ||||||
| * | ||||||
| * @return string Pretty printed statements | ||||||
| */ | ||||||
| protected function pStmts(array $nodes, $indent = true) { | ||||||
| $result = ''; | ||||||
| $nodeBefore = NULL; | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| foreach ($nodes as $node) { | ||||||
| $comments = $node->getAttribute('comments', array()); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. go modern 😉:
Suggested change
|
||||||
| if ($comments) { | ||||||
| $result .= "\n" . $this->pComments($comments); | ||||||
| if ($node instanceof Stmt\Nop) { | ||||||
| continue; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| if ($nodeBefore && $nodeBefore->getLine() && $node->getLine()) { | ||||||
| $diff = $node->getLine()- $nodeBefore->getLine(); | ||||||
| if ($diff > 0) { | ||||||
| $result .= str_repeat("\n", $diff - 1); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| $result .= "\n" . $this->p($node) . ($node instanceof Expr ? ';' : ''); | ||||||
| $nodeBefore = $node; | ||||||
| } | ||||||
|
|
||||||
| if ($indent) { | ||||||
| return preg_replace('~\n(?!$|' . $this->noIndentToken . ')~', "\n ", $result); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use code profile for indentation character(s) here. |
||||||
| } else { | ||||||
| return $result; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| public function pExpr_Array(Array_ $node) { | ||||||
| return '[' . $this->pCommaSeparated($node->items) . ']'; | ||||||
| } | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
travis says: