Skip to content

Commit 2958a0e

Browse files
committed
refactor(commands): simplify command execution and update input handling
Signed-off-by: Felipe Sayão Lobato Abreu <github@mentordosnerds.com>
1 parent 40ec952 commit 2958a0e

File tree

4 files changed

+15
-45
lines changed

4 files changed

+15
-45
lines changed

src/Command/AbstractCommand.php

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
use RuntimeException;
2222
use Symfony\Component\Console\Helper\ProcessHelper;
2323
use Composer\Command\BaseCommand;
24-
use Symfony\Component\Console\Input\ArrayInput;
25-
use Symfony\Component\Console\Input\InputInterface;
24+
use Symfony\Component\Console\Input\StringInput;
2625
use Symfony\Component\Console\Output\OutputInterface;
2726
use Symfony\Component\Filesystem\Filesystem;
2827
use Symfony\Component\Filesystem\Path;
@@ -181,27 +180,17 @@ protected function getDevToolsFile(string $filename): string
181180
/**
182181
* Configures and executes a registered console command by name.
183182
*
184-
* The method MUST look up the command from the application and run it. It SHALL ignore generic
185-
* validation errors and route the custom input and output correctly.
183+
* The method MUST run the specified command with the provided input and output interfaces.
186184
*
187-
* @param string $commandName the name of the required command
188-
* @param array|InputInterface $input the input arguments or array definition
185+
* @param string $command the commandline name of the command to execute
189186
* @param OutputInterface $output the interface for buffering output
190187
*
191188
* @return int the status code resulting from the dispatched command
192189
*/
193-
protected function runCommand(string $commandName, array|InputInterface $input, OutputInterface $output): int
190+
protected function runCommand(string $command, OutputInterface $output): int
194191
{
195-
$application = $this->getApplication();
196-
197-
$command = $application->find($commandName);
198-
$command->ignoreValidationErrors();
199-
200-
if (\is_array($input)) {
201-
$input = new ArrayInput($input);
202-
}
203-
204-
return $command->run($input, $output);
192+
return $this->getApplication()
193+
->doRun(new StringInput($command), $output);
205194
}
206195

207196
/**

src/Command/ReportsCommand.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
6565
$results = [];
6666

6767
$output->writeln('<info>Generating API documentation on path: ' . $docsPath . '</info>');
68-
$results[] = $this->runCommand('docs', [
69-
'--target' => $docsPath,
70-
], $output);
68+
$results[] = $this->runCommand('docs --target=' . $docsPath, $output);
7169

7270
$output->writeln('<info>Generating test coverage report on path: ' . $coveragePath . '</info>');
73-
$results[] = $this->runCommand('tests', [
74-
'--coverage' => $coveragePath,
75-
], $output);
71+
$results[] = $this->runCommand('tests --coverage=' . $coveragePath, $output);
7672

7773
$output->writeln('<info>Frontpage generation completed!</info>');
7874

src/Command/StandardsCommand.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7070

7171
$results = [];
7272

73-
$results[] = $this->runCommand('refactor', $input, $output);
74-
$results[] = $this->runCommand('phpdoc', $input, $output);
75-
$results[] = $this->runCommand('code-style', $input, $output);
76-
$results[] = $this->runCommand('reports', $input, $output);
73+
$fix = $input->getOption('fix') ? '--fix' : '';
74+
75+
$results[] = $this->runCommand('refactor ' . $fix, $output);
76+
$results[] = $this->runCommand('phpdoc ' . $fix, $output);
77+
$results[] = $this->runCommand('code-style ' . $fix, $output);
78+
$results[] = $this->runCommand('reports', $output);
7779

7880
$output->writeln('<info>All code standards checks completed!</info>');
7981

src/Command/SyncCommand.php

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
use Composer\Factory;
2222
use Composer\Json\JsonManipulator;
2323
use Symfony\Component\Console\Input\InputInterface;
24-
use Symfony\Component\Console\Input\StringInput;
2524
use Symfony\Component\Console\Output\OutputInterface;
2625
use Symfony\Component\Filesystem\Path;
2726
use Symfony\Component\Finder\Finder;
@@ -75,7 +74,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7574
$this->copyEditorConfig();
7675
$this->copyDependabotConfig();
7776
$this->addRepositoryWikiGitSubmodule();
78-
$this->syncGitIgnore($output);
77+
$this->runCommand('gitignore', $output);
7978

8079
return self::SUCCESS;
8180
}
@@ -235,20 +234,4 @@ private function getGitRepositoryUrl(): string
235234

236235
return trim($process->getOutput());
237236
}
238-
239-
/**
240-
* Synchronizes .gitignore entries from dev-tools into the target project.
241-
*
242-
* This method merges canonical .gitignore entries from the dev-tools package
243-
* with the target project's existing .gitignore entries, then writes the merged result.
244-
*
245-
* @param OutputInterface $output
246-
*
247-
* @return void
248-
*/
249-
private function syncGitIgnore(OutputInterface $output): void
250-
{
251-
$this->getApplication()
252-
->doRun(new StringInput('gitignore'), $output);
253-
}
254237
}

0 commit comments

Comments
 (0)