/** * {@inheritdoc} */ public function setParent(ItemInterface $parent = null) { if ($parent === $this) { throw new \InvalidArgumentException('An item cannot have itself as a parent.'); } if ($parent === $this->parent) { return $this; } if ($this->parent) { $this->parent->remove($this); } $this->parent = $parent; if ($parent && !$parent->has($this)) { $this->parent->add($this); } return $this; }