| Conditions | 11 |
| Paths | 30 |
| Total Lines | 68 |
| Code Lines | 41 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 47 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 48 | { |
||
| 49 | $start = microtime(true); |
||
| 50 | |||
| 51 | $this->getContainer()->get('ez_migration_bundle.step_executed_listener.tracing')->setOutput($output); |
||
| 52 | |||
| 53 | $workflowService = $this->getWorkflowService(); |
||
| 54 | |||
| 55 | $workflowName = $input->getOption('workflow'); |
||
| 56 | if ($workflowName != null) { |
||
| 57 | $suspendedWorkflow = $workflowService->getWorkflow($workflowName); |
||
|
|
|||
| 58 | if (!$suspendedWorkflow) { |
||
| 59 | throw new \Exception("Workflow '$workflowName' not found"); |
||
| 60 | } |
||
| 61 | if ($suspendedWorkflow->status != Migration::STATUS_SUSPENDED) { |
||
| 62 | throw new \Exception("Workflow '$workflowName' is not suspended, can not resume it"); |
||
| 63 | } |
||
| 64 | |||
| 65 | $suspendedWorkflows = array($suspendedWorkflow); |
||
| 66 | } else { |
||
| 67 | $suspendedWorkflows = $workflowService->getWorkflowsByStatus(Migration::STATUS_SUSPENDED); |
||
| 68 | }; |
||
| 69 | |||
| 70 | $output->writeln('<info>Found ' . count($suspendedWorkflows) . ' suspended workflows</info>'); |
||
| 71 | |||
| 72 | if (!count($suspendedWorkflows)) { |
||
| 73 | $output->writeln('Nothing to do'); |
||
| 74 | return 0; |
||
| 75 | } |
||
| 76 | |||
| 77 | // ask user for confirmation to make changes |
||
| 78 | if ($input->isInteractive() && !$input->getOption('no-interaction')) { |
||
| 79 | $dialog = $this->getHelperSet()->get('dialog'); |
||
| 80 | if (!$dialog->askConfirmation( |
||
| 81 | $output, |
||
| 82 | '<question>Careful, the database will be modified. Do you want to continue Y/N ?</question>', |
||
| 83 | false |
||
| 84 | ) |
||
| 85 | ) { |
||
| 86 | $output->writeln('<error>Workflow resuming cancelled!</error>'); |
||
| 87 | return 0; |
||
| 88 | } |
||
| 89 | } |
||
| 90 | |||
| 91 | $executed = 0; |
||
| 92 | $failed = 0; |
||
| 93 | |||
| 94 | foreach($suspendedWorkflows as $suspendedWorkflow) { |
||
| 95 | $output->writeln("<info>Resuming {$suspendedWorkflow->name}</info>"); |
||
| 96 | |||
| 97 | try { |
||
| 98 | $workflowService->resumeWorkflow($suspendedWorkflow, !$input->getOption('no-transactions')); |
||
| 99 | $executed++; |
||
| 100 | } catch (\Exception $e) { |
||
| 101 | $output->writeln("\n<error>Workflow failed! Reason: " . $e->getMessage() . "</error>\n"); |
||
| 102 | $failed++; |
||
| 103 | } |
||
| 104 | } |
||
| 105 | |||
| 106 | $time = microtime(true) - $start; |
||
| 107 | $output->writeln("Resumed $executed workflows, failed $failed"); |
||
| 108 | $output->writeln("Time taken: ".sprintf('%.2f', $time)." secs, memory: ".sprintf('%.2f', (memory_get_peak_usage(true) / 1000000)). ' MB'); |
||
| 109 | |||
| 110 | if ($failed) { |
||
| 111 | return 2; |
||
| 112 | } |
||
| 113 | |||
| 114 | return 0; |
||
| 115 | } |
||
| 117 |