<commit_before><?php 

namespace App\Core\Validator;

class Validator 
{
    
}<commit_msg>passes and fails and add filter for required and mail<commit_after><?php 

namespace App\Core\Validator;

class Validator 
{
    /**
     * List of available filters
     * @var array
     */ 
    protected $filters = array(
        'required',
        'mail'
    );
    
    /**
     * data to check
     * @var array
     */ 
    protected $data;
    
    /**
     * List of rules
     * @var array
     */
    protected $rules;
    
    public function __construct($data = array(), $rules = array()) 
    {
        $this->data = $data;
        $this->rules = $rules;
    }
    
    public function passes()
    {
        foreach($this->rules as $field => $rules) {
            $listRules = explode('|', $rules);
            foreach($listRules as $rule) {
                if (strpos($rule, ':') !== false) {
                    $params = explode(':', $rule);
                    $filter = array_shift($params);
                    if (in_array($params[0], $this->filters)) {
                        $this->$filter($this->data[$field], $params);
                    }
                } else {
                    $this->$rule($this->data[$field]);
                }
            }
        }
    }
    
    public function fails() 
    {
        return ! ($this->passes());
    }
    
    /**
     * Check if a value is a mail
     * @params $value
     * @return boolean
     */ 
    public function mail($value)
    {
        return filter_var($value, FILTER_VALIDATE_EMAIL);
    }
    
    
}

{'fraction_non_alphanumeric': 0.13934426229508196, 'fraction_numerical': 0.0006305170239596469, 'mean_word_length': 1.4340490797546013, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '905355', 'n_tokens_mistral': 472, 'n_tokens_neox': 454, 'n_words': 104}