diff --git a/lib/PhpParser/NodeTraverser.php b/lib/PhpParser/NodeTraverser.php index 6110488..a37f3f6 100644 --- a/lib/PhpParser/NodeTraverser.php +++ b/lib/PhpParser/NodeTraverser.php @@ -162,12 +162,7 @@ class NodeTraverser implements NodeTraverserInterface $doNodes = array(); foreach ($nodes as $i => &$node) { - if (is_array($node)) { - $node = $this->traverseArray($node); - if ($this->stopTraversal) { - break; - } - } elseif ($node instanceof Node) { + if ($node instanceof Node) { $traverseChildren = true; foreach ($this->visitors as $visitor) { $return = $visitor->enterNode($node); @@ -204,6 +199,8 @@ class NodeTraverser implements NodeTraverserInterface $node = $return; } } + } else if (is_array($node)) { + throw new \LogicException('Invalid node structure: Contains nested arrays'); } } diff --git a/test/PhpParser/NodeTraverserTest.php b/test/PhpParser/NodeTraverserTest.php index f4bade0..de59134 100644 --- a/test/PhpParser/NodeTraverserTest.php +++ b/test/PhpParser/NodeTraverserTest.php @@ -115,16 +115,15 @@ class NodeTraverserTest extends \PHPUnit_Framework_TestCase ); } - public function testDeepArray() { + /** + * @expectedException \LogicException + * @expectedExceptionMessage Invalid node structure: Contains nested arrays + */ + public function testInvalidDeepArray() { $strNode = new String_('Foo'); $stmts = array(array(array($strNode))); - $visitor = $this->getMockBuilder('PhpParser\NodeVisitor')->getMock(); - $visitor->expects($this->at(1))->method('enterNode')->with($strNode); - $traverser = new NodeTraverser; - $traverser->addVisitor($visitor); - $this->assertEquals($stmts, $traverser->traverse($stmts)); }