<commit_before><?php
/**
 * Wei Framework
 *
 * @copyright   Copyright (c) 2008-2020 <NAME>
 * @license     http://opensource.org/licenses/mit-license.php MIT License
 */

namespace Wei\Validator;

/**
 * Check if the input could be divisible by specified divisor
 *
 * @author      <NAME> <<EMAIL>>
 */
class DivisibleBy extends BaseValidator
{
    protected $notDivisibleMessage = '%name% must be divisible by %divisor%';

    protected $negativeMessage = '%name% must not be divisible by %divisor%';

    /**
     * Set divisor to 1 to avoid "division by zero" error
     *
     * @var int|float
     */
    protected $divisor = 1;

    /**
     * {@inheritdoc}
     */
    public function __invoke($input, $divisor = null)
    {
        $divisor && $this->storeOption('divisor', $divisor);

        return $this->isValid($input);
    }

    /**
     * {@inheritdoc}
     */
    protected function doValidate($input)
    {
        if (!$this->isString($input)) {
            $this->addError('notDivisible');
            return false;
        }

        if (is_float($this->divisor)) {
            $result = fmod($input, $this->divisor);
        } else {
            $result = $input % $this->divisor;
        }
<commit_msg>chore: 转换输入为 int 值，避免出现 A non-numeric value encountered 错误<commit_after><?php
/**
 * Wei Framework
 *
 * @copyright   Copyright (c) 2008-2020 <NAME>
 * @license     http://opensource.org/licenses/mit-license.php MIT License
 */

namespace Wei\Validator;

/**
 * Check if the input could be divisible by specified divisor
 *
 * @author      <NAME> <<EMAIL>>
 */
class DivisibleBy extends BaseValidator
{
    protected $notDivisibleMessage = '%name% must be divisible by %divisor%';

    protected $negativeMessage = '%name% must not be divisible by %divisor%';

    /**
     * Set divisor to 1 to avoid "division by zero" error
     *
     * @var int|float
     */
    protected $divisor = 1;

    /**
     * {@inheritdoc}
     */
    public function __invoke($input, $divisor = null)
    {
        $divisor && $this->storeOption('divisor', $divisor);

        return $this->isValid($input);
    }

    /**
     * {@inheritdoc}
     */
    protected function doValidate($input)
    {
        if (!$this->isString($input)) {
            $this->addError('notDivisible');
            return false;
        }

        if (is_float($this->divisor)) {
            $result = fmod($input, $this->divisor);
        } else {
            $result = (int) $input % $this->divisor;
        }

{'fraction_non_alphanumeric': 0.14502596883739513, 'fraction_numerical': 0.007990411506192568, 'mean_word_length': 2.2990777338603428, 'pattern_counts': {'":': 0, '<': 13, '<?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': '4797233', 'n_tokens_mistral': 813, 'n_tokens_neox': 765, 'n_words': 193}