Skip to content

Commit 93d2f7f

Browse files
committed
fix(validator): inStep when start+step>end | closes #12
1 parent e86fc06 commit 93d2f7f

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

src/Validator.php

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,33 @@ public function inRange($value, $offset)
2929

3030
public function inStep($value, $offset)
3131
{
32-
if (\strpos($offset, '*/') !== false || \strpos($offset, '0/') !== false) {
33-
$parts = \explode('/', $offset, 2);
32+
$parts = \explode('/', $offset, 2);
33+
34+
if (empty($parts[1])) {
35+
return false;
36+
}
3437

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

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

41-
return ($subparts[0] <= $value && $value <= $subparts[1] && $parts[1])
42-
? \in_array($value, \range($subparts[0], $subparts[1], $parts[1]))
43-
: false;
45+
return $this->inStepRange($value, $subparts[0], $subparts[1], $parts[1]);
46+
}
47+
48+
public function inStepRange($value, $start, $end, $step)
49+
{
50+
if (($start + $step) > $end) {
51+
return false;
52+
}
53+
54+
if ($start <= $value && $value <= $end) {
55+
return \in_array($value, \range($start, $end, $step));
56+
}
57+
58+
return false;
4459
}
4560

4661
/**

0 commit comments

Comments
 (0)