|
18 | 18 |
|
19 | 19 | namespace FastForward\DevTools\Console\Command; |
20 | 20 |
|
| 21 | +use Composer\Command\BaseCommand; |
| 22 | +use FastForward\DevTools\Process\ProcessBuilderInterface; |
| 23 | +use FastForward\DevTools\Process\ProcessQueueInterface; |
| 24 | +use Symfony\Component\Config\FileLocatorInterface; |
21 | 25 | use Symfony\Component\Console\Attribute\AsCommand; |
22 | 26 | use Symfony\Component\Console\Input\InputInterface; |
23 | 27 | use Symfony\Component\Console\Input\InputOption; |
24 | 28 | use Symfony\Component\Console\Output\OutputInterface; |
25 | | -use Symfony\Component\Process\Process; |
26 | 29 |
|
27 | 30 | /** |
28 | 31 | * Represents the command responsible for checking and fixing code style issues. |
|
33 | 36 | description: 'Checks and fixes code style issues using EasyCodingStandard and Composer Normalize.', |
34 | 37 | help: 'This command runs EasyCodingStandard and Composer Normalize to check and fix code style issues.' |
35 | 38 | )] |
36 | | -final class CodeStyleCommand extends AbstractCommand |
| 39 | +final class CodeStyleCommand extends BaseCommand |
37 | 40 | { |
38 | 41 | /** |
39 | 42 | * @var string the default configuration file used for EasyCodingStandard |
40 | 43 | */ |
41 | 44 | public const string CONFIG = 'ecs.php'; |
42 | 45 |
|
| 46 | + /** |
| 47 | + * Constructs a new command instance responsible for orchestrating code style checks. |
| 48 | + * |
| 49 | + * The provided collaborators SHALL be used to locate the ECS configuration, |
| 50 | + * build process definitions, and execute the resulting process queue. These |
| 51 | + * dependencies MUST be valid service instances capable of supporting the |
| 52 | + * command lifecycle expected by this class. |
| 53 | + * |
| 54 | + * @param FileLocatorInterface $fileLocator locates the configuration file required by EasyCodingStandard |
| 55 | + * @param ProcessBuilderInterface $processBuilder builds the process instances used to execute Composer and ECS commands |
| 56 | + * @param ProcessQueueInterface $processQueue queues and executes the generated processes in the required order |
| 57 | + */ |
| 58 | + public function __construct( |
| 59 | + private readonly FileLocatorInterface $fileLocator, |
| 60 | + private readonly ProcessBuilderInterface $processBuilder, |
| 61 | + private readonly ProcessQueueInterface $processQueue, |
| 62 | + ) { |
| 63 | + parent::__construct(); |
| 64 | + } |
| 65 | + |
43 | 66 | /** |
44 | 67 | * Configures the current command. |
45 | 68 | * |
@@ -74,20 +97,30 @@ protected function execute(InputInterface $input, OutputInterface $output): int |
74 | 97 | { |
75 | 98 | $output->writeln('<info>Running code style checks and fixes...</info>'); |
76 | 99 |
|
77 | | - $command = new Process(['composer', 'update', '--lock', '--quiet']); |
| 100 | + $composerUpdate = $this->processBuilder |
| 101 | + ->withArgument('--lock') |
| 102 | + ->withArgument('--quiet') |
| 103 | + ->build('composer update'); |
| 104 | + |
| 105 | + $composerNormalize = $this->processBuilder |
| 106 | + ->withArgument('--ansi') |
| 107 | + ->withArgument($input->getOption('fix') ? '--quiet' : '--dry-run') |
| 108 | + ->build('composer normalize'); |
78 | 109 |
|
79 | | - parent::runProcess($command, $output); |
| 110 | + $processBuilder = $this->processBuilder |
| 111 | + ->withArgument('--no-progress-bar') |
| 112 | + ->withArgument('--config', $this->fileLocator->locate(self::CONFIG)); |
80 | 113 |
|
81 | | - $command = new Process(['composer', 'normalize', $input->getOption('fix') ? '--quiet' : '--dry-run']); |
| 114 | + if ($input->getOption('fix')) { |
| 115 | + $processBuilder = $processBuilder->withArgument('--fix'); |
| 116 | + } |
82 | 117 |
|
83 | | - parent::runProcess($command, $output); |
| 118 | + $ecs = $processBuilder->build('vendor/bin/ecs'); |
84 | 119 |
|
85 | | - $command = new Process([ |
86 | | - $this->getAbsolutePath('vendor/bin/ecs'), |
87 | | - '--config=' . parent::getConfigFile(self::CONFIG), |
88 | | - $input->getOption('fix') ? '--fix' : '--clear-cache', |
89 | | - ]); |
| 120 | + $this->processQueue->add($composerUpdate); |
| 121 | + $this->processQueue->add($composerNormalize); |
| 122 | + $this->processQueue->add($ecs); |
90 | 123 |
|
91 | | - return parent::runProcess($command, $output); |
| 124 | + return $this->processQueue->run($output); |
92 | 125 | } |
93 | 126 | } |
0 commit comments