Skip to content

Commit

Permalink
fix(validator): inStep when start+step>end | closes #12
Browse files Browse the repository at this point in the history
  • Loading branch information
adhocore committed Aug 15, 2018
1 parent e86fc06 commit 93d2f7f
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,33 @@ public function inRange($value, $offset)

public function inStep($value, $offset)
{
if (\strpos($offset, '*/') !== false || \strpos($offset, '0/') !== false) {
$parts = \explode('/', $offset, 2);
$parts = \explode('/', $offset, 2);

if (empty($parts[1])) {
return false;
}

if (\strpos($offset, '*/') !== false || \strpos($offset, '0/') !== false) {
return $value % $parts[1] === 0;
}

$parts = \explode('/', $offset, 2);
$subparts = \explode('-', $parts[0], 2) + [1 => $value];

return ($subparts[0] <= $value && $value <= $subparts[1] && $parts[1])
? \in_array($value, \range($subparts[0], $subparts[1], $parts[1]))
: false;
return $this->inStepRange($value, $subparts[0], $subparts[1], $parts[1]);
}

public function inStepRange($value, $start, $end, $step)
{
if (($start + $step) > $end) {
return false;
}

if ($start <= $value && $value <= $end) {
return \in_array($value, \range($start, $end, $step));
}

return false;
}

/**
Expand Down

0 comments on commit 93d2f7f

Please sign in to comment.