Skip to content

Commit

Permalink
Update syntax.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Dec 12, 2018
1 parent d77e679 commit 6476e4e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
8 changes: 3 additions & 5 deletions src/Node/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,9 @@ public function withChildren(NodeInterface ...$nodes): NodeInterface
$clone = clone $this;
$clone->storage['children'] = [];

foreach ($nodes as $node) {
$clone->add($node);
}

return $clone;
return [] === $nodes ?
$clone:
$clone->add(...$nodes);
}

/**
Expand Down
13 changes: 12 additions & 1 deletion src/Node/NodeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function getSibblings(): \Traversable;
* The number of children a node has.
*
* @return int
* The amound of children.
* The amount of children.
*/
public function degree(): int;

Expand All @@ -105,4 +105,15 @@ public function degree(): int;
* The depth is the number of nodes before root.
*/
public function depth(): int;

/**
* Get a clone of the object without any children.
*
* @param \drupol\phptree\Node\NodeInterface ...$nodes
* The children that the clone will have.
*
* @return \drupol\phptree\Node\NodeInterface
* The new object.
*/
public function withChildren(NodeInterface ...$nodes): NodeInterface;
}

0 comments on commit 6476e4e

Please sign in to comment.