Skip to content

Commit

Permalink
uints updates
Browse files Browse the repository at this point in the history
  • Loading branch information
James Galecki committed Mar 7, 2018
1 parent 606a22c commit 20a3f69
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/Filter/UnsignedInt.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 20a3f69

Please sign in to comment.