<commit_before><?php

/*
 * This file is part of the Indigo Container package.
 *
 * (c) Indigo Development Team
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Indigo\Container;

use Fuel\Validation\ContainerValidator as Validator;
use Fuel\Validation\RuleProvider\FromArray;
use Fuel\Common\DataContainer;
use InvalidArgumentException;

/**
 * Validation Container
 *
 * Validate data of container
 *
 * @author <NAME> <<EMAIL>>
 */
class Validation extends DataContainer
{
    protected $validator;

    public function __construct(Validator $validator, array $data = array(), $readOnly = false)
    {
        $this->validator = $validator;

        $result = $validator->run($data);

        if ($result->isValid() === false) {
            $error = $result->getErrors();

            throw new InvalidArgumentException(reset($error));
        }

        parent::__construct($data, $readOnly);
    }

    /**
     * {@inheritdocs}
     */
    public function set($key, $value)
    {
        $result = $this->validator->runField($key, $value, $this->data);

        if ($result->isValid() === false) {
            $error = $result->getError($key);

            throw new InvalidArgumentException($error);
        }

        return parent::set($key, $value);
    }

    /**
     * {@inheritdocs}
     */
    public function merge($arg)
    {
        $arguments = array_map(function ($array) {
            if ($array instanceof DataContainer) {
                return $array->getContents();
            }

            return $array;

        }, func_get_args());

        array_unshift($arguments, $this->data);

        $arguments = call_user_func_array('Fuel\\Common\\Arr::merge', $arguments);

        $result = $this->validator->run($arguments);

        if ($result->isValid() === false) {
            $error = $result->getErrors();

            throw new InvalidArgumentException(reset($error));
        }

        return parent::merge($arguments);
    }
}
<commit_msg>Patches applied<commit_after><?php

/*
 * This file is part of the Indigo Container package.
 *
 * (c) Indigo Development Team
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Indigo\Container;

use Fuel\Validation\ContainerValidator as Validator;
use Fuel\Common\DataContainer;
use InvalidArgumentException;

/**
 * Validation Container
 *
 * Validate data of container
 *
 * @author <NAME> <<EMAIL>>
 */
class Validation extends DataContainer
{
    protected $validator;

    public function __construct(Validator $validator, array $data = array(), $readOnly = false)
    {
        $this->validator = $validator;

        $result = $validator->run($data);

        if ($result->isValid() === false) {
            $error = $result->getErrors();

            throw new InvalidArgumentException(reset($error));
        }

        parent::__construct($data, $readOnly);
    }

    /**
     * {@inheritdocs}
     */
    public function set($key, $value)
    {
        $result = $this->validator->runField($key, $value, $this->data);

        if ($result->isValid() === false) {
            $error = $result->getError($key);

            throw new InvalidArgumentException($error);
        }

        return parent::set($key, $value);
    }

    /**
     * {@inheritdocs}
     */
    public function merge($arg)
    {
        $arguments = array_map(function ($array) {
            if ($array instanceof DataContainer) {
                return $array->getContents();
            }

            return $array;

        }, func_get_args());

        array_unshift($arguments, $this->data);

        $arguments = call_user_func_array('Fuel\\Common\\Arr::merge', $arguments);

        $result = $this->validator->run($arguments);

        if ($result->isValid() === false) {
            $error = $result->getErrors();

            throw new InvalidArgumentException(reset($error));
        }

        return parent::merge($arguments);
    }
}

{'fraction_non_alphanumeric': 0.1394441735738664, 'fraction_numerical': 0.0, 'mean_word_length': 2.4919148936170212, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4967135', 'n_tokens_mistral': 1124, 'n_tokens_neox': 1092, 'n_words': 271}