|
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 | *
|
@@ -81,6 +88,7 @@ protected function configure()
|
81 | 88 | protected function execute(InputInterface $input, OutputInterface $output)
|
82 | 89 | {
|
83 | 90 | $this->ioStyle = new SymfonyStyle($input, $output);
|
| 91 | + $this->parseRulesetJson(); |
84 | 92 | try {
|
85 | 93 | $this->validateInput($input);
|
86 | 94 | } catch (InvalidArgumentException $e) {
|
@@ -133,8 +141,10 @@ private function validateInput(InputInterface $input)
|
133 | 141 | $this->staticCheckObjects = [];
|
134 | 142 | $requiredChecksNames = $input->getArgument('names');
|
135 | 143 | $invalidCheckNames = [];
|
136 |
| - // Found user required static check script(s) to run, |
137 |
| - // If no static check name is supplied, run all static check scripts |
| 144 | + // Build list of static check names to run. |
| 145 | + if (empty($requiredChecksNames) && isset($this->ruleSet['tests'])) { |
| 146 | + $requiredChecksNames = $this->ruleSet['tests']; |
| 147 | + } |
138 | 148 | if (empty($requiredChecksNames)) {
|
139 | 149 | $this->staticCheckObjects = $this->allStaticCheckObjects;
|
140 | 150 | } else {
|
@@ -164,4 +174,19 @@ private function validateInput(InputInterface $input)
|
164 | 174 | );
|
165 | 175 | }
|
166 | 176 | }
|
| 177 | + |
| 178 | + /** |
| 179 | + * Parses and sets local ruleSet. If not found, simply returns and lets script continue. |
| 180 | + * @return void; |
| 181 | + */ |
| 182 | + private function parseRulesetJson() |
| 183 | + { |
| 184 | + $pathToRuleset = FW_BP . DIRECTORY_SEPARATOR . "staticRuleset.json"; |
| 185 | + if ($pathToRuleset === null) { |
| 186 | + $this->ioStyle->text("No ruleset under $pathToRuleset" . PHP_EOL); |
| 187 | + return; |
| 188 | + } |
| 189 | + $this->ioStyle->text("Using ruleset under $pathToRuleset" . PHP_EOL); |
| 190 | + $this->ruleSet = json_decode(file_get_contents($pathToRuleset), true); |
| 191 | + } |
167 | 192 | }
|
0 commit comments