mirror of
https://github.com/nikic/PHP-Parser.git
synced 2025-01-17 15:18:17 +01:00
Ensure removing visitor does not leave holes
This commit is contained in:
parent
fb2c3ac97c
commit
8bc698248d
@ -48,11 +48,9 @@ class NodeTraverser implements NodeTraverserInterface {
|
||||
* @param NodeVisitor $visitor
|
||||
*/
|
||||
public function removeVisitor(NodeVisitor $visitor): void {
|
||||
foreach ($this->visitors as $index => $storedVisitor) {
|
||||
if ($storedVisitor === $visitor) {
|
||||
unset($this->visitors[$index]);
|
||||
break;
|
||||
}
|
||||
$index = array_search($visitor, $this->visitors);
|
||||
if ($index !== false) {
|
||||
array_splice($this->visitors, $index, 1, []);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -348,7 +348,7 @@ class NodeTraverserTest extends \PHPUnit\Framework\TestCase {
|
||||
|
||||
$traverser->removeVisitor($visitor2);
|
||||
|
||||
$postExpected = [0 => $visitor1, 2 => $visitor3];
|
||||
$postExpected = [$visitor1, $visitor3];
|
||||
$this->assertSame($postExpected, $getVisitors());
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user