<commit_before><?php

namespace Codeages\Biz\Framework\Validation;

class SimpleValidator implements Validator
{
    protected $data = array();

    protected $rules = array();

    protected $errors = array();

    protected $ruleMessages = array(
        'required' => '{key} is required',
        'string' => '{key} must be string',
        'numeric' => '{key} must be numeric',
        'integer' => '{key} must be an integer (0-9)',
        'float' => '{key} must be float',
        'boolean' => '{key} must be boolean',
        'array' => '{key} must be array',
        'alpha' => '{key} must be alphabetic characters',
        'alpha_num' => '{key} must be alpha-numeric characters',
        'alpha_dash' => '{key} must be alpha-numeric characters, dashes and underscores',
        'digits' => '{key} can only contains digits, and length must be {0}',
        'digits_between' => '{key} can only contains digits, and length must be between {0}-{1}',
        'min' => '{key} must be equal or greater than {0}',
        'max' => '{key} must be equal or less than {0}',
        'between' => '{key} must be between {0}-{1}',
        'length' => '{key} must be string, and length must be equal {0}',
        'length_min' => '{key} must be string, and length must be equal or greater than {0}',
        'length_max' => '{key} must be string, and length must be equal or less than {0}',
        'length_between' => '{key} must be string, and length must be between {0}-{1}',
        'email' => '{key} is not a valid email address',
        'in' => '{key} contains invalid value',
        'ip' => '{key} is not a valid IP address',
        'url' => '{key} must be url',
        'http_url' => '{key} must be http url',
        'date' => '{key} must be a valid date',
        'date_after' => '{key} must be a value after a given date',
        'date_after_or_equal' => '{key} must be a value after or equal to the given date',
        'date_before' => '{key} must be a value before a given date',
        'date_before_or_equal' => '{key} must be a value before or equal to the given date',
    );

    private function isEmptyValue($value)
    {
        return is_null($value) || (is_string($value) && empty($value));
    }

    public function validate($fields, $fieldRules, $throwException = true)
    {
        $fields = array_intersect_key($fields, array_flip(array_keys($fieldRules)));

        foreach ($fieldRules as $key => $rules) {
            $rules = RuleParser::parse($rules);
            foreach ($rules as $rule) {
                if (is_string($rule)) {
                    $ruleName = $rule;
                    $params = array();
                } else {
                    $ruleName = array_shift($rule);
                    $params = $rule;
                }
                
                if (!isset($fields[$key]) || is_null($fields[$key]) || (is_string($fields[$key]) && $fields[$key] == '')) {
                    if ($this->inRules('required', $rules)) {
                        $this->addError($key, 'required', $params);
                    }
                    break;
                }

                if (isset($this->rules[$ruleName])) {<commit_msg>remove<commit_after><?php

namespace Codeages\Biz\Framework\Validation;

class SimpleValidator implements Validator
{
    protected $data = array();

    protected $rules = array();

    protected $errors = array();

    protected $ruleMessages = array(
        'required' => '{key} is required',
        'string' => '{key} must be string',
        'numeric' => '{key} must be numeric',
        'integer' => '{key} must be an integer (0-9)',
        'float' => '{key} must be float',
        'boolean' => '{key} must be boolean',
        'array' => '{key} must be array',
        'alpha' => '{key} must be alphabetic characters',
        'alpha_num' => '{key} must be alpha-numeric characters',
        'alpha_dash' => '{key} must be alpha-numeric characters, dashes and underscores',
        'digits' => '{key} can only contains digits, and length must be {0}',
        'digits_between' => '{key} can only contains digits, and length must be between {0}-{1}',
        'min' => '{key} must be equal or greater than {0}',
        'max' => '{key} must be equal or less than {0}',
        'between' => '{key} must be between {0}-{1}',
        'length' => '{key} must be string, and length must be equal {0}',
        'length_min' => '{key} must be string, and length must be equal or greater than {0}',
        'length_max' => '{key} must be string, and length must be equal or less than {0}',
        'length_between' => '{key} must be string, and length must be between {0}-{1}',
        'email' => '{key} is not a valid email address',
        'in' => '{key} contains invalid value',
        'ip' => '{key} is not a valid IP address',
        'url' => '{key} must be url',
        'http_url' => '{key} must be http url',
        'date' => '{key} must be a valid date',
        'date_after' => '{key} must be a value after a given date',
        'date_after_or_equal' => '{key} must be a value after or equal to the given date',
        'date_before' => '{key} must be a value before a given date',
        'date_before_or_equal' => '{key} must be a value before or equal to the given date',
    );

    public function validate($fields, $fieldRules, $throwException = true)
    {
        $fields = array_intersect_key($fields, array_flip(array_keys($fieldRules)));

        foreach ($fieldRules as $key => $rules) {
            $rules = RuleParser::parse($rules);
            foreach ($rules as $rule) {
                if (is_string($rule)) {
                    $ruleName = $rule;
                    $params = array();
                } else {
                    $ruleName = array_shift($rule);
                    $params = $rule;
                }

                if (!isset($fields[$key]) || is_null($fields[$key]) || (is_string($fields[$key]) && $fields[$key] == '')) {
                    if ($this->inRules('required', $rules)) {
                        $this->addError($key, 'required', $params);
                    }
                    break;
                }

                if (isset($this->rules[$ruleName])) {
{'fraction_non_alphanumeric': 0.15668276972624798, 'fraction_numerical': 0.0045088566827697265, 'mean_word_length': 2.2098191214470284, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 69, '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': '7229742', 'n_tokens_mistral': 1771, 'n_tokens_neox': 1738, 'n_words': 613}