From 489f8c8b562590eb5f581ca038b02cc2ba13f4f3 Mon Sep 17 00:00:00 2001 From: nikic <+@ni-po.com> Date: Sun, 29 May 2011 20:38:36 +0200 Subject: [PATCH] Fix some prettyprinting issues --- lib/PrettyPrinter/Zend.php | 16 ++++++++-------- test/testAgainstDirectory.php | 30 ++++++++++++++++++++++++++---- 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/lib/PrettyPrinter/Zend.php b/lib/PrettyPrinter/Zend.php index dd52edb..c949509 100644 --- a/lib/PrettyPrinter/Zend.php +++ b/lib/PrettyPrinter/Zend.php @@ -299,7 +299,7 @@ class PrettyPrinter_Zend extends PrettyPrinterAbstract } public function pExpr_StaticCall(Node_Expr_StaticCall $node) { - return $this->p($node->class) . '::' + return $this->pClassName($node->class) . '::' . ($node->func instanceof Node_Variable ? $this->p($node->func) : $node->func) . '(' . $this->pCommaSeparated($node->args) . ')'; } @@ -351,7 +351,7 @@ class PrettyPrinter_Zend extends PrettyPrinterAbstract } public function pExpr_StaticPropertyFetch(Node_Expr_StaticPropertyFetch $node) { - return $this->p($node->class) . '::$' . $this->pObjectProperty($node->name); + return $this->pClassName($node->class) . '::$' . $this->pObjectProperty($node->name); } public function pExpr_ShellExec(Node_Expr_ShellExec $node) { @@ -370,7 +370,7 @@ class PrettyPrinter_Zend extends PrettyPrinterAbstract } public function pExpr_New(Node_Expr_New $node) { - return 'new ' . $this->p($node->class) . '(' . $this->pCommaSeparated($node->args) . ')'; + return 'new ' . $this->pClassName($node->class) . '(' . $this->pCommaSeparated($node->args) . ')'; } public function pExpr_Ternary(Node_Expr_Ternary $node) { @@ -406,7 +406,9 @@ class PrettyPrinter_Zend extends PrettyPrinterAbstract return $this->pModifiers($node->type) . 'function ' . $node->name . '(' . $this->pCommaSeparated($node->params) . ')' - . "\n" . '{' . "\n" . $this->pIndent($this->pStmts($node->stmts)) . '}'; + . (null !== $node->stmts + ? "\n" . '{' . "\n" . $this->pIndent($this->pStmts($node->stmts)) . '}' + : ';'); } public function pStmt_ClassConst(Node_Stmt_ClassConst $node) { @@ -535,12 +537,10 @@ class PrettyPrinter_Zend extends PrettyPrinterAbstract } public function pClassName($node) { - if ($node instanceof Node_Name) { - return $this->pName($node); - } elseif ($node == 'static') { + if ($node == 'static') { return 'static'; } else { - throw new InvalidArgumentException(); + return $this->p($node); } } diff --git a/test/testAgainstDirectory.php b/test/testAgainstDirectory.php index 9a5db4e..d1fc144 100644 --- a/test/testAgainstDirectory.php +++ b/test/testAgainstDirectory.php @@ -1,6 +1,6 @@ .failReason { background-color: rgba(255, 0, 0, 0.3); } + + .failCount { + color: red; + }
Parse | Time | PrettyPrint | -Same | +Compare | PASS | @@ -91,6 +100,8 @@ foreach (new RecursiveIteratorIterator(PASS | FAIL | '; + + ++$compareFail; } } else { echo ' @@ -99,6 +110,8 @@ foreach (new RecursiveIteratorIterator(FAIL | '; + + ++$ppFail; } } else { echo ' @@ -108,12 +121,21 @@ foreach (new RecursiveIteratorIterator( |
' . $errMsg . ' | ||||
Fail / Total: | +' . $parseFail . ' / ' . $parseCount . ' | ++ | ' . $ppFail . ' / ' . $ppCount . ' | +' . $compareFail . ' / ' . $compareCount . ' | +