2222
2323class StaticChecksCommand extends Command
2424{
25+ /**
26+ * Associative array containing static ruleset properties.
27+ *
28+ * @var array
29+ */
30+ private $ ruleSet ;
31+
2532 /**
2633 * Pool of all existing static check objects
2734 *
@@ -132,26 +139,15 @@ private function validateInput(InputInterface $input)
132139 {
133140 $ this ->staticCheckObjects = [];
134141 $ 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+ }
138147 if (empty ($ requiredChecksNames )) {
139148 $ this ->staticCheckObjects = $ this ->allStaticCheckObjects ;
140149 } 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 );
155151 }
156152
157153 if ($ input ->getOption ('path ' )) {
@@ -164,4 +160,48 @@ private function validateInput(InputInterface $input)
164160 );
165161 }
166162 }
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+ }
167207}
0 commit comments