<commit_before><?php
/**
 * Webino (http://webino.sk)
 *
 * @link        https://github.com/webino/WebinoDraw for the canonical source repository
 * @copyright   Copyright (c) 2012-2014 Webino, s. r. o. (http://webino.sk)
 * @author      <NAME> <<EMAIL>>
 * @license     BSD-3-Clause
 */

namespace WebinoDraw\Manipulator\Plugin;

use WebinoDraw\Exception\RuntimeException;

/**
 *
 */
class Html implements InLoopPluginInterface
{
    /**
     * @param PluginArgument $arg
     * @throws Exception\RuntimeException
     */
    public function inLoop(PluginArgument $arg)
    {
        $spec = $arg->getSpec();
        if (!array_key_exists('html', $spec) || null === $spec['html']) {
            return;
        }

        $translatedHtml  = $arg->getHelper()->translateValue($spec['html'], $arg->getVarTranslation(), $spec);
        $node            = $arg->getNode();
        $node->nodeValue = '';

        if (empty($translatedHtml)) {
            return;
        }

        $frag = $node->ownerDocument->createDocumentFragment();
        $frag->appendXml($translatedHtml);
        if (!$frag->hasChildNodes()) {
            throw new RuntimeException('Invalid XHTML ' . $translatedHtml);
        }
        $node->appendChild($frag);
    }
}
<commit_msg>Updated Manipulator\Plugin\Html, added node type check<commit_after><?php
/**
 * Webino (http://webino.sk)
 *
 * @link        https://github.com/webino/WebinoDraw for the canonical source repository
 * @copyright   Copyright (c) 2012-2014 Webino, s. r. o. (http://webino.sk)
 * @author      <NAME> <<EMAIL>>
 * @license     BSD-3-Clause
 */

namespace WebinoDraw\Manipulator\Plugin;

use DOMElement;
use WebinoDraw\Exception;

/**
 *
 */
class Html implements InLoopPluginInterface
{
    /**
     * @param PluginArgument $arg
     * @throws Exception\RuntimeException
     */
    public function inLoop(PluginArgument $arg)
    {
        $spec = $arg->getSpec();
        if (!array_key_exists('html', $spec) || null === $spec['html']) {
            return;
        }

        $node = $arg->getNode();
        if (!($node instanceof DOMElement)) {
            throw new Exception\LogicException('Expected node of type DOMElement');
        }

        $node->nodeValue = '';
        $translatedHtml  = $arg->getHelper()->translateValue($spec['html'], $arg->getVarTranslation(), $spec);

        if (empty($translatedHtml)) {
            return;
        }

        $frag = $node->ownerDocument->createDocumentFragment();
        $frag->appendXml($translatedHtml);
        if (!$frag->hasChildNodes()) {
            throw new Exception\RuntimeException('Invalid XHTML ' . $translatedHtml);
        }
        $node->appendChild($frag);
    }
}

{'fraction_non_alphanumeric': 0.156412157153447, 'fraction_numerical': 0.006671608598962194, 'mean_word_length': 2.532722513089005, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 31, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '4031107', 'n_tokens_mistral': 805, 'n_tokens_neox': 778, 'n_words': 158}