@@ -140,28 +140,14 @@ private function validateInput(InputInterface $input)
140
140
{
141
141
$ this ->staticCheckObjects = [];
142
142
$ requiredChecksNames = $ input ->getArgument ('names ' );
143
- $ invalidCheckNames = [];
144
143
// Build list of static check names to run.
145
144
if (empty ($ requiredChecksNames ) && isset ($ this ->ruleSet ['tests ' ])) {
146
145
$ requiredChecksNames = $ this ->ruleSet ['tests ' ];
147
146
}
148
147
if (empty ($ requiredChecksNames )) {
149
148
$ this ->staticCheckObjects = $ this ->allStaticCheckObjects ;
150
149
} else {
151
- for ($ index = 0 ; $ index < count ($ requiredChecksNames ); $ index ++) {
152
- if (in_array ($ requiredChecksNames [$ index ], array_keys ($ this ->allStaticCheckObjects ))) {
153
- $ this ->staticCheckObjects [$ requiredChecksNames [$ index ]] =
154
- $ this ->allStaticCheckObjects [$ requiredChecksNames [$ index ]];
155
- } else {
156
- $ invalidCheckNames [] = $ requiredChecksNames [$ index ];
157
- }
158
- }
159
- }
160
-
161
- if (!empty ($ invalidCheckNames )) {
162
- throw new InvalidArgumentException (
163
- 'Invalid static check script(s): ' . implode (', ' , $ invalidCheckNames ) . '. '
164
- );
150
+ $ this ->validateTestNames ($ requiredChecksNames );
165
151
}
166
152
167
153
if ($ input ->getOption ('path ' )) {
@@ -175,6 +161,30 @@ private function validateInput(InputInterface $input)
175
161
}
176
162
}
177
163
164
+ /**
165
+ * Validates that all passed in static-check names match an existing static check
166
+ * @param string[] $requiredChecksNames
167
+ * @return void
168
+ */
169
+ private function validateTestNames ($ requiredChecksNames )
170
+ {
171
+ $ invalidCheckNames = [];
172
+ for ($ index = 0 ; $ index < count ($ requiredChecksNames ); $ index ++) {
173
+ if (in_array ($ requiredChecksNames [$ index ], array_keys ($ this ->allStaticCheckObjects ))) {
174
+ $ this ->staticCheckObjects [$ requiredChecksNames [$ index ]] =
175
+ $ this ->allStaticCheckObjects [$ requiredChecksNames [$ index ]];
176
+ } else {
177
+ $ invalidCheckNames [] = $ requiredChecksNames [$ index ];
178
+ }
179
+ }
180
+
181
+ if (!empty ($ invalidCheckNames )) {
182
+ throw new InvalidArgumentException (
183
+ 'Invalid static check script(s): ' . implode (', ' , $ invalidCheckNames ) . '. '
184
+ );
185
+ }
186
+ }
187
+
178
188
/**
179
189
* Parses and sets local ruleSet. If not found, simply returns and lets script continue.
180
190
* @return void;
0 commit comments