Conditions | 13 |
Paths | 2 |
Total Lines | 62 |
Code Lines | 36 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
47 | protected function execute(InputInterface $input, OutputInterface $output) |
||
48 | { |
||
49 | $update_all = (bool)$input->getOption('update'); |
||
50 | $latest = (bool)$input->getOption('latest'); |
||
51 | |||
52 | $modx = $this->console->loadMODX(); |
||
53 | $modxPackages = new MODXPackages($modx, $this->consoleUserInteractionHandler); |
||
54 | |||
55 | $io = new SymfonyStyle($input, $output); |
||
56 | |||
57 | |||
58 | $io->title('Installed MODX Extras'); |
||
59 | |||
60 | $current_packages = $modxPackages->getList(100); |
||
61 | $packages = []; |
||
62 | |||
63 | if ($current_packages['total'] > 0) { |
||
64 | foreach ($current_packages['packages'] as $package) { |
||
65 | $update = 'No'; |
||
66 | if (isset($package['updates']) && isset($package['updates']['count']) && $package['updates']['count'] > 0) { |
||
67 | $update = ''; |
||
68 | foreach ($package['updates']['versions'] as $key => $version) { |
||
69 | $update .= ', ' . $version['version']; |
||
70 | } |
||
71 | $update = 'Yes ' . trim(trim($update, ',')); |
||
72 | } |
||
73 | |||
74 | $installed = 'No'; |
||
75 | if (!is_null($package['installed']) && $package['installed'] != '0000-00-00 00:00:00') { |
||
76 | $installed = utf8_encode(date($modx->getOption('manager_date_format') . ', ' . $modx->getOption('manager_time_format'), strtotime($package['installed']))); |
||
77 | } |
||
78 | |||
79 | if ($update_all && $update != 'No') { |
||
80 | // update |
||
81 | $output->writeln('### Orchestrator is attempting to update the MODX Extra Package: ' . $package['signature'] .' ###'); |
||
82 | |||
83 | try { |
||
84 | $modxPackages->requirePackage($package['signature'], $latest); |
||
85 | |||
|
|||
86 | } catch (TransportNotFoundException $exception) { |
||
87 | $output->writeln('Error: '.$exception->getMessage()); |
||
88 | |||
89 | } catch (TransportException $exception) { |
||
90 | $output->writeln('Error: '.$exception->getMessage()); |
||
91 | } |
||
92 | } |
||
93 | |||
94 | $packages[] = [ |
||
95 | $package['package_name'], |
||
96 | $package['signature'], |
||
97 | $package['metadata']['version'], |
||
98 | $installed, |
||
99 | $update |
||
100 | ]; |
||
101 | } |
||
102 | } |
||
103 | $table_header = ['Name', 'Signature', 'Version', 'Installed', 'Update Available']; |
||
104 | |||
105 | $io->table($table_header, $packages); |
||
106 | |||
107 | |||
108 | $output->writeln($this->getRunStats()); |
||
109 | } |
||
111 |