Skip to content

Commit 74f8dfc

Browse files
committed
refactor(expr): normalize expr, use regex split instead
1 parent 0c3405b commit 74f8dfc

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/Expression.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,7 @@ public function filter(array $jobs, $time = null)
173173
protected function process($expr, $time)
174174
{
175175
$expr = $this->normalizeExpr($expr);
176-
$expr = \str_ireplace(\array_keys(static::$literals), \array_values(static::$literals), $expr);
177-
$expr = \explode(' ', $expr);
176+
$expr = \preg_split('~\s+~', $expr); # 14
178177

179178
if (\count($expr) < 5 || \count($expr) > 6) {
180179
throw new \UnexpectedValueException(
@@ -203,10 +202,16 @@ protected function normalizeTime($time)
203202

204203
protected function normalizeExpr($expr)
205204
{
205+
$expr = \trim($expr);
206+
206207
if (isset(static::$expressions[$expr])) {
207-
$expr = static::$expressions[$expr];
208+
return static::$expressions[$expr];
208209
}
209210

210-
return $expr;
211+
return \str_ireplace(
212+
\array_keys(static::$literals),
213+
\array_values(static::$literals),
214+
$expr
215+
);
211216
}
212217
}

0 commit comments

Comments
 (0)