Skip to content

Commit

Permalink
Now NodeInterface extends from IteratorAggregate and Traversable.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Jun 5, 2019
1 parent 0a4587a commit 170ed5f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 11 additions & 3 deletions src/Node/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ public function getAncestors(): \Traversable
}
}

/**
* {@inheritdoc}
*/
public function getIterator()
{
yield from $this->children();
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -194,10 +202,10 @@ public function offsetUnset($offset)
*/
public function remove(NodeInterface ...$nodes): NodeInterface
{
$this->storage['children'] = new \ArrayObject(
$this->storage['children']->exchangeArray(
\array_filter(
(array) $this->storage['children'],
function ($child) use ($nodes) {
$this->storage['children']->getArrayCopy(),
static function ($child) use ($nodes) {
return !\in_array($child, $nodes, true);
}
)
Expand Down
2 changes: 1 addition & 1 deletion src/Node/NodeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* Interface NodeInterface.
*/
interface NodeInterface extends \Countable, \ArrayAccess
interface NodeInterface extends \Countable, \ArrayAccess, \Traversable, \IteratorAggregate
{
/**
* The node to add.
Expand Down

0 comments on commit 170ed5f

Please sign in to comment.