<commit_before><?php
/**
 * Text input field with validation for numeric values.
 * 
 * @package forms
 * @subpackage fields-formattedinput
 */
class QuantityField extends NumericField
{

    public function Type()
    {
        return 'quantity numeric text';
    }

    /** PHP Validation **/
    public function validate($validator)
    {
        if ($this->value && !is_int(floatval(trim($this->value)))) {
            $validator->validationError(
                $this->name,
                _t(
                    'NumericField.VALIDATION', "'{value}' is not a valid number, only whole numbers can be accepted for this field",
                    array('value' => $this->value)
                ),
                "validation"
            );
            return false;
        } elseif (!$this->value) {
            $validator->validationError(
                $this->name,
                sprintf(_t('Form.FIELDISREQUIRED', '%s is required'), $this->title),
                "validation"
            );
            return false;
        } else {
            return true;
        }
    }
    
    public function dataValue()
    {
        return (is_numeric($this->value)) ? $this->value : 0;<commit_msg>Fix validation issues with quantity field<commit_after><?php
/**
 * Text input field with validation for numeric values.
 * 
 * @package forms
 * @subpackage fields-formattedinput
 */
class QuantityField extends NumericField
{

    public function Type()
    {
        return 'quantity numeric text';
    }

    /** PHP Validation **/
    public function validate($validator)
    {
        // First check if value is numeric
        if ($this->value && $this->isNumeric()) {
            // Convert to a number to check
            $value = $this->value + 0;
            
            if(is_int($value)) {
                return true;
            }
        }
        
        $validator->validationError(
            $this->name,
            _t(
                'Checkout.VALIDATION', '{value} is not a valid number, only whole numbers can be accepted for this field',
                array('value' => $this->value)
            ),
            "validation"
        );
        return false;
    }
    
    public function dataValue()
    {
        return (is_numeric($this->value)) ? $this->value : 0;
{'fraction_non_alphanumeric': 0.11713665943600868, 'fraction_numerical': 0.0013015184381778742, 'mean_word_length': 1.6566820276497696, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 24, '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': '2824028', 'n_tokens_mistral': 610, 'n_tokens_neox': 589, 'n_words': 163}