Move leading space out of pStmt_Else

Same as previous commit. Also add support for pStmt_If->else
insertion.
This commit is contained in:
Nikita Popov 2017-10-06 14:56:59 +02:00
parent e3888cbe02
commit bb2ac91115
3 changed files with 13 additions and 3 deletions

View File

@ -717,7 +717,7 @@ class Standard extends PrettyPrinterAbstract
return 'if (' . $this->p($node->cond) . ') {'
. $this->pStmts($node->stmts) . $this->nl . '}'
. ($node->elseifs ? ' ' . $this->pImplode($node->elseifs, ' ') : '')
. (null !== $node->else ? $this->p($node->else) : '');
. (null !== $node->else ? ' ' . $this->p($node->else) : '');
}
protected function pStmt_ElseIf(Stmt\ElseIf_ $node) {
@ -726,7 +726,7 @@ class Standard extends PrettyPrinterAbstract
}
protected function pStmt_Else(Stmt\Else_ $node) {
return ' else {' . $this->pStmts($node->stmts) . $this->nl . '}';
return 'else {' . $this->pStmts($node->stmts) . $this->nl . '}';
}
protected function pStmt_For(Stmt\For_ $node) {

View File

@ -1052,7 +1052,7 @@ abstract class PrettyPrinterAbstract
'Stmt_Continue->num' => [T_CONTINUE, ' ', null],
'Stmt_Foreach->keyVar' => [T_AS, null, ' => '],
'Stmt_Function->returnType' => [')', ' : ', null],
//'Stmt_If->else' => [null, ' ', null], // TODO
'Stmt_If->else' => [null, ' ', null],
'Stmt_Namespace->name' => [T_NAMESPACE, ' ', null],
'Stmt_PropertyProperty->default' => [null, ' = ', null],
'Stmt_Return->expr' => [T_RETURN, ' ', null],

View File

@ -65,6 +65,10 @@ try {
} catch (X
$y) {
}
if ($cond) { // Foo
} elseif ($cond2) { // Bar
}
-----
$stmts[0]->returnType = new Node\Name('Foo');
$stmts[0]->params[0]->type = new Node\Identifier('int');
@ -85,6 +89,7 @@ $stmts[10]->stmts[1]->props[0]->default = new Scalar\DNumber(42.0);
$stmts[11]->keyVar = new Expr\Variable('z');
$stmts[12]->vars[0]->default = new Scalar\String_('abc');
$stmts[13]->finally = new Stmt\Finally_([]);
$stmts[14]->else = new Stmt\Else_([]);
-----
<?php
@ -152,6 +157,11 @@ try {
$y) {
} finally {
}
if ($cond) { // Foo
} elseif ($cond2) { // Bar
} else {
}
-----
<?php