public function prependSibling($sibling, ...$optionals)
{
return $this->handler->insertElement($this->nodes, $sibling, $optionals, function ($sibling, $element) {
if ($sibling->parentNode === null) {
// If the node doesn't have at least one parent node,
// the sibling creation fails. In this case we replace
// the sibling creation with the creation of a child node.
// Useful when dealing with a DOMDocument with a null
// documentElement property.
return $sibling->appendChild($element);
}
return $sibling->parentNode->insertBefore($element, $sibling);
}, $this);
}