|
22 | 22 | use Phauthentic\BcCheck\Config\ConfigurationException; |
23 | 23 | use Phauthentic\BcCheck\Config\ConfigurationLoader; |
24 | 24 | use Phauthentic\BcCheck\DependencyInjection\ContainerFactory; |
| 25 | +use Phauthentic\BcCheck\Factory\OutputFormatterFactory; |
25 | 26 | use Phauthentic\BcCheck\Git\GitException; |
26 | | -use Phauthentic\BcCheck\Output\CheckstyleOutputFormatter; |
27 | | -use Phauthentic\BcCheck\Output\GithubActionsFormatter; |
28 | | -use Phauthentic\BcCheck\Output\GitlabCodeQualityOutputFormatter; |
29 | | -use Phauthentic\BcCheck\Output\JsonOutputFormatter; |
30 | | -use Phauthentic\BcCheck\Output\JunitOutputFormatter; |
31 | | -use Phauthentic\BcCheck\Output\MarkdownOutputFormatter; |
32 | | -use Phauthentic\BcCheck\Output\OutputFormatterInterface; |
33 | | -use Phauthentic\BcCheck\Output\SarifOutputFormatter; |
34 | | -use Phauthentic\BcCheck\Output\TextOutputFormatter; |
35 | 27 | use Symfony\Component\Console\Attribute\AsCommand; |
36 | 28 | use Symfony\Component\Console\Command\Command; |
37 | 29 | use Symfony\Component\Console\Input\InputArgument; |
|
45 | 37 | )] |
46 | 38 | final class CheckCommand extends Command |
47 | 39 | { |
48 | | - private const FORMAT_TEXT = 'text'; |
49 | | - private const FORMAT_JSON = 'json'; |
50 | | - private const FORMAT_MARKDOWN = 'markdown'; |
51 | | - private const FORMAT_GITHUB = 'github-actions'; |
52 | | - private const FORMAT_SARIF = 'sarif'; |
53 | | - private const FORMAT_CHECKSTYLE = 'checkstyle'; |
54 | | - private const FORMAT_JUNIT = 'junit'; |
55 | | - private const FORMAT_GITLAB = 'gitlab'; |
| 40 | + public function __construct( |
| 41 | + private readonly OutputFormatterFactory $formatterFactory = new OutputFormatterFactory(), |
| 42 | + ) { |
| 43 | + parent::__construct(); |
| 44 | + } |
56 | 45 |
|
57 | 46 | protected function configure(): void |
58 | 47 | { |
@@ -83,17 +72,10 @@ protected function configure(): void |
83 | 72 | 'f', |
84 | 73 | InputOption::VALUE_REQUIRED, |
85 | 74 | sprintf( |
86 | | - 'Output format (%s, %s, %s, %s, %s, %s, %s, %s)', |
87 | | - self::FORMAT_TEXT, |
88 | | - self::FORMAT_JSON, |
89 | | - self::FORMAT_MARKDOWN, |
90 | | - self::FORMAT_GITHUB, |
91 | | - self::FORMAT_SARIF, |
92 | | - self::FORMAT_CHECKSTYLE, |
93 | | - self::FORMAT_JUNIT, |
94 | | - self::FORMAT_GITLAB, |
| 75 | + 'Output format (%s)', |
| 76 | + implode(', ', $this->formatterFactory->getSupportedFormats()), |
95 | 77 | ), |
96 | | - self::FORMAT_TEXT, |
| 78 | + OutputFormatterFactory::FORMAT_TEXT, |
97 | 79 | ) |
98 | 80 | ->addOption( |
99 | 81 | 'show-files', |
@@ -140,7 +122,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int |
140 | 122 | } |
141 | 123 |
|
142 | 124 | // Get formatter |
143 | | - $formatter = $this->getFormatter($format); |
| 125 | + $formatter = $this->formatterFactory->create($format); |
144 | 126 |
|
145 | 127 | // Build container with services |
146 | 128 | try { |
@@ -205,18 +187,4 @@ private function loadConfiguration(?string $configPath): Configuration |
205 | 187 |
|
206 | 188 | return $loader->createDefault(); |
207 | 189 | } |
208 | | - |
209 | | - private function getFormatter(string $format): OutputFormatterInterface |
210 | | - { |
211 | | - return match ($format) { |
212 | | - self::FORMAT_JSON => new JsonOutputFormatter(), |
213 | | - self::FORMAT_MARKDOWN => new MarkdownOutputFormatter(), |
214 | | - self::FORMAT_GITHUB => new GithubActionsFormatter(), |
215 | | - self::FORMAT_SARIF => new SarifOutputFormatter(), |
216 | | - self::FORMAT_CHECKSTYLE => new CheckstyleOutputFormatter(), |
217 | | - self::FORMAT_JUNIT => new JunitOutputFormatter(), |
218 | | - self::FORMAT_GITLAB => new GitlabCodeQualityOutputFormatter(), |
219 | | - default => new TextOutputFormatter(), |
220 | | - }; |
221 | | - } |
222 | 190 | } |
0 commit comments