| Conditions | 7 |
| Paths | 10 |
| Total Lines | 52 |
| Code Lines | 30 |
| 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 |
||
| 75 | protected function execute(InputInterface $input, OutputInterface $output) { |
||
| 76 | $appId = $input->getArgument('app-id'); |
||
| 77 | |||
| 78 | // Check if the app is installed |
||
| 79 | if (!\OC_App::getAppPath($appId)) { |
||
|
|
|||
| 80 | $output->writeln($appId . ' is not installed'); |
||
| 81 | return 1; |
||
| 82 | } |
||
| 83 | |||
| 84 | // Removing shipped apps is not possible, therefore we pre-check that |
||
| 85 | // before trying to remove it |
||
| 86 | if ($this->manager->isShipped($appId)) { |
||
| 87 | $output->writeln($appId . ' could not be removed as it is a shipped app'); |
||
| 88 | return 1; |
||
| 89 | } |
||
| 90 | |||
| 91 | // If we want to keep the data of the app, we simply don't disable it here. |
||
| 92 | // App uninstall tasks are being executed when disabled. More info: PR #11627. |
||
| 93 | if (!$input->getOption('keep-data')) { |
||
| 94 | try { |
||
| 95 | $this->manager->disableApp($appId); |
||
| 96 | $output->writeln($appId . ' disabled'); |
||
| 97 | } catch(Throwable $e) { |
||
| 98 | $output->writeln('<error>Error: ' . $e->getMessage() . '</error>'); |
||
| 99 | $this->logger->logException($e, [ |
||
| 100 | 'app' => 'CLI', |
||
| 101 | 'level' => ILogger::ERROR |
||
| 102 | ]); |
||
| 103 | return 1; |
||
| 104 | } |
||
| 105 | } |
||
| 106 | |||
| 107 | // Let's try to remove the app... |
||
| 108 | try { |
||
| 109 | $result = $this->installer->removeApp($appId); |
||
| 110 | } catch(Throwable $e) { |
||
| 111 | $output->writeln('<error>Error: ' . $e->getMessage() . '</error>'); |
||
| 112 | $this->logger->logException($e, [ |
||
| 113 | 'app' => 'CLI', |
||
| 114 | 'level' => ILogger::ERROR |
||
| 115 | ]); |
||
| 116 | return 1; |
||
| 117 | } |
||
| 118 | |||
| 119 | if($result === false) { |
||
| 120 | $output->writeln($appId . ' could not be removed'); |
||
| 121 | return 1; |
||
| 122 | } |
||
| 123 | |||
| 124 | $output->writeln($appId . ' removed'); |
||
| 125 | |||
| 126 | return 0; |
||
| 127 | } |
||
| 150 |