mirror of
https://github.com/Respect/Validation.git
synced 2024-06-04 23:02:16 +02:00
Better message for Length rule
Update exception message when minimum value and maximum value are the same.
This commit is contained in:
parent
d14a87c6c7
commit
b43c9b103b
|
@ -16,17 +16,20 @@ class LengthException extends ValidationException
|
|||
const BOTH = 0;
|
||||
const LOWER = 1;
|
||||
const GREATER = 2;
|
||||
const EXACT = 3;
|
||||
|
||||
public static $defaultTemplates = [
|
||||
self::MODE_DEFAULT => [
|
||||
self::BOTH => '{{name}} must have a length between {{minValue}} and {{maxValue}}',
|
||||
self::LOWER => '{{name}} must have a length greater than {{minValue}}',
|
||||
self::GREATER => '{{name}} must have a length lower than {{maxValue}}',
|
||||
self::EXACT => '{{name}} must have a length of {{maxValue}}',
|
||||
],
|
||||
self::MODE_NEGATIVE => [
|
||||
self::BOTH => '{{name}} must not have a length between {{minValue}} and {{maxValue}}',
|
||||
self::LOWER => '{{name}} must not have a length greater than {{minValue}}',
|
||||
self::GREATER => '{{name}} must not have a length lower than {{maxValue}}',
|
||||
self::EXACT => '{{name}} must not have a length of {{maxValue}}',
|
||||
],
|
||||
];
|
||||
|
||||
|
@ -34,10 +37,16 @@ class LengthException extends ValidationException
|
|||
{
|
||||
if (!$this->getParam('minValue')) {
|
||||
return static::GREATER;
|
||||
} elseif (!$this->getParam('maxValue')) {
|
||||
}
|
||||
|
||||
if (!$this->getParam('maxValue')) {
|
||||
return static::LOWER;
|
||||
}
|
||||
|
||||
if ($this->getParam('minValue') == $this->getParam('maxValue')) {
|
||||
return self::EXACT;
|
||||
}
|
||||
|
||||
return static::BOTH;
|
||||
}
|
||||
}
|
||||
|
|
16
tests/integration/rules/length_4.phpt
Normal file
16
tests/integration/rules/length_4.phpt
Normal file
|
@ -0,0 +1,16 @@
|
|||
--FILE--
|
||||
<?php
|
||||
|
||||
require_once 'vendor/autoload.php';
|
||||
|
||||
use Respect\Validation\Exceptions\LengthException;
|
||||
use Respect\Validation\Validator as v;
|
||||
|
||||
try {
|
||||
v::length(5, 5)->check('123456');
|
||||
} catch (LengthException $e) {
|
||||
echo $e->getMainMessage();
|
||||
}
|
||||
?>
|
||||
--EXPECTF--
|
||||
"123456" must have a length of 5
|
Loading…
Reference in a new issue