| Conditions | 15 |
| Paths | 135 |
| Total Lines | 93 |
| Code Lines | 68 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
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 |
||
| 26 | public function execute(InputInterface $input, OutputInterface $output) |
||
| 27 | { |
||
| 28 | $workflowService = $this->getWorkflowService(); |
||
| 29 | |||
| 30 | $workflows = $workflowService->getWorkflows(); |
||
|
|
|||
| 31 | |||
| 32 | if (!count($workflows)) { |
||
| 33 | $output->writeln('<info>No workflows found</info>'); |
||
| 34 | return 0; |
||
| 35 | } |
||
| 36 | |||
| 37 | $summary = array( |
||
| 38 | Migration::STATUS_TODO => array('To do', 0), |
||
| 39 | Migration::STATUS_STARTED => array('Started', 0), |
||
| 40 | Migration::STATUS_DONE => array('Done', 0), |
||
| 41 | Migration::STATUS_SUSPENDED => array('Suspended', 0), |
||
| 42 | Migration::STATUS_FAILED => array('Failed', 0), |
||
| 43 | Migration::STATUS_SKIPPED => array('Skipped', 0), |
||
| 44 | Migration::STATUS_PARTIALLY_DONE => array('Partially done', 0), |
||
| 45 | ); |
||
| 46 | |||
| 47 | $i = 1; |
||
| 48 | foreach ($workflows as $workflow) { |
||
| 49 | |||
| 50 | if (!isset($summary[$workflow->status])) { |
||
| 51 | $summary[$workflow->status] = array($workflow->status, 0); |
||
| 52 | } |
||
| 53 | $summary[$workflow->status][1]++; |
||
| 54 | if ($input->getOption('summary')) { |
||
| 55 | continue; |
||
| 56 | } |
||
| 57 | |||
| 58 | switch ($workflow->status) { |
||
| 59 | case Migration::STATUS_DONE: |
||
| 60 | $status = '<info>executed</info>'; |
||
| 61 | break; |
||
| 62 | case Migration::STATUS_STARTED: |
||
| 63 | $status = '<comment>execution started</comment>'; |
||
| 64 | break; |
||
| 65 | case Migration::STATUS_TODO: |
||
| 66 | // bold to-migrate! |
||
| 67 | $status = '<error>not executed</error>'; |
||
| 68 | break; |
||
| 69 | case Migration::STATUS_SKIPPED: |
||
| 70 | $status = '<comment>skipped</comment>'; |
||
| 71 | break; |
||
| 72 | case Migration::STATUS_PARTIALLY_DONE: |
||
| 73 | $status = '<comment>partially executed</comment>'; |
||
| 74 | break; |
||
| 75 | case Migration::STATUS_SUSPENDED: |
||
| 76 | $status = '<comment>suspended</comment>'; |
||
| 77 | break; |
||
| 78 | case Migration::STATUS_FAILED: |
||
| 79 | $status = '<error>failed</error>'; |
||
| 80 | break; |
||
| 81 | } |
||
| 82 | |||
| 83 | switch ($workflow->status) { |
||
| 84 | case Migration::STATUS_FAILED: |
||
| 85 | $name = '<error>' . $workflow->name . '</error>'; |
||
| 86 | break; |
||
| 87 | default: |
||
| 88 | $name = $workflow->name; |
||
| 89 | } |
||
| 90 | |||
| 91 | $data[] = array( |
||
| 92 | $i++, |
||
| 93 | $name, |
||
| 94 | $workflow->signalName, |
||
| 95 | $status, |
||
| 96 | $workflow->executionDate != null ? date("Y-m-d H:i:s", $workflow->executionDate) : '', |
||
| 97 | $workflow->executionError, |
||
| 98 | ); |
||
| 99 | |||
| 100 | } |
||
| 101 | |||
| 102 | if ($input->getOption('summary')) { |
||
| 103 | $output->writeln("\n <info>==</info> Workflows Summary\n"); |
||
| 104 | // do not print info about the not yet supported case |
||
| 105 | unset($summary[Migration::STATUS_PARTIALLY_DONE]); |
||
| 106 | $data = $summary; |
||
| 107 | $headers = array('Status', 'Count'); |
||
| 108 | } else { |
||
| 109 | $headers = array('#', 'Workflow', 'Signal', 'Status', 'Executed on', 'Notes'); |
||
| 110 | } |
||
| 111 | |||
| 112 | $table = new Table($output); |
||
| 113 | $table |
||
| 114 | ->setHeaders($headers) |
||
| 115 | ->setRows($data); |
||
| 116 | $table->render(); |
||
| 117 | |||
| 118 | return 0; |
||
| 119 | } |
||
| 121 |