Conditions | 27 |
Paths | 409 |
Total Lines | 114 |
Code Lines | 74 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
52 | protected function execute(InputInterface $input, OutputInterface $output) |
||
53 | { |
||
54 | if (!$input->getOption('delete') && !$input->getOption('info')) { |
||
55 | throw new \InvalidArgumentException('You must specify whether you want to --delete or --info the specified workflow.'); |
||
56 | } |
||
57 | |||
58 | $workflowService = $this->getWorkflowService(); |
||
59 | $workflowNameOrPath = $input->getArgument('workflow'); |
||
60 | |||
61 | if ($input->getOption('info')) { |
||
62 | $output->writeln(''); |
||
63 | |||
64 | $workflow = $workflowService->getWorkflow($workflowNameOrPath); |
||
65 | if ($workflow == null) { |
||
66 | throw new \InvalidArgumentException(sprintf('The workflow "%s" does not exist in the database table.', $workflowNameOrPath)); |
||
|
|||
67 | } |
||
68 | |||
69 | switch ($workflow->status) { |
||
70 | case Migration::STATUS_DONE: |
||
71 | $status = '<info>executed</info>'; |
||
72 | break; |
||
73 | case Migration::STATUS_STARTED: |
||
74 | $status = '<comment>execution started</comment>'; |
||
75 | break; |
||
76 | case Migration::STATUS_TODO: |
||
77 | // bold to-migrate! |
||
78 | $status = '<error>not executed</error>'; |
||
79 | break; |
||
80 | case Migration::STATUS_SKIPPED: |
||
81 | $status = '<comment>skipped</comment>'; |
||
82 | break; |
||
83 | case Migration::STATUS_PARTIALLY_DONE: |
||
84 | $status = '<comment>partially executed</comment>'; |
||
85 | break; |
||
86 | case Migration::STATUS_SUSPENDED: |
||
87 | $status = '<comment>suspended</comment>'; |
||
88 | break; |
||
89 | case Migration::STATUS_FAILED: |
||
90 | $status = '<error>failed</error>'; |
||
91 | break; |
||
92 | } |
||
93 | |||
94 | $output->writeln('<info>Workflow: ' . $workflow->name . '</info>'); |
||
95 | $output->writeln('Status: ' . $status); |
||
96 | $output->writeln('Executed on: <info>' . ($workflow->executionDate != null ? date("Y-m-d H:i:s", $workflow->executionDate) : '--'). '</info>'); |
||
97 | $output->writeln('Execution notes: <info>' . $workflow->executionError . '</info>'); |
||
98 | $output->writeln('Signal: <info>' . $workflow->signalName . '</info>'); |
||
99 | |||
100 | if ($workflow->status == Migration::STATUS_SUSPENDED) { |
||
101 | /// @todo decode the suspension context: date, step, ... |
||
102 | } |
||
103 | |||
104 | $output->writeln('Definition path: <info>' . $workflow->path . '</info>'); |
||
105 | $output->writeln('Definition md5: <info>' . $workflow->md5 . '</info>'); |
||
106 | |||
107 | if ($workflow->path != '') { |
||
108 | // q: what if we have a loader which does not work with is_file? We could probably remove this check... |
||
109 | if (is_file($workflow->path)) { |
||
110 | try { |
||
111 | $workflowDefinitionCollection = $workflowService->getWorkflowsDefinitions(array($workflow->path)); |
||
112 | if (count($workflowDefinitionCollection)) { |
||
113 | $workflowDefinition = reset($workflowDefinitionCollection); |
||
114 | $workflowDefinition = $workflowService->parseWorkflowDefinition($workflowDefinition); |
||
115 | |||
116 | if ($workflowDefinition->status != MigrationDefinition::STATUS_PARSED) { |
||
117 | $output->writeln('Definition error: <error>' . $workflowDefinition->parsingError . '</error>'); |
||
118 | } |
||
119 | |||
120 | if (md5($workflowDefinition->rawDefinition) != $workflow->md5) { |
||
121 | $output->writeln('Notes: <comment>The workflow definition file has now a different checksum</comment>'); |
||
122 | } |
||
123 | |||
124 | $output->writeln('Switch User: <info>' . (($workflowDefinition->runAs === false) ? '-' : $workflowDefinition->runAs) . '</info>'); |
||
125 | $output->writeln('Use transaction: <info>' . ($workflowDefinition->useTransaction ? 'Y' : 'N') . '</info>'); |
||
126 | |||
127 | } else { |
||
128 | $output->writeln('Definition error: <error>The workflow definition file can not be loaded</error>'); |
||
129 | } |
||
130 | } catch (\Exception $e) { |
||
131 | /// @todo one day we should be able to limit the kind of exceptions we have to catch here... |
||
132 | $output->writeln('Definition parsing error: <error>' . $e->getMessage() . '</error>'); |
||
133 | } |
||
134 | } else { |
||
135 | $output->writeln('Definition error: <error>The workflow definition file can not be found any more</error>'); |
||
136 | } |
||
137 | } |
||
138 | |||
139 | $output->writeln(''); |
||
140 | return; |
||
141 | } |
||
142 | |||
143 | // ask user for confirmation to make changes |
||
144 | if ($input->isInteractive() && !$input->getOption('no-interaction')) { |
||
145 | $dialog = $this->getHelperSet()->get('dialog'); |
||
146 | if (!$dialog->askConfirmation( |
||
147 | $output, |
||
148 | '<question>Careful, the database will be modified. Do you want to continue Y/N ?</question>', |
||
149 | false |
||
150 | ) |
||
151 | ) { |
||
152 | $output->writeln('<error>Workflow change cancelled!</error>'); |
||
153 | return 0; |
||
154 | } |
||
155 | } |
||
156 | |||
157 | if ($input->getOption('delete')) { |
||
158 | $workflow = $workflowService->getWorkflow($workflowNameOrPath); |
||
159 | if ($workflow == null) { |
||
160 | throw new \InvalidArgumentException(sprintf('The workflow "%s" does not exist in the database table.', $workflowNameOrPath)); |
||
161 | } |
||
162 | |||
163 | $workflowService->deleteWorkflow($workflow); |
||
164 | |||
165 | return; |
||
166 | } |
||
169 |