22
22
23
23
class StaticChecksCommand extends Command
24
24
{
25
+ /**
26
+ * Associative array containing static ruleset properties.
27
+ *
28
+ * @var array
29
+ */
30
+ private $ ruleSet ;
31
+
25
32
/**
26
33
* Pool of all existing static check objects
27
34
*
@@ -132,26 +139,15 @@ private function validateInput(InputInterface $input)
132
139
{
133
140
$ this ->staticCheckObjects = [];
134
141
$ requiredChecksNames = $ input ->getArgument ('names ' );
135
- $ invalidCheckNames = [];
136
- // Found user required static check script(s) to run,
137
- // If no static check name is supplied, run all static check scripts
142
+ // Build list of static check names to run.
143
+ if (empty ($ requiredChecksNames )) {
144
+ $ this ->parseRulesetJson ();
145
+ $ requiredChecksNames = $ this ->ruleSet ['tests ' ] ?? null ;
146
+ }
138
147
if (empty ($ requiredChecksNames )) {
139
148
$ this ->staticCheckObjects = $ this ->allStaticCheckObjects ;
140
149
} else {
141
- for ($ index = 0 ; $ index < count ($ requiredChecksNames ); $ index ++) {
142
- if (in_array ($ requiredChecksNames [$ index ], array_keys ($ this ->allStaticCheckObjects ))) {
143
- $ this ->staticCheckObjects [$ requiredChecksNames [$ index ]] =
144
- $ this ->allStaticCheckObjects [$ requiredChecksNames [$ index ]];
145
- } else {
146
- $ invalidCheckNames [] = $ requiredChecksNames [$ index ];
147
- }
148
- }
149
- }
150
-
151
- if (!empty ($ invalidCheckNames )) {
152
- throw new InvalidArgumentException (
153
- 'Invalid static check script(s): ' . implode (', ' , $ invalidCheckNames ) . '. '
154
- );
150
+ $ this ->validateTestNames ($ requiredChecksNames );
155
151
}
156
152
157
153
if ($ input ->getOption ('path ' )) {
@@ -164,4 +160,48 @@ private function validateInput(InputInterface $input)
164
160
);
165
161
}
166
162
}
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
+
188
+ /**
189
+ * Parses and sets local ruleSet. If not found, simply returns and lets script continue.
190
+ * @return void;
191
+ */
192
+ private function parseRulesetJson ()
193
+ {
194
+ $ pathAddition = "/dev/tests/acceptance/ " ;
195
+ // MFTF is both NOT attached and no MAGENTO_BP defined in .env
196
+ if (MAGENTO_BP === FW_BP ) {
197
+ $ pathAddition = "/dev/ " ;
198
+ }
199
+ $ pathToRuleset = MAGENTO_BP . $ pathAddition . "staticRuleset.json " ;
200
+ if (!file_exists ($ pathToRuleset )) {
201
+ $ this ->ioStyle ->text ("No ruleset under $ pathToRuleset " . PHP_EOL );
202
+ return ;
203
+ }
204
+ $ this ->ioStyle ->text ("Using ruleset under $ pathToRuleset " . PHP_EOL );
205
+ $ this ->ruleSet = json_decode (file_get_contents ($ pathToRuleset ), true );
206
+ }
167
207
}
0 commit comments