From cacd77590a282f50c924175bbf67f8d346191057 Mon Sep 17 00:00:00 2001 From: atom Date: Mon, 15 Oct 2018 19:40:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DNumber=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E5=99=A8=E6=9C=80=E5=A4=A7=E5=92=8C=E6=9C=80=E5=B0=8F=E7=9A=84?= =?UTF-8?q?template=E6=B2=A1=E6=9C=89=E7=94=9F=E6=95=88=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20(#218)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 修复Number验证器最大和最小的template没有生效的问题 * Fix: Optimize accuracy of the wording --- src/Helper/ValidatorHelper.php | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/Helper/ValidatorHelper.php b/src/Helper/ValidatorHelper.php index d068fe9d..a5d5c085 100644 --- a/src/Helper/ValidatorHelper.php +++ b/src/Helper/ValidatorHelper.php @@ -4,11 +4,6 @@ use Swoft\Exception\ValidatorException; -/** - * Class ValidatorHelper - * - * @package Swoft\Helper - */ class ValidatorHelper { /** @@ -120,15 +115,15 @@ public static function validateNumber(string $name, $value, $min = null, $max = $value = (int)$value; if ($min !== null && $value < $min) { - $template = empty($template) ?: $template; + $template = empty($template) ? sprintf('Parameter %s is too short (minimum is %d)', $name, $min): $template; - return self::validateError(sprintf('Parameter %s is too small (minimum is %d)', $name, $min), $throws); + return self::validateError($template, $throws); } if ($max !== null && $value > $max) { - $template = empty($template) ?: $template; + $template = empty($template) ? sprintf('Parameter %s is too large (maximum is %d)', $name, $max) : $template; - return self::validateError(sprintf('Parameter %s is too big (maximum is %d)', $name, $max), $throws); + return self::validateError($template, $throws); } return (int)$value; @@ -177,13 +172,13 @@ public static function validateFloat( $value = (float)$value; if ($min !== null && $value < $min) { - $template = empty($template) ? sprintf('Parameter %s is too small (minimum is %d)', $name, $min) : $template; + $template = empty($template) ? sprintf('Parameter %s is too short (minimum is %d)', $name, $min) : $template; return self::validateError($template, $throws); } if ($max !== null && $value > $max) { - $template = empty($template) ? sprintf('Parameter %s is too big (maximum is %d)', $name, $max) : $template; + $template = empty($template) ? sprintf('Parameter %s is too large (maximum is %d)', $name, $max) : $template; return self::validateError($template, $throws); }