public function insertBefore(Node $node, Node $newNode) { $index = $this->indexOf($node); if ($index === false) { return $this->prepend($newNode); } array_splice($this->children, $index, 0, [$newNode]); $newNode->parent = $this; return $this; }