* @param boolean $preserveChildNodes preserve child nodes, only supported for elements
*/
public static function removeNode(\DOMNode $node, $preserveChildNodes = false) {
+ $parent = $node->parentNode ?: $node->ownerDocument;
+
if ($preserveChildNodes) {
if (!($node instanceof \DOMElement)) {
throw new \InvalidArgumentException("Preserving child nodes is only supported for DOMElement.");
}
foreach ($children as $child) {
- self::insertBefore($child, $node);
+ $parent->insertBefore($child, $node);
}
}
- self::getParentNode($node)->removeChild($node);
+ $parent->removeChild($node);
}
/**