<commit_before><?php
/**
 * Custom validation rules for validating uploads
 *
 * @author <NAME> <<EMAIL>>
 */

namespace Proffer\Model\Validation;

use Cake\Core\Exception\Exception;
use Cake\Validation\Validator;
use finfo;
use Proffer\Error\DisabledExtension;

class ProfferRules extends Validator
{

    /**
     * Check the size of the image
     *
     * @param array $value An array of the name and value of the field
     * @param int $size Filesize in bytes
     * @return bool
     */
    public static function filesize($value, $size)
    {
        if ($value['size'] <= $size) {
            return true;
        }

        return false;
    }

    /**
     * Make sure the extension matches the allowed
     *
     * @param array $value An array of the name and value of the field
     * @param array $extensions Array of file extensions to allow
     * @return bool
     */
    public static function extension($value, array $extensions)
    {
        $extension = pathinfo($value['tmp_name'], PATHINFO_EXTENSION);

        if (in_array($extension, $extensions)) {
            return true;
        }

        return false;
    }

    /**
     * Check the mimetype of the file
     *<commit_msg>Changed 'tmp_name' to 'name'<commit_after><?php
/**
 * Custom validation rules for validating uploads
 *
 * @author <NAME> <<EMAIL>>
 */

namespace Proffer\Model\Validation;

use Cake\Core\Exception\Exception;
use Cake\Validation\Validator;
use finfo;
use Proffer\Error\DisabledExtension;

class ProfferRules extends Validator
{

    /**
     * Check the size of the image
     *
     * @param array $value An array of the name and value of the field
     * @param int $size Filesize in bytes
     * @return bool
     */
    public static function filesize($value, $size)
    {
        if ($value['size'] <= $size) {
            return true;
        }

        return false;
    }

    /**
     * Make sure the extension matches the allowed
     *
     * @param array $value An array of the name and value of the field
     * @param array $extensions Array of file extensions to allow
     * @return bool
     */
    public static function extension($value, array $extensions)
    {
        $extension = pathinfo($value['name'], PATHINFO_EXTENSION);

        if (in_array($extension, $extensions)) {
            return true;
        }

        return false;
    }

    /**
     * Check the mimetype of the file
     *
{'fraction_non_alphanumeric': 0.10070160957490713, 'fraction_numerical': 0.0, 'mean_word_length': 2.3205479452054796, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, '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': '2349483', 'n_tokens_mistral': 694, 'n_tokens_neox': 669, 'n_words': 235}