<commit_before><?php
namespace Phalcon\Mvc\Model\Validator;

use Phalcon\Mvc\Model\Exception;
use Phalcon\Mvc\ModelInterface;

/**
 * Phalcon\Mvc\Model\Validator\CardNumber
 *
 * Validates credit card number using Luhn algorithm
 *
 *<code>
 *use Phalcon\Mvc\Model\Validator\CardNumber;
 *
 *class User extends Phalcon\Mvc\Model
 *{
 *
 *  public function validation()
 *  {
 *      $this->validate(new CardNumber(array(
 *          'field' => 'cardnumber',
 *          'message' => 'Card number must be valid',
 *      )));
 *
 *      if ($this->validationHasFailed() == true) {
 *          return false;
 *      }
 *  }
 *
 *}
 *</code>
 */
class CardNumber extends \Phalcon\Mvc\Model\Validator
{
    public function validate($record)
    {
        if (false === is_object($record) || false === $record instanceof ModelInterface) {
            throw new Exception('Invalid parameter type.');
        }

        $field = $this->getOption('field');

        if (false === is_string($field)) {
            throw new Exception('Field name must be a string');
        }

        $fieldValue = $record->readAttribute($field);

        $value = strrev(preg_replace('/[^\d]/','',$fieldValue));
        $checkSum = 0;

        for ($i = 0; $i < strlen($value); $i++) {

            if (($i % 2) == 0) {
                $temp = $value[$i];
            } else {
                $vabufl = $value[$i] * 2;
                if ($temp > 9)  $temp -= 9;
            }

            $checkSum += $temp;
        }

        if ( ($checkSum % 10) != 0)
        {
            $message = $this->getOption('message') ?: 'Credit card number is invalid';

            $this->appendMessage($message, $field, "CardNumber");
            return false;
        }
        return true;
    }
}<commit_msg>Fix PSR-2<commit_after><?php
namespace Phalcon\Mvc\Model\Validator;

use Phalcon\Mvc\Model\Exception;
use Phalcon\Mvc\ModelInterface;

/**
 * Phalcon\Mvc\Model\Validator\CardNumber
 *
 * Validates credit card number using Luhn algorithm
 *
 *<code>
 *use Phalcon\Mvc\Model\Validator\CardNumber;
 *
 *class User extends Phalcon\Mvc\Model
 *{
 *
 *  public function validation()
 *  {
 *      $this->validate(new CardNumber(array(
 *          'field' => 'cardnumber',
 *          'message' => 'Card number must be valid',
 *      )));
 *
 *      if ($this->validationHasFailed() == true) {
 *          return false;
 *      }
 *  }
 *
 *}
 *</code>
 */
class CardNumber extends \Phalcon\Mvc\Model\Validator
{
    public function validate($record)
    {
        if (false === is_object($record) || false === $record instanceof ModelInterface) {
            throw new Exception('Invalid parameter type.');
        }

        $field = $this->getOption('field');

        if (false === is_string($field)) {
            throw new Exception('Field name must be a string');
        }

        $fieldValue = $record->readAttribute($field);

        $value = strrev(preg_replace('/[^\d]/', '', $fieldValue));
        $checkSum = 0;

        for ($i = 0; $i < strlen($value); $i++) {

            if (($i % 2) == 0) {
                $temp = $value[$i];
            } else {
                $vabufl = $value[$i] * 2;
                if ($temp > 9) {
                    $temp -= 9;
                }
            }

            $checkSum += $temp;
        }

        if (($checkSum % 10) != 0) {
            $message = $this->getOption('message') ?: 'Credit card number is invalid';

            $this->appendMessage($message, $field, "CardNumber");
            return false;
        }
        return true;
    }
}
{'fraction_non_alphanumeric': 0.16144376049244544, 'fraction_numerical': 0.0058757694459988805, 'mean_word_length': 1.9423868312757202, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 25, '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': '4663338', 'n_tokens_mistral': 1114, 'n_tokens_neox': 1084, 'n_words': 242}