|
5 | 5 | namespace Arkitect\CLI\Command; |
6 | 6 |
|
7 | 7 | use Arkitect\CLI\Baseline; |
8 | | -use Arkitect\CLI\Config; |
| 8 | +use Arkitect\CLI\ConfigBuilder; |
9 | 9 | use Arkitect\CLI\Printer\PrinterFactory; |
10 | 10 | use Arkitect\CLI\Progress\DebugProgress; |
11 | 11 | use Arkitect\CLI\Progress\ProgressBarProgress; |
|
16 | 16 | use Symfony\Component\Console\Input\InputOption; |
17 | 17 | use Symfony\Component\Console\Output\ConsoleOutputInterface; |
18 | 18 | use Symfony\Component\Console\Output\OutputInterface; |
19 | | -use Webmozart\Assert\Assert; |
20 | 19 |
|
21 | 20 | class Check extends Command |
22 | 21 | { |
@@ -123,18 +122,21 @@ protected function execute(InputInterface $input, OutputInterface $output): int |
123 | 122 |
|
124 | 123 | $this->printHeadingLine($output); |
125 | 124 |
|
126 | | - $printer = (new PrinterFactory())->create($format); |
| 125 | + $config = ConfigBuilder::loadFromFile($rulesFilename) |
| 126 | + ->stopOnFailure($stopOnFailure) |
| 127 | + ->targetPhpVersion(TargetPhpVersion::create($phpVersion)) |
| 128 | + ->baselineFilePath(Baseline::resolveFilePath($useBaseline, self::DEFAULT_BASELINE_FILENAME)) |
| 129 | + ->ignoreBaselineLinenumbers($ignoreBaselineLinenumbers) |
| 130 | + ->skipBaseline($skipBaseline) |
| 131 | + ->format($format); |
127 | 132 |
|
128 | | - $progress = $verbose ? new DebugProgress($output) : new ProgressBarProgress($output); |
| 133 | + $printer = PrinterFactory::create($config->getFormat()); |
129 | 134 |
|
130 | | - $baseline = Baseline::create($skipBaseline, $useBaseline, self::DEFAULT_BASELINE_FILENAME); |
| 135 | + $progress = $verbose ? new DebugProgress($output) : new ProgressBarProgress($output); |
131 | 136 |
|
132 | | - $config = ConfigBuilder::loadFromFile($rulesFilename); |
133 | | - $config->stopOnFailure($stopOnFailure); |
134 | | - $config->targetPhpVersion(TargetPhpVersion::create($phpVersion)); |
135 | | - $config->ignoreBaselineLinenumbers($ignoreBaselineLinenumbers); |
| 137 | + $baseline = Baseline::create($config->isSkipBaseline(), $config->getBaselineFilePath()); |
136 | 138 |
|
137 | | - $baseline->getFilename() && $output->writeln("Baseline file '{$baseline->getFilename()}' found"); |
| 139 | + null !== $config->getBaselineFilePath() && $output->writeln("Baseline file '{$config->getBaselineFilePath()}' found"); |
138 | 140 | $output->writeln("Config file '$rulesFilename' found\n"); |
139 | 141 |
|
140 | 142 | $runner = new Runner(); |
@@ -192,24 +194,3 @@ protected function printExecutionTime(OutputInterface $output, float $startTime) |
192 | 194 | $output->writeln("⏱️ Execution time: $executionTime\n"); |
193 | 195 | } |
194 | 196 | } |
195 | | - |
196 | | -class ConfigBuilder |
197 | | -{ |
198 | | - public static function loadFromFile(string $filePath): Config |
199 | | - { |
200 | | - Assert::file($filePath, "Config file '$filePath' not found"); |
201 | | - |
202 | | - $config = new Config(); |
203 | | - |
204 | | - \Closure::fromCallable(function () use ($config, $filePath): ?bool { |
205 | | - /** @psalm-suppress UnresolvableInclude $config */ |
206 | | - $configFunction = require $filePath; |
207 | | - |
208 | | - Assert::isCallable($configFunction); |
209 | | - |
210 | | - return $configFunction($config); |
211 | | - })(); |
212 | | - |
213 | | - return $config; |
214 | | - } |
215 | | -} |
0 commit comments