<commit_before><?php
namespace Mlib\Validator;

class Validator {
	
	protected $fields = array();
	protected $errors = array();	
	
	public function __construct(Array $config) {
		for($i = 0; $i < count($config); $i++) {
			$this->add($config[$i]['name'], $config[$i]);
		}
	}
	
	public function add($name, Array $config) {
		$this->fields[$name] = $config;
	}
	
	/**
	 * @todo return errors if field not set
	 */
	public function test($name, $value) {
		$valid = false;
		if(isset($this->fields[$name])) {
			$valid = $this->_test($this->fields[$name], $value, $name);
		} else {
			// Raise error
		}
		return $valid;
	}
	
	public function error() {
		// Get recent error
		return $this->errors;
	}
	
	protected function add_error($type, $message) {
		$this->errors[] = array('type' => $type, 'message' => $message);
	}
	
	/**
	 * @todo add errors if test does not exist, return more detailed errors about invalid
	 */<commit_msg>testing<commit_after><?php
namespace Mlib\Validator;

class Validator {
	
	protected $fields = array();
	protected $errors = array();	
	
	public function __construct(Array $config) {
		for($i = 0; $i < count($config); $i++) {
			$this->add($config[$i]['name'], $config[$i]);
		}
	}
	
	public function add($name, Array $config) {
		$this->fields[$name] = $config;
	}
	
	/**
	 * @todo return errors if field not set
	 */
	public function test($name, $value) {
		$valid = false;
		if(isset($this->fields[$name])) {
			$valid = $this->_test($this->fields[$name]['validators'], $value, $name);
		} else {
			// Raise error
		}
		return $valid;
	}
	
	public function error() {
		// Get recent error
		return $this->errors;
	}
	
	protected function add_error($type, $message) {
		$this->errors[] = array('type' => $type, 'message' => $message);
	}
	
	/**
	 * @todo add errors if test does not exist, return more detailed errors about invalid
	 */
{'fraction_non_alphanumeric': 0.18609625668449198, 'fraction_numerical': 0.0010695187165775401, 'mean_word_length': 3.619753086419753, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, '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': '6119328', 'n_tokens_mistral': 684, 'n_tokens_neox': 613, 'n_words': 166}