Skip to content

Commit

Permalink
Added min/max check; fixed behavior if max is null and min is not
Browse files Browse the repository at this point in the history
  • Loading branch information
franzose committed Jun 26, 2018
1 parent 5c48679 commit 6abbd19
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/Rules/Core/Length.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ public function __construct(
throw new InvalidArgumentException('Either option "min" or "max" must be given.');
}

if ($max < $min) {
if ($min !== null && $min > $max) {
throw new LogicException('"Min" option cannot be greater that "max".');
}

if ($max !== null && $max < $min) {
throw new LogicException('"Max" option cannot be less that "min".');
}

Expand Down
6 changes: 5 additions & 1 deletion src/Rules/Core/Range.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ public function __construct($min = null, $max = null)
throw new InvalidArgumentException('Either option "min" or "max" must be given.');
}

if ($max < $min) {
if ($min !== null && $min > $max) {
throw new LogicException('"Min" option cannot be greater that "max".');
}

if ($max !== null && $max < $min) {
throw new LogicException('"Max" option cannot be less that "min".');
}

Expand Down

0 comments on commit 6abbd19

Please sign in to comment.