<commit_before><?php
/**
 * Widget Framework
 *
 * @copyright   Copyright (c) 2008-2013 <NAME>
 * @license     http://www.opensource.org/licenses/apache2.0.php Apache License
 */

namespace Widget\Validator;

use Widget\AbstractWidget;
use Widget\Exception\UnexpectedValueException;

/**
 * The base class of validator
 * 
 * @author      <NAME> <<EMAIL>>
 * @method string t(string $message, array $parameters = array()) Translates a message
 * @property \Widget\T $t The translator widget
 */
abstract class AbstractValidator extends AbstractWidget implements ValidatorInterface
{
    protected $notStringMessage = '%name% must be a string';
    
    /**
     * The common message for opposite validator
     * 
     * @var string
     */
    protected $notMessage = '%name% is not valid';
    
    /**
     * The message name
     * 
     * @var string
     */
    protected $name = 'This value';
    
    /**
     * The error definition
     * 
     * @var array
     */
    protected $errors = array();
    
    /**
     * The summary message that would overwrite all $this->xxxMessage messages
     * when called addError, which MAY useful when you want to set message for 
     * the validaor
     * 
     * @var string
     * @internal
     */
    protected $message;
    
    /**
     * Whether it's a opposite validator, for examole, notDigit is digit's 
     * opposite validator. The opposite validator will returns $this->notMessage 
     * as the error message currently
     * 
     * @var string
     */
    protected $opposite = false;
    
    /**
     * The array constains the validator original property values
     * 
     * @var array
     * @internal
     */
    protected $backup = array();
    
    /**
     * The array to store previous and current called parameters from __invoke
     * 
     * @var array
     * @internal 
     */
    protected $store = array(array());
    
    /**
     * Whether the translation widget has loaded the validator messages
     * 
     * @var bool
     */
    protected static $translationMessagesLoaded;
     
    /**
     * Validate the input value
     * 
     * @param mixed $input
     * @return bool
     */
    public function __invoke($input)
    {
        return $this->isValid($input);
    }

    /**
     * {@inheritdoc}
     */
    public function isValid($input)
    {
        // Clean previous status
        $this->reset();
         
        return $this->opposite xor $this->validate($input);
    }
    
    /**
     * Validate the input value (ignore the $opposite property)
     * 
     * @param type $input
     * @return boolean
     */
    abstract protected function validate($input);
    
    /**
     * Set property value
     * 
     * @param string|array $name The name of property
     * @param mixed $value The value of property
     * @return \Widget\Validator\AbstractValidator
     * @internal This method should be use to set __invoke arguments only
     */
    protected function storeOption($name, $value = null)
    {
        // hanlde array
        if (is_array($name)) {
            foreach ($name as $key => $value) {
                $this->storeOption($key, $value);
            }
            return $this;
        }
        
        if (property_exists($this, $name)) {
            if (!array_key_exists($name, $this->backup)) {
                $this->backup[$name] = $this->$name;
            }<commit_msg>updated varibale type of valiate method<commit_after><?php
/**
 * Widget Framework
 *
 * @copyright   Copyright (c) 2008-2013 <NAME>
 * @license     http://www.opensource.org/licenses/apache2.0.php Apache License
 */

namespace Widget\Validator;

use Widget\AbstractWidget;
use Widget\Exception\UnexpectedValueException;

/**
 * The base class of validator
 * 
 * @author      <NAME> <<EMAIL>>
 * @method string t(string $message, array $parameters = array()) Translates a message
 * @property \Widget\T $t The translator widget
 */
abstract class AbstractValidator extends AbstractWidget implements ValidatorInterface
{
    protected $notStringMessage = '%name% must be a string';
    
    /**
     * The common message for opposite validator
     * 
     * @var string
     */
    protected $notMessage = '%name% is not valid';
    
    /**
     * The message name
     * 
     * @var string
     */
    protected $name = 'This value';
    
    /**
     * The error definition
     * 
     * @var array
     */
    protected $errors = array();
    
    /**
     * The summary message that would overwrite all $this->xxxMessage messages
     * when called addError, which MAY useful when you want to set message for 
     * the validaor
     * 
     * @var string
     * @internal
     */
    protected $message;
    
    /**
     * Whether it's a opposite validator, for examole, notDigit is digit's 
     * opposite validator. The opposite validator will returns $this->notMessage 
     * as the error message currently
     * 
     * @var string
     */
    protected $opposite = false;
    
    /**
     * The array constains the validator original property values
     * 
     * @var array
     * @internal
     */
    protected $backup = array();
    
    /**
     * The array to store previous and current called parameters from __invoke
     * 
     * @var array
     * @internal 
     */
    protected $store = array(array());
    
    /**
     * Whether the translation widget has loaded the validator messages
     * 
     * @var bool
     */
    protected static $translationMessagesLoaded;
     
    /**
     * Validate the input value
     * 
     * @param mixed $input
     * @return bool
     */
    public function __invoke($input)
    {
        return $this->isValid($input);
    }

    /**
     * {@inheritdoc}
     */
    public function isValid($input)
    {
        // Clean previous status
        $this->reset();
         
        return $this->opposite xor $this->validate($input);
    }
    
    /**
     * Validate the input value (ignore the $opposite property)
     * 
     * @param mixed $input The input to be validated
     * @return boolean
     */
    abstract protected function validate($input);
    
    /**
     * Set property value
     * 
     * @param string|array $name The name of property
     * @param mixed $value The value of property
     * @return \Widget\Validator\AbstractValidator
     * @internal This method should be use to set __invoke arguments only
     */
    protected function storeOption($name, $value = null)
    {
        // hanlde array
        if (is_array($name)) {
            foreach ($name as $key => $value) {
                $this->storeOption($key, $value);
            }
            return $this;
        }
        
        if (property_exists($this, $name)) {
            if (!array_key_exists($name, $this->backup)) {
                $this->backup[$name] = $this->$name;
            }
{'fraction_non_alphanumeric': 0.10743921968263212, 'fraction_numerical': 0.0029116319697190273, 'mean_word_length': 1.9986905281536447, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4321192', 'n_tokens_mistral': 1907, 'n_tokens_neox': 1854, 'n_words': 586}