Skip to content

Commit 178fbb8

Browse files
Tweak
1 parent 7ee9d06 commit 178fbb8

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

src/CronLinter.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -152,19 +152,16 @@ function ($v) {
152152
}
153153
}
154154

155-
// Check if range is ordered (only if both values are valid and numeric)
156155
if (!$hasInvalidValue && count($rangeValues) === 2) {
157-
$start = $rangeValues[0];
158-
$end = $rangeValues[1];
159-
160-
// Only check ordering for numeric values
161-
if (is_numeric($start) && is_numeric($end)) {
162-
$startValue = (int)$start;
163-
$endValue = (int)$end;
164-
165-
if ($startValue > $endValue) {
156+
$numericalValues = array_filter($rangeValues, "is_numeric");
157+
if (count($numericalValues) === 2) {
158+
$sorted = $rangeValues;
159+
sort($sorted);
160+
if ($sorted !== $rangeValues) {
166161
$this->errors[] = "$valueErrorPrefix $steppedValue - values must be ordered";
167162
}
163+
} else {
164+
$this->errors[] = "$valueErrorPrefix " . implode("-", array_diff($rangeValues, $numericalValues)) . " - values in range must be numeric";
168165
}
169166
}
170167
}
@@ -178,6 +175,4 @@ function ($v) {
178175
$this->errors[] = "Line $lineNo has invalid Cmd: $cmd";
179176
}
180177
}
181-
182-
183178
}

tests/LinterTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ public static function validProvider(): array {
4545
["* * * 6-12/2 * php test.php"],
4646
["* * * feb * php test.php"],
4747
["* * * JUN * php test.php"],
48-
["* * * dec-jan * php test.php"],
49-
["* * * mar-feb * php test.php"],
5048

5149
["* * * * 0 php test.php"],
5250
["* * * * 6 php test.php"],
@@ -56,7 +54,6 @@ public static function validProvider(): array {
5654
["* * * * 1-5/4 php test.php"],
5755
["* * * * fri php test.php"],
5856
["* * * * TuE php test.php"],
59-
["* * * * fri-mon php test.php"],
6057
];
6158
}
6259

@@ -122,6 +119,8 @@ public static function invalidProvider(): array {
122119
["* * * 8/12 * php test.php", ["Line 1 has invalid value for Month: 8 - wildcard * or range supported only"]],
123120
["* * * 8/12/16 * php test.php", ["Line 1 has invalid value for Month: 8/12/16 - too many steps"]],
124121
["* * * june * php test.php", ["Line 1 has invalid value for Month: june"]],
122+
["* * * dec-jan * php test.php", ["Line 1 has invalid value for Month: dec-jan - values in range must be numeric"]],
123+
["* * * mar-feb * php test.php", ["Line 1 has invalid value for Month: mar-feb - values in range must be numeric"]],
125124
["* * * 12-1 * php test.php", ["Line 1 has invalid value for Month: 12-1 - values must be ordered"]],
126125

127126
["* * * * -4 php test.php", ["Line 1 has invalid value for Day of week: -4"]],
@@ -137,6 +136,7 @@ public static function invalidProvider(): array {
137136
["* * * * thurs php test.php", ["Line 1 has invalid value for Day of week: thurs"]],
138137
["* * * * 6-0 php test.php", ["Line 1 has invalid value for Day of week: 6-0 - values must be ordered"]],
139138
["* * * * 5-2 php test.php", ["Line 1 has invalid value for Day of week: 5-2 - values must be ordered"]],
139+
["* * * * fri-mon php test.php", ["Line 1 has invalid value for Day of week: fri-mon - values in range must be numeric"]],
140140
];
141141
}
142142

0 commit comments

Comments
 (0)