diff --git a/src/Filter/UnsignedInt.php b/src/Filter/UnsignedInt.php index 800b33c..a39a3ac 100644 --- a/src/Filter/UnsignedInt.php +++ b/src/Filter/UnsignedInt.php @@ -26,12 +26,19 @@ final class UnsignedInt */ public static function filter($value, bool $allowNull = false, int $minValue = null, int $maxValue = PHP_INT_MAX) { - if ($minValue === null) { - $minValue = 0; - } elseif (is_int($minValue) && $minValue < 0) { + return Ints::filter($value, $allowNull, self::validateMinValue($minValue), $maxValue); + } + + private static function validateMinValue($minValue) : int + { + // IFF a user chooses not to include $minValue, or passes null, mandate it returns to 0. + $minValue = $minValue ?: 0; + + // Validate that the minimum value is positive. + if ($minValue < 0) { throw new \InvalidArgumentException("{$minValue} was not greater or equal to zero"); } - return Ints::filter($value, $allowNull, $minValue, $maxValue); + return $minValue; } }