Conditions | 11 |
Paths | 20 |
Total Lines | 45 |
Code Lines | 31 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
78 | protected function execute(InputInterface $input, OutputInterface $output) { |
||
79 | $singleAppId = $input->getArgument('app-id'); |
||
80 | |||
81 | if ($singleAppId) { |
||
82 | $apps = array($singleAppId); |
||
83 | try { |
||
84 | $this->manager->getAppPath($singleAppId); |
||
|
|||
85 | } catch (\OCP\App\AppPathNotFoundException $e) { |
||
86 | $output->writeln($singleAppId . ' not installed'); |
||
87 | return 1; |
||
88 | } |
||
89 | |||
90 | } else if ($input->getOption('all') || $input->getOption('showonly')) { |
||
91 | $apps = \OC_App::getAllApps(); |
||
92 | } else { |
||
93 | $output->writeln("<error>Please specify an app to update or \"--all\" to update all updatable apps\"</error>"); |
||
94 | return 1; |
||
95 | } |
||
96 | |||
97 | $return = 0; |
||
98 | foreach ($apps as $appId) { |
||
99 | $newVersion = $this->installer->isUpdateAvailable($appId); |
||
100 | if ($newVersion) { |
||
101 | $output->writeln($appId . ' new version available: ' . $newVersion); |
||
102 | |||
103 | if (!$input->getOption('showonly')) { |
||
104 | try { |
||
105 | $result = $this->installer->updateAppstoreApp($appId); |
||
106 | } catch(\Exception $e) { |
||
107 | $this->logger->logException($e, ['message' => 'Failure during update of app "' . $appId . '"','app' => 'app:update']); |
||
108 | $output->writeln('Error: ' . $e->getMessage()); |
||
109 | $return = 1; |
||
110 | } |
||
111 | |||
112 | if ($result === false) { |
||
113 | $output->writeln($appId . ' couldn\'t be updated'); |
||
114 | $return = 1; |
||
115 | } else if($result === true) { |
||
116 | $output->writeln($appId . ' updated'); |
||
117 | } |
||
118 | } |
||
119 | } |
||
120 | } |
||
121 | |||
122 | return $return; |
||
123 | } |
||
126 |