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

/**
 * Check if the input value is valid Taiwan identity card
 * 
 * @author      <NAME> <<EMAIL>>
 */
class IdCardTw extends AbstractValidator
{
    protected $invalidMessage = '%name% must be valid Taiwan identity card';
    
    protected $notMessage = '%name% must not be valid Taiwan identity card';
        
    /**
     * {@inheritdoc}
     */
    protected function validate($input) 
    {
        if (!$this->isString($input)) {
            $this->addError('notString');
            return false;
        }
        
        
        if (10 != strlen($input)) {
            $this->addError('invalid');
            return false;
        }
        
        $input = strtoupper($input);
        
        // Validate the city letter, should be A-Z
        $first = ord($input[0]);
        if ($first <  65 || $first > 90) {
            $this->addError('invalid');
            return false;
        }
        
        // Validate the gender
        if ($input[1] != '1' && $input[1] != '2') {
            $this->addError('invalid');
            return false;
        }
        
        
        list($x1, $x2) = str_split((string)($first - 55));
        $sum = $x1 + 9 * $x2;
        for ($i = 1, $j = 8; $i < 9; $i++, $j--) {
            $sum += $input[$i] * $i;
        }
        
        if (!($sum % 10)) {
            $this->addError('invalid');
            return false;
        }
        
        return true;
        
        
        // c1 = ord(c1) - 64 => A=1, B=2, ... , Z=26
        // sum = c1*8 + c2*7 + ... + c6*3 + c5*2
        $sum = ($first - 64) * 8;
        for ($i = 1, $j = 7; $i < 7; $i++, $j--) {
            $sum += $input[$i] * $j;
        }

        $checksum = $sum % 11;
        if ($checksum == 1) {
            $checksum = 'A';
        } elseif ($checksum > 1) {
            $checksum = 11 - $checksum;
        }
        
        if ($checksum != $input[7]) {
            $this->addError('invalid');
            return false;
        }
        
        return true;
    }
}<commit_msg>removed extra code<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;

/**
 * Check if the input value is valid Taiwan identity card
 * 
 * @author      <NAME> <<EMAIL>>
 */
class IdCardTw extends AbstractValidator
{
    protected $invalidMessage = '%name% must be valid Taiwan identity card';
    
    protected $notMessage = '%name% must not be valid Taiwan identity card';
        
    /**
     * {@inheritdoc}
     */
    protected function validate($input) 
    {
        if (!$this->isString($input)) {
            $this->addError('notString');
            return false;
        }
        
        
        if (10 != strlen($input)) {
            $this->addError('invalid');
            return false;
        }
        
        $input = strtoupper($input);
        
        // Validate the city letter, should be A-Z
        $first = ord($input[0]);
        if ($first <  65 || $first > 90) {
            $this->addError('invalid');
            return false;
        }
        
        // Validate the gender
        if ($input[1] != '1' && $input[1] != '2') {
            $this->addError('invalid');
            return false;
        }
        
        
        list($x1, $x2) = str_split((string)($first - 55));
        $sum = $x1 + 9 * $x2;
        for ($i = 1, $j = 8; $i < 9; $i++, $j--) {
            $sum += $input[$i] * $i;
        }
        
        if (!($sum % 10)) {
            $this->addError('invalid');
            return false;
        }
        
        return true;
    }
}
{'fraction_non_alphanumeric': 0.16099948480164863, 'fraction_numerical': 0.024471921689850594, 'mean_word_length': 1.448297604035309, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 28, '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': '3497469', 'n_tokens_mistral': 1236, 'n_tokens_neox': 1188, 'n_words': 297}