Skip to content

Commit

Permalink
修复Number验证器最大和最小的template没有生效的问题 (#218)
Browse files Browse the repository at this point in the history
* 修复Number验证器最大和最小的template没有生效的问题

* Fix: Optimize accuracy of the wording
  • Loading branch information
xnnyeYp authored and swoft-bot committed Oct 15, 2018
1 parent 211a690 commit 848b2ed
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions Helper/ValidatorHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@

use Swoft\Exception\ValidatorException;

/**
* Class ValidatorHelper
*
* @package Swoft\Helper
*/
class ValidatorHelper
{
/**
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 848b2ed

Please sign in to comment.