|
10 | 10 |
|
11 | 11 | namespace OpenCodeModeling\CodeGenerator\Console;
|
12 | 12 |
|
13 |
| -use OpenCodeModeling\CodeGenerator\Config\Component; |
14 |
| -use OpenCodeModeling\CodeGenerator\Config\ComponentCollection; |
15 |
| -use OpenCodeModeling\CodeGenerator\Config\Config; |
16 |
| -use OpenCodeModeling\CodeGenerator\Config\WorkflowCollection; |
| 13 | +use OpenCodeModeling\CodeGenerator\Config; |
17 | 14 | use OpenCodeModeling\CodeGenerator\Config\WorkflowConfig;
|
| 15 | +use OpenCodeModeling\CodeGenerator\Console; |
18 | 16 | use OpenCodeModeling\CodeGenerator\Exception\RuntimeException;
|
19 | 17 | use OpenCodeModeling\CodeGenerator\Workflow\WorkflowContext;
|
20 | 18 | use OpenCodeModeling\CodeGenerator\Workflow\WorkflowEngine;
|
|
27 | 25 | */
|
28 | 26 | final class WorkflowCommand extends Command
|
29 | 27 | {
|
30 |
| - protected function configure() |
| 28 | + protected function configure(): void |
31 | 29 | {
|
32 | 30 | $this
|
33 | 31 | ->setName('ocmcg:workflow:run')
|
34 | 32 | ->setDescription('Executes workflow from configuration file to generate code');
|
35 | 33 | }
|
36 | 34 |
|
37 |
| - protected function execute(InputInterface $input, OutputInterface $output) |
| 35 | + protected function execute(InputInterface $input, OutputInterface $output): int |
38 | 36 | {
|
39 | 37 | /** @var WorkflowContext $workflowContext */
|
40 |
| - $workflowContext = $this->getHelper(\OpenCodeModeling\CodeGenerator\Console\WorkflowContext::class)->context(); |
| 38 | + $workflowContext = $this->getHelper(Console\WorkflowContext::class)->context(); |
41 | 39 |
|
42 | 40 | $config = $this->loadConfig($workflowContext);
|
43 | 41 |
|
44 |
| - if ($config instanceof WorkflowConfig |
45 |
| - || $config instanceof Component |
46 |
| - ) { |
| 42 | + if ($config instanceof Config\WorkflowConfig) { |
47 | 43 | $this->executeWorkflow($config, $workflowContext);
|
48 |
| - } elseif ($config instanceof WorkflowCollection |
49 |
| - || $config instanceof ComponentCollection |
50 |
| - ) { |
| 44 | + } elseif ($config instanceof Config\WorkflowCollection) { |
51 | 45 | foreach ($config as $workflowConfig) {
|
52 | 46 | $this->executeWorkflow($workflowConfig, $workflowContext);
|
53 | 47 | }
|
54 | 48 | } else {
|
55 | 49 | throw new RuntimeException(
|
56 |
| - \sprintf('$config must implement %s or %s', WorkflowConfig::class, WorkflowCollection::class) |
| 50 | + \sprintf( |
| 51 | + '$config must implement %s or %s', Config\WorkflowConfig::class, |
| 52 | + Config\WorkflowCollection::class |
| 53 | + ) |
57 | 54 | );
|
58 | 55 | }
|
59 | 56 |
|
60 | 57 | return 0;
|
61 | 58 | }
|
62 | 59 |
|
63 |
| - private function loadConfig(WorkflowContext $workflowContext): Config |
| 60 | + private function loadConfig(WorkflowContext $workflowContext): Config\Config |
64 | 61 | {
|
65 |
| - return $this->getHelper(\OpenCodeModeling\CodeGenerator\Console\Config::class)->resolver()->resolve($workflowContext); |
| 62 | + return $this->getHelper(Console\Config::class)->resolver()->resolve($workflowContext); |
66 | 63 | }
|
67 | 64 |
|
68 |
| - /** |
69 |
| - * @param WorkflowConfig|Component $config |
70 |
| - * @param WorkflowContext $workflowContext |
71 |
| - */ |
72 |
| - private function executeWorkflow($config, WorkflowContext $workflowContext): void |
| 65 | + private function executeWorkflow(WorkflowConfig $config, WorkflowContext $workflowContext): void |
73 | 66 | {
|
74 | 67 | $workflowEngine = new WorkflowEngine();
|
75 | 68 | $workflowEngine->run($workflowContext, ...$config->componentDescriptions());
|
|
0 commit comments