Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ parameters:
- '#Call to an undefined method DateTimeInterface::setTime\(\)#'
- '#Call to an undefined method DateTimeInterface::setTimezone\(\)#'
- '#Call to an undefined method DateTimeInterface::sub\(\)#'
- '#Method Cron\\CronExpression::getRunDate\(\) should return DateTime but returns DateTimeInterface.#'

level: 2
level: 8

paths:
- src/
17 changes: 8 additions & 9 deletions src/Cron/AbstractField.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ public function isInIncrementsOfRanges(int $dateValue, string $value): bool
{
$chunks = array_map('trim', explode('/', $value, 2));
$range = $chunks[0];
$step = $chunks[1] ?? 0;
$step = (int) ($chunks[1] ?? 0);

// No step or 0 steps aren't cool
if (null === $step || '0' === $step || 0 === $step) {
if (0 === $step) {
return false;
}

Expand Down Expand Up @@ -184,7 +184,7 @@ public function isInIncrementsOfRanges(int $dateValue, string $value): bool
* @param string $expression The expression to evaluate
* @param int $max Maximum offset for range
*
* @return array<int, int>
* @return list<int|string>
*/
public function getRangeForExpression(string $expression, int $max): array
{
Expand All @@ -193,7 +193,6 @@ public function getRangeForExpression(string $expression, int $max): array

if (false !== strpos($expression, ',')) {
$ranges = explode(',', $expression);
$values = [];
foreach ($ranges as $range) {
$expanded = $this->getRangeForExpression($range, $this->rangeEnd);
$values = array_merge($values, $expanded);
Expand All @@ -210,18 +209,18 @@ public function getRangeForExpression(string $expression, int $max): array
$stepSize = 1;
} else {
$range = array_map('trim', explode('/', $expression, 2));
$stepSize = $range[1] ?? 0;
$stepSize = (int) ($range[1] ?? 0);
$range = $range[0];
$range = explode('-', $range, 2);
$offset = $range[0];
$to = $range[1] ?? $max;
$to = (int) ($range[1] ?? $max);
}
$offset = '*' === $offset ? $this->rangeStart : $offset;
$offset = (int) ('*' === $offset ? $this->rangeStart : $offset);
if ($stepSize >= $this->rangeEnd) {
$values = [$this->fullRange[(int) $stepSize % \count($this->fullRange)]];
$values = [$this->fullRange[$stepSize % \count($this->fullRange)]];
} else {
for ($i = $offset; $i <= $to; $i += $stepSize) {
$values[] = (int) $i;
$values[] = $i;
}
}
sort($values);
Expand Down