mirror of
https://github.com/danog/PHP-Parser.git
synced 2025-01-22 05:41:23 +01:00
Throw on nested array in NodeTraverser
The AST never uses deeply nested arrays, so don't support this in the node traverser. Throw an exception instead.
This commit is contained in:
parent
d9911c8da5
commit
2b6804aa50
@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user