<commit_before><?php
/**
 * Created by PhpStorm.
 * User: johan
 * Date: 2017-09-10
 * Time: 15:44
 */
declare(strict_types = 1);

namespace Vinnia\Util\Validation;


use Vinnia\Util\Arrays;

abstract class Rule implements RuleInterface
{

    /**
     * @param mixed $value
     * @return bool
     */
    abstract protected function validateValue($value): bool;

    /**
     * @param string[] $keys
     * @param string $ruleKey
     * @return array
     */
    public function getMatchingKeys(array $keys, string $ruleKey): array
    {
        $regex = '/^' . str_replace(['.', '*'], ['\.', '[^\.]+'], $ruleKey) . '$/';
        $props = [];
        foreach ($keys as $key) {
            if (preg_match($regex, $key) === 1) {
                $props[] = $key;
            }
        }
        return $props;
    }

    /**
     * @param DataSet $dataSet
     * @param string $ruleKey
     * @return ErrorBag
     */
    public function validateRuleKey(DataSet $dataSet, string $ruleKey): ErrorBag
    {
        $props = $this->getMatchingKeys($dataSet->getKeys(), $ruleKey);
        $errors = new ErrorBag;

        foreach ($props as $prop) {
            if (!$this->validateValue(Arrays::get($dataSet->getData(), $prop, '.'))) {
                $errors->addError($prop, $this->getErrorMessage($prop));
            }
        }

        return $errors;
    }

}<commit_msg>Fix incorrect method call<commit_after><?php
/**
 * Created by PhpStorm.
 * User: johan
 * Date: 2017-09-10
 * Time: 15:44
 */
declare(strict_types = 1);

namespace Vinnia\Util\Validation;


use Vinnia\Util\Arrays;

abstract class Rule implements RuleInterface
{

    /**
     * @param mixed $value
     * @return bool
     */
    abstract protected function validateValue($value): bool;

    /**
     * @param string[] $keys
     * @param string $ruleKey
     * @return array
     */
    public function getMatchingKeys(array $keys, string $ruleKey): array
    {
        $regex = '/^' . str_replace(['.', '*'], ['\.', '[^\.]+'], $ruleKey) . '$/';
        $props = [];
        foreach ($keys as $key) {
            if (preg_match($regex, $key) === 1) {
                $props[] = $key;
            }
        }
        return $props;
    }

    /**
     * @param DataSet $dataSet
     * @param string $ruleKey
     * @return ErrorBag
     */
    public function validateRuleKey(DataSet $dataSet, string $ruleKey): ErrorBag
    {
        $props = $this->getMatchingKeys($dataSet->getKeys(), $ruleKey);
        $errors = new ErrorBag;

        foreach ($props as $prop) {
            if (!$this->validateValue(Arrays::get($dataSet->getData(), $prop))) {
                $errors->addError($prop, $this->getErrorMessage($prop));
            }
        }

        return $errors;
    }

}
{'fraction_non_alphanumeric': 0.16551724137931034, 'fraction_numerical': 0.010163339382940109, 'mean_word_length': 2.096629213483146, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, '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': '5736073', 'n_tokens_mistral': 881, 'n_tokens_neox': 847, 'n_words': 191}