Skip to content

Commit e12a8ab

Browse files
Tweak errors
1 parent 326f6ca commit e12a8ab

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

src/CronLinter.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,9 @@ function ($v) {
113113
$values = explode(",", $data["values"]);
114114
$hasMultipleValues = count($values) > 1;
115115
foreach ($values as $value) {
116-
$valueErrorPrefix = $hasMultipleValues ? "$errorPrefix {$name}[$offset]:" : "$errorPrefix $name:";
117-
$rangeErrorName = $hasMultipleValues ? "{$name}[$offset]" : $name;
116+
$errorIndex = $hasMultipleValues ? "{$name}[$offset]" : $name;
117+
$valueErrorPrefix = "$errorPrefix $errorIndex:";
118+
$rangeErrorPrefix = "Line $lineNo has invalid range for $errorIndex:";
118119

119120
$steppedValues = explode("/", $value);
120121
if (count($steppedValues) > 2) {
@@ -142,7 +143,7 @@ function ($v) {
142143
$rangeValues[0] = "-" . $rangeValues[0];
143144
}
144145
if (count($rangeValues) > 2) {
145-
$this->errors[] = "Line $lineNo has too many values for the range for $rangeErrorName: $steppedValue";
146+
$this->errors[] = "$rangeErrorPrefix $steppedValue (too many values)";
146147
continue;
147148
}
148149

@@ -160,11 +161,11 @@ function ($v) {
160161
$sorted = $rangeValues;
161162
sort($sorted);
162163
if ($sorted !== $rangeValues) {
163-
$this->errors[] = "Line $lineNo has invalid range for $rangeErrorName: $steppedValue (values must be ordered)";
164+
$this->errors[] = "$rangeErrorPrefix $steppedValue (values must be ordered)";
164165
}
165166
} else {
166167
$badValues = implode("-", array_diff($rangeValues, $numericalValues));
167-
$this->errors[] = "Line $lineNo has invalid range for $rangeErrorName: $badValues (values in range must be numeric)";
168+
$this->errors[] = "$rangeErrorPrefix $badValues (values must be numeric)";
168169
}
169170
}
170171
}

tests/LinterTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ public static function invalidProvider(): array {
7070
["60 * * * * php test.php", ["Line 1 has invalid value for Minute: 60"]],
7171
["59,69 * * * * php test.php", ["Line 1 has invalid value for Minute[1]: 69"]],
7272
["60,65 * * * * php test.php", ["Line 1 has invalid value for Minute[0]: 60", "Line 1 has invalid value for Minute[1]: 65"]],
73-
["15-30-45 * * * * php test.php", ["Line 1 has too many values for the range for Minute: 15-30-45"]],
73+
["15-30-45 * * * * php test.php", ["Line 1 has invalid range for Minute: 15-30-45 (too many values)"]],
7474
["*/60 * * * * php test.php", ["Line 1 has invalid value for Minute: 60"]],
7575
["55-61/2 * * * * php test.php", ["Line 1 has invalid value for Minute: 61"]],
76-
["55-61-63/2 * * * * php test.php", ["Line 1 has too many values for the range for Minute: 55-61-63"]],
76+
["55-61-63/2 * * * * php test.php", ["Line 1 has invalid range for Minute: 55-61-63 (too many values)"]],
7777
["61-62/2 * * * * php test.php", ["Line 1 has invalid value for Minute: 61", "Line 1 has invalid value for Minute: 62"]],
7878
["1/2 * * * * php test.php", ["Line 1 has invalid value for Minute: 1 (only wildcard * or range supported)"]],
7979
["*/1/2 * * * * php test.php", ["Line 1 has too many step values for Minute: */1/2"]],
@@ -88,7 +88,7 @@ public static function invalidProvider(): array {
8888
["* 24 * * * php test.php", ["Line 1 has invalid value for Hour: 24"]],
8989
["* 12,24 * * * php test.php", ["Line 1 has invalid value for Hour[1]: 24"]],
9090
["* 24,32 * * * php test.php", ["Line 1 has invalid value for Hour[0]: 24", "Line 1 has invalid value for Hour[1]: 32"]],
91-
["* 6-12-18 * * * php test.php", ["Line 1 has too many values for the range for Hour: 6-12-18"]],
91+
["* 6-12-18 * * * php test.php", ["Line 1 has invalid range for Hour: 6-12-18 (too many values)"]],
9292
["* */40 * * * php test.php", ["Line 1 has invalid value for Hour: 40"]],
9393
["* 23-24/2 * * * php test.php", ["Line 1 has invalid value for Hour: 24"]],
9494
["* 24-26/2 * * * php test.php", ["Line 1 has invalid value for Hour: 24","Line 1 has invalid value for Hour: 26"]],
@@ -104,7 +104,7 @@ public static function invalidProvider(): array {
104104
["* * 32 * * php test.php", ["Line 1 has invalid value for Day of month: 32"]],
105105
["* * 28,35 * * php test.php", ["Line 1 has invalid value for Day of month[1]: 35"]],
106106
["* * 32,35 * * php test.php", ["Line 1 has invalid value for Day of month[0]: 32", "Line 1 has invalid value for Day of month[1]: 35"]],
107-
["* * 7-14-21 * * php test.php", ["Line 1 has too many values for the range for Day of month: 7-14-21"]],
107+
["* * 7-14-21 * * php test.php", ["Line 1 has invalid range for Day of month: 7-14-21 (too many values)"]],
108108
["* * */32 * * php test.php", ["Line 1 has invalid value for Day of month: 32"]],
109109
["* * 21-35/2 * * php test.php", ["Line 1 has invalid value for Day of month: 35"]],
110110
["* * 32-35/2 * * php test.php", ["Line 1 has invalid value for Day of month: 32", "Line 1 has invalid value for Day of month: 35"]],
@@ -119,7 +119,7 @@ public static function invalidProvider(): array {
119119
["* * * 13 * php test.php", ["Line 1 has invalid value for Month: 13"]],
120120
["* * * 3,13 * php test.php", ["Line 1 has invalid value for Month[1]: 13"]],
121121
["* * * 13,14 * php test.php", ["Line 1 has invalid value for Month[0]: 13", "Line 1 has invalid value for Month[1]: 14"]],
122-
["* * * 3-6-9 * php test.php", ["Line 1 has too many values for the range for Month: 3-6-9"]],
122+
["* * * 3-6-9 * php test.php", ["Line 1 has invalid range for Month: 3-6-9 (too many values)"]],
123123
["* * * */24 * php test.php", ["Line 1 has invalid value for Month: 24"]],
124124
["* * * 8-16/2 * php test.php", ["Line 1 has invalid value for Month: 16"]],
125125
["* * * 14-16/2 * php test.php", ["Line 1 has invalid value for Month: 14", "Line 1 has invalid value for Month: 16"]],
@@ -128,14 +128,14 @@ public static function invalidProvider(): array {
128128
["* * * 12-0 * php test.php", ["Line 1 has invalid value for Month: 0"]],
129129
["* * * 12-1 * php test.php", ["Line 1 has invalid range for Month: 12-1 (values must be ordered)"]],
130130
["* * * june * php test.php", ["Line 1 has invalid value for Month: june"]],
131-
["* * * mar-feb * php test.php", ["Line 1 has invalid range for Month: mar-feb (values in range must be numeric)"]],
131+
["* * * mar-feb * php test.php", ["Line 1 has invalid range for Month: mar-feb (values must be numeric)"]],
132132

133133
["* * * * -4 php test.php", ["Line 1 has invalid value for Day of week: -4"]],
134134
["* * * * -3-5 php test.php", ["Line 1 has invalid value for Day of week: -3"]],
135135
["* * * * 7 php test.php", ["Line 1 has invalid value for Day of week: 7"]],
136136
["* * * * 4,8 php test.php", ["Line 1 has invalid value for Day of week[1]: 8"]],
137137
["* * * * 7,8 php test.php", ["Line 1 has invalid value for Day of week[0]: 7", "Line 1 has invalid value for Day of week[1]: 8"]],
138-
["* * * * 2-4-6 php test.php", ["Line 1 has too many values for the range for Day of week: 2-4-6"]],
138+
["* * * * 2-4-6 php test.php", ["Line 1 has invalid range for Day of week: 2-4-6 (too many values)"]],
139139
["* * * * */7 php test.php", ["Line 1 has invalid value for Day of week: 7"]],
140140
["* * * * 4-8/2 php test.php", ["Line 1 has invalid value for Day of week: 8"]],
141141
["* * * * 8-10/2 php test.php", ["Line 1 has invalid value for Day of week: 8", "Line 1 has invalid value for Day of week: 10"]],
@@ -144,7 +144,7 @@ public static function invalidProvider(): array {
144144
["* * * * thurs php test.php", ["Line 1 has invalid value for Day of week: thurs"]],
145145
["* * * * 6-0 php test.php", ["Line 1 has invalid range for Day of week: 6-0 (values must be ordered)"]],
146146
["* * * * 5-2 php test.php", ["Line 1 has invalid range for Day of week: 5-2 (values must be ordered)"]],
147-
["* * * * fri-mon php test.php", ["Line 1 has invalid range for Day of week: fri-mon (values in range must be numeric)"]],
147+
["* * * * fri-mon php test.php", ["Line 1 has invalid range for Day of week: fri-mon (values must be numeric)"]],
148148

149149
["* * * 18 45 php test.php", ["Line 1 has invalid value for Month: 18", "Line 1 has invalid value for Day of week: 45"]],
150150
];

0 commit comments

Comments
 (0)