/** * @param NodeInterface $parent * * @return $this */ public function setParent(NodeInterface $parent = null) { if ($this->parent === $parent) { return $this; } if ($parent !== null && $this->parent && $this->parent->hasChild($this)) { $this->parent->removeChild($this); return $this; } $this->parent = $parent; if ($parent !== null && !$parent->hasChild($this)) { $parent->appendChild($this); } return $this; }