respect-validation/library/Exceptions/DigitException.php
Henrique Moody 9283c8ecd9
Do not accept whitespace by default in "Digit" rule
The "Digit" rule is meant to validate digits. However, by default, it
also considers any whitespace character (spaces, new lines, tabs, etc)
as valid.

Since the rule also accepts a list of characters to ignore during the
validation it seemed logical to me to leave the responsibility of
allowing whitespace characters on the hands of the one who uses the
rule.

The messages of the exception are not really consistent, this commit
will also fix that.

It's also clear that the "AbstractCtypeRule" is an unnecessary overhead
since it is only a proxy for "AbstractFilterRule". That one can and
should even be removed after this commit is applied especially because
this commit will also remove the method "filterWhiteSpaceOption" which
is the only substantial difference between "AbstractCtypeRule" and
"AbstractFilterRule".

This commit will also apply our guidelines to the "Digit" rule since we
want to do that to all the rules we have.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2018-09-12 10:00:17 +02:00

36 lines
1,013 B
PHP

<?php
/*
* This file is part of Respect/Validation.
*
* (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
*
* For the full copyright and license information, please view the "LICENSE.md"
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Respect\Validation\Exceptions;
/**
* @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
* @author Henrique Moody <henriquemoody@gmail.com>
*/
final class DigitException extends FilteredValidationException
{
/**
* {@inheritdoc}
*/
public static $defaultTemplates = [
self::MODE_DEFAULT => [
self::STANDARD => '{{name}} must contain only digits (0-9)',
self::EXTRA => '{{name}} must contain only digits (0-9) and {{additionalChars}}',
],
self::MODE_NEGATIVE => [
self::STANDARD => '{{name}} must not contain digits (0-9)',
self::EXTRA => '{{name}} must not contain digits (0-9) and {{additionalChars}}',
],
];
}