Skip to content

Commit ee2cc96

Browse files
committed
refactor: rename array of time parts to times
1 parent f0425da commit ee2cc96

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

src/Expression.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,15 @@ public static function isDue($expr, $time = null)
8888
*/
8989
public function isCronDue($expr, $time = null)
9090
{
91-
list($expr, $time) = $this->process($expr, $time);
91+
list($expr, $times) = $this->process($expr, $time);
9292

9393
$checker = new SegmentChecker;
9494
foreach ($expr as $pos => $segment) {
9595
if ($segment === '*' || $segment === '?') {
9696
continue;
9797
}
9898

99-
if (!$checker->checkDue($segment, $pos, $time)) {
99+
if (!$checker->checkDue($segment, $pos, $times)) {
100100
return false;
101101
}
102102
}
@@ -127,11 +127,10 @@ protected function process($expr, $time)
127127
);
128128
}
129129

130-
$time = static::normalizeTime($time);
130+
$time = static::normalizeTime($time);
131+
$times = \array_map('intval', \explode(' ', \date('i G j n w Y t d m N', $time)));
131132

132-
$time = \array_map('intval', \explode(' ', \date('i G j n w Y t d m N', $time)));
133-
134-
return [$expr, $time];
133+
return [$expr, $times];
135134
}
136135

137136
protected function normalizeTime($time)

src/SegmentChecker.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@ public function __construct()
3333
*
3434
* @param string $segment
3535
* @param int $pos
36-
* @param int $time
36+
* @param array $times
3737
*
3838
* @return bool
3939
*/
40-
public function checkDue($segment, $pos, $time)
40+
public function checkDue($segment, $pos, $times)
4141
{
4242
$isDue = true;
4343
$offsets = \explode(',', \trim($segment));
4444

4545
foreach ($offsets as $offset) {
46-
if (null === $isDue = $this->isOffsetDue($offset, $pos, $time)) {
46+
if (null === $isDue = $this->isOffsetDue($offset, $pos, $times)) {
4747
throw new \UnexpectedValueException(
4848
sprintf('Invalid offset value at segment #%d: %s', $pos, $offset)
4949
);
@@ -62,37 +62,37 @@ public function checkDue($segment, $pos, $time)
6262
*
6363
* @param string $offset
6464
* @param int $pos
65-
* @param array $time
65+
* @param array $times
6666
*
6767
* @return bool|null
6868
*/
69-
protected function isOffsetDue($offset, $pos, $time)
69+
protected function isOffsetDue($offset, $pos, $times)
7070
{
7171
if (\strpos($offset, '/') !== false) {
72-
return $this->validator->inStep($time[$pos], $offset);
72+
return $this->validator->inStep($times[$pos], $offset);
7373
}
7474

7575
if (\strpos($offset, '-') !== false) {
76-
return $this->validator->inRange($time[$pos], $offset);
76+
return $this->validator->inRange($times[$pos], $offset);
7777
}
7878

7979
if (\is_numeric($offset)) {
80-
return $time[$pos] == $offset;
80+
return $times[$pos] == $offset;
8181
}
8282

83-
return $this->checkModifier($offset, $pos, $time);
83+
return $this->checkModifier($offset, $pos, $times);
8484
}
8585

86-
protected function checkModifier($offset, $pos, $time)
86+
protected function checkModifier($offset, $pos, $times)
8787
{
8888
$isModifier = \strpbrk($offset, 'LCW#');
8989

9090
if ($pos === 2 && $isModifier) {
91-
return $this->validator->isValidMonthDay($offset, $time);
91+
return $this->validator->isValidMonthDay($offset, $times);
9292
}
9393

9494
if ($pos === 4 && $isModifier) {
95-
return $this->validator->isValidWeekDay($offset, $time);
95+
return $this->validator->isValidWeekDay($offset, $times);
9696
}
9797

9898
return null;

0 commit comments

Comments
 (0)