mirror of
https://github.com/phabelio/PHP-Parser.git
synced 2025-01-22 05:11:39 +01:00
Add NodeTraverser::removeVisitor()
This commit is contained in:
parent
52aa17fa68
commit
700847e295
@ -1,7 +1,8 @@
|
||||
Version 0.9.5-dev
|
||||
-----------------
|
||||
|
||||
Nothing yet.
|
||||
* Added `NodeTraverser::removeVisitor()` method, which removes a visitor from the node traverser. This also modifies the
|
||||
corresponding `NodeTraverserInterface`.
|
||||
|
||||
Version 0.9.4 (25.08.2013)
|
||||
--------------------------
|
||||
|
@ -23,6 +23,20 @@ class PHPParser_NodeTraverser implements PHPParser_NodeTraverserInterface
|
||||
$this->visitors[] = $visitor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an added visitor.
|
||||
*
|
||||
* @param PHPParser_NodeVisitor $visitor
|
||||
*/
|
||||
public function removeVisitor(PHPParser_NodeVisitor $visitor) {
|
||||
foreach ($this->visitors as $index => $storedVisitor) {
|
||||
if ($storedVisitor === $visitor) {
|
||||
unset($this->visitors[$index]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Traverses an array of nodes using the registered visitors.
|
||||
*
|
||||
|
@ -9,6 +9,13 @@ interface PHPParser_NodeTraverserInterface
|
||||
*/
|
||||
function addVisitor(PHPParser_NodeVisitor $visitor);
|
||||
|
||||
/**
|
||||
* Removes an added visitor.
|
||||
*
|
||||
* @param PHPParser_NodeVisitor $visitor
|
||||
*/
|
||||
function removeVisitor(PHPParser_NodeVisitor $visitor);
|
||||
|
||||
/**
|
||||
* Traverses an array of nodes using the registered visitors.
|
||||
*
|
||||
|
@ -122,4 +122,23 @@ class PHPParser_Tests_NodeTraverserTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
$this->assertEquals($stmts, $traverser->traverse($stmts));
|
||||
}
|
||||
|
||||
public function testRemovingVisitor() {
|
||||
$visitor1 = $this->getMock('PHPParser_NodeVisitor');
|
||||
$visitor2 = $this->getMock('PHPParser_NodeVisitor');
|
||||
$visitor3 = $this->getMock('PHPParser_NodeVisitor');
|
||||
|
||||
$traverser = new PHPParser_NodeTraverser;
|
||||
$traverser->addVisitor($visitor1);
|
||||
$traverser->addVisitor($visitor2);
|
||||
$traverser->addVisitor($visitor3);
|
||||
|
||||
$preExpected = array($visitor1, $visitor2, $visitor3);
|
||||
$this->assertAttributeSame($preExpected, 'visitors', $traverser, 'The appropriate visitors have not been added');
|
||||
|
||||
$traverser->removeVisitor($visitor2);
|
||||
|
||||
$postExpected = array(0 => $visitor1, 2 => $visitor3);
|
||||
$this->assertAttributeSame($postExpected, 'visitors', $traverser, 'The appropriate visitors are not present after removal');
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user