From fd7ac251084746a24cbcbb66bd5d9d49c9e7cee2 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sun, 29 Jan 2017 21:56:21 +0100 Subject: [PATCH] Throw if pretty-printing Error node --- lib/PhpParser/PrettyPrinter/Standard.php | 4 ++++ test/PhpParser/PrettyPrinterTest.php | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/lib/PhpParser/PrettyPrinter/Standard.php b/lib/PhpParser/PrettyPrinter/Standard.php index a6118ecd..d8e530f0 100644 --- a/lib/PhpParser/PrettyPrinter/Standard.php +++ b/lib/PhpParser/PrettyPrinter/Standard.php @@ -485,6 +485,10 @@ class Standard extends PrettyPrinterAbstract // Other + protected function pExpr_Error(Expr\Error $node) { + throw new \LogicException('Cannot pretty-print AST with Error nodes'); + } + protected function pExpr_Variable(Expr\Variable $node) { if ($node->name instanceof Expr) { return '${' . $this->p($node->name) . '}'; diff --git a/test/PhpParser/PrettyPrinterTest.php b/test/PhpParser/PrettyPrinterTest.php index e316744b..f5a6bfce 100644 --- a/test/PhpParser/PrettyPrinterTest.php +++ b/test/PhpParser/PrettyPrinterTest.php @@ -183,4 +183,14 @@ class PrettyPrinterTest extends CodeTestAbstract [new DNumber(-\NAN), '\NAN'], ]; } + + /** + * @expectedException \LogicException + * @expectedExceptionMessage Cannot pretty-print AST with Error nodes + */ + public function testPrettyPrintWithError() { + $stmts = [new Expr\PropertyFetch(new Expr\Variable('a'), new Expr\Error())]; + $prettyPrinter = new PrettyPrinter\Standard; + $prettyPrinter->prettyPrint($stmts); + } }