<commit_before><?php

/**
 * Adds additional validation rules to the Form_validation library
 *
 * @package     Nails
 * @subpackage  common
 * @category    Library
 * @author      Nails Dev Team
 * @link
 */

use Nails\Factory;

class CORE_NAILS_Form_validation extends CI_Form_validation
{
    /**
     * Quick mod of run() to allow for HMVC.
     */
    public function run($module = '', $group = '')
    {
        (is_object($module)) && $this->CI = &$module;
            return parent::run($group);
    }

    // --------------------------------------------------------------------------

    /**
     * Returns the form validation error array.
     * @return array
     */
    public function get_error_array()
    {
        return $this->_error_array;
    }

    // --------------------------------------------------------------------------

    /**
     * Checks if a certain value is unique in a specified table if different
     * from current value.
     * @param  string $new    The form value
     * @param  string $params Parameters passed from set_rules() method
     * @return boolean
     */
    public function unique_if_diff($new, $params)
    {
        $CI =& get_instance();

        list($table, $column, $old) = explode(".", $params, 3);

        if ($new == $old) {
            return true;
        }

        if (!array_key_exists('unique_if_diff', $CI->form_validation->_error_messages)) {
            $CI->form_validation->set_message('unique_if_diff', lang('fv_unique_if_diff_field'));
        }

        $CI->db->where($column . ' !=', $old);
        $CI->db->where($column, $new);
        $CI->db->limit(1);
        $q = $CI->db->get($table);

        if ($q->row()) {
            return false;
        }

        return true;
    }

    // --------------------------------------------------------------------------

    /**
     * Checks if a string is in a valid UK post code format.
     * @param  string $str The form value
     * @return boolean
     */
    public function valid_postcode($str)
    {
        $CI =& get_instance();

        if (!array_key_exists('valid_postcode', $CI->form_validation->_error_messages)) {
            $CI->form_validation->set_message('valid_postcode', lang('fv_valid_postcode'));
        }

        $pattern = '/^([Gg][Ii][Rr] 0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([A-Za-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9]?[A-Za-z])))) {0,1}[0-9][A-Za-z]{2})$/';
        return preg_match($pattern, strtoupper($str)) ? true : false;
    }

    // --------------------------------------------------------------------------

    /**
     * Checks if an array satisfies specified count restrictions.
     * @param  array  $aArray  The value to check
     * @param  string  $sParam  The parameter to check against
     * @return boolean
    */
    public function count(array $aArray, $sParam) {

        $oFormValidation = Factory::service('FormValidation');
        $aParams         = preg_replace('/[^0-9]/', '', explode(',', $sParam));
        $mFloor          = getFromArray(0, $aParams, 0);
        $mCeiling        = getFromArray(1, $aParams, INF);

        if(substr($sParam, 0, 1) === '(' && substr($sParam, -1, 1) === ')') {

            $mFloor++;
            $mCeiling--;
        }

        if (($bAboveFloor = $mFloor <= count($aArray)) === false) {

            $oFormValidation->set_message('count', lang('fv_count_floor'));
        }

        if (($bBeneathCeiling = $mCeiling >= count($aArray)) === false) {

            $oFormValidation->set_message('count', lang('fv_count_ceiling'));
        }

        return $bAboveFloor && $bBeneathCeiling;<commit_msg>Revised method name<commit_after><?php

/**
 * Adds additional validation rules to the Form_validation library
 *
 * @package     Nails
 * @subpackage  common
 * @category    Library
 * @author      Nails Dev Team
 * @link
 */

use Nails\Factory;

class CORE_NAILS_Form_validation extends CI_Form_validation
{
    /**
     * Quick mod of run() to allow for HMVC.
     */
    public function run($module = '', $group = '')
    {
        (is_object($module)) && $this->CI = &$module;
            return parent::run($group);
    }

    // --------------------------------------------------------------------------

    /**
     * Returns the form validation error array.
     * @return array
     */
    public function get_error_array()
    {
        return $this->_error_array;
    }

    // --------------------------------------------------------------------------

    /**
     * Checks if a certain value is unique in a specified table if different
     * from current value.
     * @param  string $new    The form value
     * @param  string $params Parameters passed from set_rules() method
     * @return boolean
     */
    public function unique_if_diff($new, $params)
    {
        $CI =& get_instance();

        list($table, $column, $old) = explode(".", $params, 3);

        if ($new == $old) {
            return true;
        }

        if (!array_key_exists('unique_if_diff', $CI->form_validation->_error_messages)) {
            $CI->form_validation->set_message('unique_if_diff', lang('fv_unique_if_diff_field'));
        }

        $CI->db->where($column . ' !=', $old);
        $CI->db->where($column, $new);
        $CI->db->limit(1);
        $q = $CI->db->get($table);

        if ($q->row()) {
            return false;
        }

        return true;
    }

    // --------------------------------------------------------------------------

    /**
     * Checks if a string is in a valid UK post code format.
     * @param  string $str The form value
     * @return boolean
     */
    public function valid_postcode($str)
    {
        $CI =& get_instance();

        if (!array_key_exists('valid_postcode', $CI->form_validation->_error_messages)) {
            $CI->form_validation->set_message('valid_postcode', lang('fv_valid_postcode'));
        }

        $pattern = '/^([Gg][Ii][Rr] 0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([A-Za-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9]?[A-Za-z])))) {0,1}[0-9][A-Za-z]{2})$/';
        return preg_match($pattern, strtoupper($str)) ? true : false;
    }

    // --------------------------------------------------------------------------

    /**
     * Checks if an array satisfies specified count restrictions.
     * @param  array  $aArray  The value to check
     * @param  string  $sParam  The parameter to check against
     * @return boolean
    */
    public function item_count(array $aArray, $sParam) {

        $oFormValidation = Factory::service('FormValidation');
        $aParams         = preg_replace('/[^0-9]/', '', explode(',', $sParam));
        $mFloor          = getFromArray(0, $aParams, 0);
        $mCeiling        = getFromArray(1, $aParams, INF);

        if(substr($sParam, 0, 1) === '(' && substr($sParam, -1, 1) === ')') {

            $mFloor++;
            $mCeiling--;
        }

        if (($bAboveFloor = $mFloor <= count($aArray)) === false) {

            $oFormValidation->set_message('item_count', lang('fv_count_floor'));
        }

        if (($bBeneathCeiling = $mCeiling >= count($aArray)) === false) {

            $oFormValidation->set_message('item_count', lang('fv_count_ceiling'));
        }

        return $bAboveFloor && $bBeneathCeiling;
{'fraction_non_alphanumeric': 0.23786869647954328, 'fraction_numerical': 0.008155498165012914, 'mean_word_length': 1.748599178184535, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 47, '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': '3856626', 'n_tokens_mistral': 2316, 'n_tokens_neox': 2208, 'n_words': 463}