<commit_before><?php
/*
 * This file is part of the QuipXml package.
 *
 * (c) <NAME>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace QuipXml\Xml;

use QuipXml\Quip;
class QuipXmlElement extends \SimpleXMLElement {
  protected function _contentToDom($content) {
    if ($content instanceof \SimpleXMLElement) {
      $new = dom_import_simplexml($content);
    }
    elseif ($content instanceof \DOMNode) {
      $new = $content;
    }
    elseif (is_string($content)) {
      $new = clone dom_import_simplexml(Quip::load($content));
    }
    else {
      throw new \InvalidArgumentException("Unknown type of content.");
    }
    $me = $this->get();
    if ($new->ownerDocument !== $me->ownerDocument) {
      $clone = $new->cloneNode(TRUE);
      $new = $me->ownerDocument->importNode($clone, TRUE);
    }
    return $new;
  }

  protected function _getEmptyElement() {
    $results = parent::xpath('/*');
    return $results[0]->{uniqid('empty element')};
  }

  /**
   * Add the content before this node.
   * @param mixed $content
   * @return \QuipXml\Xml\QuipXmlElement
   */
  public function before($content) {
    if (FALSE === (bool) $this) {
      return $this;
    }
    $me = $this->get();
    $parent = $this->parent_()->get();
    $new = $this->_contentToDom($content);
    $parent->insertBefore($new, $me);
    return $this;
  }

  /**
   * Add the content after this node.
   * @param mixed $content
   * @return \QuipXml\Xml\QuipXmlElement
   */
  public function after($content) {
    if (FALSE === (bool) $this) {
      return $this;
    }
    $this->before($content);
    $this->prev_()->before($this);
    return $this;
  }

  /**
   * Add the content before this node.
   * @param int $index
   * @return \QuipXml\Xml\QuipXmlElement
   */
  public function eq($index = 0) {
    return $this;
  }

  /**
   * Get the DOM object associated with this node.
   * @param int $index
   * @return DOMElement|FALSE
   */
  public function get($index = 0) {
    if ($index == 0) {
      $dom = dom_import_simplexml($this);
      return $dom;
    }
    return FALSE;
  }

  /**
   * @todo set the html content.
   * @todo adjust the xml for html display.<commit_msg>Refactored append() to address travis build error.<commit_after><?php
/*
 * This file is part of the QuipXml package.
 *
 * (c) <NAME>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace QuipXml\Xml;

use QuipXml\Quip;
class QuipXmlElement extends \SimpleXMLElement {
  protected function _contentToDom($content) {
    if ($content instanceof \SimpleXMLElement) {
      $new = dom_import_simplexml($content);
    }
    elseif ($content instanceof \DOMNode) {
      $new = $content;
    }
    elseif (is_string($content)) {
      $new = clone dom_import_simplexml(Quip::load($content));
    }
    else {
      throw new \InvalidArgumentException("Unknown type of content.");
    }
    $me = $this->get();
    if ($new->ownerDocument !== $me->ownerDocument) {
      $clone = $new->cloneNode(TRUE);
      $new = $me->ownerDocument->importNode($clone, TRUE);
    }
    return $new;
  }

  protected function _getEmptyElement() {
    $results = parent::xpath('/*');
    return $results[0]->{uniqid('empty element')};
  }

  /**
   * Add the content before this node.
   * @param mixed $content
   * @return \QuipXml\Xml\QuipXmlElement
   */
  public function before($content) {
    if (FALSE === (bool) $this) {
      return $this;
    }
    $me = $this->get();
    $parent = $this->parent_()->get();
    $new = $this->_contentToDom($content);
    $parent->insertBefore($new, $me);
    return $this;
  }

  /**
   * Add the content after this node.
   * @param mixed $content
   * @return \QuipXml\Xml\QuipXmlElement
   */
  public function after($content) {
    if (FALSE === (bool) $this) {
      return $this;
    }
    $me = $this->get();
    $parent = $this->parent_()->get();
    $new = $this->_contentToDom($content);
    if (isset($me->nextSibling)) {
      $parent->insertBefore($new, $me->nextSibling);
    }
    else {
      $parent->appendChild($new);
    }
    return $this;
  }

  /**
   * Add the content before this node.
   * @param int $index
   * @return \QuipXml\Xml\QuipXmlElement
   */
  public function eq($index = 0) {
    return $this;
  }

  /**
   * Get the DOM object associated with this node.
   * @param int $index
   * @return DOMElement|FALSE
   */
  public function get($index = 0) {
    if ($index == 0) {
      $dom = dom_import_simplexml($this);
      return $dom;
    }
    return FALSE;
  }

  /**
   * @todo set the html content.
   * @todo adjust the xml for html display.
{'fraction_non_alphanumeric': 0.15215571368773545, 'fraction_numerical': 0.0016743407283382169, 'mean_word_length': 2.762992125984252, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '487394', 'n_tokens_mistral': 1553, 'n_tokens_neox': 1540, 'n_words': 403}