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; + } @@ -37,10 +41,12 @@ echo ' - + '; -$GST = microtime(true); +$totalStartTime = microtime(true); +$parseFail = $parseCount = $ppFail = $ppCount = $compareFail = $compareCount = 0; + foreach (new RecursiveIteratorIterator( new RecursiveDirectoryIterator($DIR), RecursiveIteratorIterator::LEAVES_ONLY) @@ -67,6 +73,7 @@ foreach (new RecursiveIteratorIterator( $time = microtime(true) - $startTime; + ++$parseCount; if (false !== $stmts) { $code = 'pStmts($stmts); @@ -77,7 +84,9 @@ foreach (new RecursiveIteratorIterator( } ); + ++$ppCount; if (false !== $ppStmts) { + ++$compareCount; if ($stmts == $ppStmts) { echo ' @@ -91,6 +100,8 @@ foreach (new RecursiveIteratorIterator( '; + + ++$compareFail; } } else { echo ' @@ -99,6 +110,8 @@ foreach (new RecursiveIteratorIterator( '; + + ++$ppFail; } } else { echo ' @@ -108,12 +121,21 @@ foreach (new RecursiveIteratorIterator( '; + + ++$parseFail; } flush(); } echo ' + + + + + + +
Parse Time PrettyPrintSameCompare
PASSPASS FAIL
FAIL
' . $errMsg . '
Fail / Total:' . $parseFail . ' / ' . $parseCount . '' . $ppFail . ' / ' . $ppCount . '' . $compareFail . ' / ' . $compareCount . '
'; -echo 'Total time: ', microtime(true) - $GST; \ No newline at end of file +echo 'Total time: ', microtime(true) - $totalStartTime; \ No newline at end of file