<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;

/**
 * @package     Widget
 * @author      <NAME> <<EMAIL>>
 */
class Image extends AbstractValidator
{
    protected $notFoundMessage = '%name% is not found or not readable';
    
    protected $notDetectedMessage = '%name% is not a valid image or the size of the image could not be detected';

    protected $widthTooBigMessage = '%name% width is too big (%width%px), allowed maximum width is %maxWidth%px';
    
    protected $widthTooSmallMessage = '%name% width is too small (%width%px), expected minimum width is %minWidth%px';
    
    protected $heightTooBigMessage = '%name% height is too big (%height%px), allowed maximum height is %maxHeight%px';
    
    protected $heightTooSmallMessage = '%name% height is too small (%height%px), expected minimum height is %minHeight%px';
    
    protected $maxWidth;
    
    protected $minWidth;
    
    protected $maxHeight;
    
    protected $minHeight;
    
    /**
     * The detected width of image
     * 
     * @var int
     */
    protected $width;
    
    /**
     * The detected height of image
     * 
     * @var int
     */
    protected $height;
    
    public function __invoke($file, $options = array())
    {
        $options && $this->option($options);
        
        if (false === stream_resolve_include_path($file)) {
            $this->addError('notFound');
            return false;
        }
        
        $size = @getimagesize($file);
        if (false === $size) {
            $this->addError('notDetected');
            return false;
        }
        
        $this->width = $size[0];
        $this->height = $size[1];
        
        if ($this->maxWidth && $this->maxWidth < $this->width) {
            $this->addError('widthTooBig', array(
                'maxWidth' => $this->maxWidth,
                'width' => $this->width
            ));
        }
        
        if ($this->minWidth && $this->minWidth > $this->width) {
            $this->addError('widthTooSmall', array(
                'minWidth' => $this->minWidth,
                'width' => $this->width
            ));
        }
        
        if ($this->maxHeight && $this->maxHeight < $this->height) {
            $this->addError('heightTooBig', array(
                'maxHeight' => $this->maxHeight,
                'height' => $this->height
            ));
        }
        
        if ($this->minHeight && $this->minHeight > $this->height) {
            $this->addError('heightTooSmall', array(
                'minHeight' => $this->minHeight,
                'height' => $this->height
            ));
        }
        
        return !$this->errors;
    }
}
<commit_msg>used file as the image validator parent class<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;

/**
 * @package     Widget
 * @author      <NAME> <<EMAIL>>
 */
class Image extends File
{
    protected $notDetectedMessage = '%name% is not a valid image or the size of the image could not be detected';

    protected $widthTooBigMessage = '%name% width is too big (%width%px), allowed maximum width is %maxWidth%px';
    
    protected $widthTooSmallMessage = '%name% width is too small (%width%px), expected minimum width is %minWidth%px';
    
    protected $heightTooBigMessage = '%name% height is too big (%height%px), allowed maximum height is %maxHeight%px';
    
    protected $heightTooSmallMessage = '%name% height is too small (%height%px), expected minimum height is %minHeight%px';
    
    protected $maxWidth;
    
    protected $minWidth;
    
    protected $maxHeight;
    
    protected $minHeight;
    
    /**
     * The detected width of image
     * 
     * @var int
     */
    protected $width;
    
    /**
     * The detected height of image
     * 
     * @var int
     */
    protected $height;
    
    public function __invoke($file, $options = array())
    {
        parent::__invoke($file, $options);
        
        $size = @getimagesize($file);
        if (false === $size) {
            $this->addError('notDetected');
            return false;
        }
        
        $this->width = $size[0];
        $this->height = $size[1];
        
        if ($this->maxWidth && $this->maxWidth < $this->width) {
            $this->addError('widthTooBig', array(
                'maxWidth' => $this->maxWidth,
                'width' => $this->width
            ));
        }
        
        if ($this->minWidth && $this->minWidth > $this->width) {
            $this->addError('widthTooSmall', array(
                'minWidth' => $this->minWidth,
                'width' => $this->width
            ));
        }
        
        if ($this->maxHeight && $this->maxHeight < $this->height) {
            $this->addError('heightTooBig', array(
                'maxHeight' => $this->maxHeight,
                'height' => $this->height
            ));
        }
        
        if ($this->minHeight && $this->minHeight > $this->height) {
            $this->addError('heightTooSmall', array(
                'minHeight' => $this->minHeight,
                'height' => $this->height
            ));
        }
        
        return !$this->errors;
    }
}

{'fraction_non_alphanumeric': 0.13643574828133262, 'fraction_numerical': 0.004230565838180857, 'mean_word_length': 1.7213429256594723, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 89, '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': '2337733', 'n_tokens_mistral': 1651, 'n_tokens_neox': 1552, 'n_words': 382}