NavigationItem: Reduce code complexity in method addChild()

refs #5600
This commit is contained in:
Johannes Meyer 2015-09-02 15:17:26 +02:00
parent c03109c4c6
commit 62f7a49a45
1 changed files with 6 additions and 15 deletions

View File

@ -224,30 +224,21 @@ class NavigationItem implements Countable, IteratorAggregate
}
/**
* Add a child item to this item
* Add a child to this item
*
* Bubbles active state.
* If the child is active this item gets activated as well.
*
* @param NavigationItem|array $child The child to add
* @param NavigationItem $child
*
* @return $this
* @throws InvalidArgumentException If the child argument is invalid
*/
public function addChild($child)
public function addChild(NavigationItem $child)
{
if (! $child instanceof NavigationItem) {
if (! is_array($child)) {
throw new InvalidArgumentException(
'Argument child must be either an array or an instance of NavigationItem'
);
}
$child = new NavigationItem($child);
}
$child->parent = $this;
$this->children->addItem($child);
$this->getChildren()->addItem($child->setParent($this));
if ($child->getActive()) {
$this->setActive();
}
return $this;
}