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