mirror of
https://github.com/danog/PHP-Parser.git
synced 2024-11-26 20:04:48 +01:00
Fix switch formatting
The switch cases were not indented and fall-through cases had an unnecessary additional newline. Patch by @pscheit (PR #39).
This commit is contained in:
parent
ac6f221c50
commit
df17d62b40
@ -603,7 +603,12 @@ class PHPParser_PrettyPrinter_Zend extends PHPParser_PrettyPrinterAbstract
|
||||
|
||||
public function pStmt_Switch(PHPParser_Node_Stmt_Switch $node) {
|
||||
return 'switch (' . $this->p($node->cond) . ') {'
|
||||
. "\n" . $this->pImplode($node->cases) . '}';
|
||||
. "\n" . $this->pStmts($node->cases) . "\n" . '}';
|
||||
}
|
||||
|
||||
public function pStmt_Case(PHPParser_Node_Stmt_Case $node) {
|
||||
return (null !== $node->cond ? 'case ' . $this->p($node->cond) : 'default') . ':'
|
||||
. ($node->stmts ? "\n" . $this->pStmts($node->stmts) : '');
|
||||
}
|
||||
|
||||
public function pStmt_TryCatch(PHPParser_Node_Stmt_TryCatch $node) {
|
||||
@ -619,11 +624,6 @@ class PHPParser_PrettyPrinter_Zend extends PHPParser_PrettyPrinterAbstract
|
||||
. "\n" . $this->pStmts($node->stmts) . "\n" . '}';
|
||||
}
|
||||
|
||||
public function pStmt_Case(PHPParser_Node_Stmt_Case $node) {
|
||||
return (null !== $node->cond ? 'case ' . $this->p($node->cond) : 'default') . ':'
|
||||
. "\n" . $this->pStmts($node->stmts) . "\n";
|
||||
}
|
||||
|
||||
public function pStmt_Break(PHPParser_Node_Stmt_Break $node) {
|
||||
return 'break' . ($node->num !== null ? ' ' . $this->p($node->num) : '') . ';';
|
||||
}
|
||||
|
35
test/code/prettyPrinter/switch.test
Normal file
35
test/code/prettyPrinter/switch.test
Normal file
@ -0,0 +1,35 @@
|
||||
switch/case/default
|
||||
-----
|
||||
<?php
|
||||
|
||||
switch ($expr) {
|
||||
case 0:
|
||||
echo 'First case, with a break';
|
||||
break;
|
||||
case 1:
|
||||
echo 'Second case, which falls through';
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
echo 'Third case, return instead of break';
|
||||
return;
|
||||
default:
|
||||
echo 'Default case';
|
||||
break;
|
||||
}
|
||||
-----
|
||||
switch ($expr) {
|
||||
case 0:
|
||||
echo 'First case, with a break';
|
||||
break;
|
||||
case 1:
|
||||
echo 'Second case, which falls through';
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
echo 'Third case, return instead of break';
|
||||
return;
|
||||
default:
|
||||
echo 'Default case';
|
||||
break;
|
||||
}
|
Loading…
Reference in New Issue
Block a user