Skip to content

Commit 2ccf8ce

Browse files
committed
blank lines fix
1 parent 83c363d commit 2ccf8ce

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/parser/PrettyPrinter.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
use PhpParser\PrettyPrinter\Standard;
55
use PhpParser\Node\Expr\Array_;
6+
use PhpParser\Node\Stmt;
7+
use PhpParser\Node;
8+
use PhpParser\Node\Expr;
69

710
class 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) {

0 commit comments

Comments
 (0)