Skip to content

Commit

Permalink
refactor(expr): normalize expr, use regex split instead
Browse files Browse the repository at this point in the history
  • Loading branch information
adhocore committed Aug 12, 2019
1 parent 0c3405b commit 74f8dfc
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/Expression.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,7 @@ public function filter(array $jobs, $time = null)
protected function process($expr, $time)
{
$expr = $this->normalizeExpr($expr);
$expr = \str_ireplace(\array_keys(static::$literals), \array_values(static::$literals), $expr);
$expr = \explode(' ', $expr);
$expr = \preg_split('~\s+~', $expr); # 14

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

protected function normalizeExpr($expr)
{
$expr = \trim($expr);

if (isset(static::$expressions[$expr])) {
$expr = static::$expressions[$expr];
return static::$expressions[$expr];
}

return $expr;
return \str_ireplace(
\array_keys(static::$literals),
\array_values(static::$literals),
$expr
);
}
}

0 comments on commit 74f8dfc

Please sign in to comment.