| Conditions | 7 |
| Paths | 61 |
| Total Lines | 53 |
| Code Lines | 42 |
| 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 |
||
| 123 | protected function execute(InputInterface $input, OutputInterface $output) { |
||
| 124 | |||
| 125 | try { |
||
| 126 | if ($this->encryptionManager->isEnabled() === true) { |
||
| 127 | $output->write('Disable server side encryption... '); |
||
| 128 | $this->config->setAppValue('core', 'encryption_enabled', 'no'); |
||
| 129 | $output->writeln('done.'); |
||
| 130 | } else { |
||
| 131 | $output->writeln('Server side encryption not enabled. Nothing to do.'); |
||
| 132 | return; |
||
| 133 | } |
||
| 134 | |||
| 135 | $uid = $input->getArgument('user'); |
||
| 136 | if ($uid === '') { |
||
| 137 | $message = 'your Nextcloud'; |
||
| 138 | } else { |
||
| 139 | $message = "$uid's account"; |
||
| 140 | } |
||
| 141 | |||
| 142 | $output->writeln("\n"); |
||
| 143 | $output->writeln("You are about to start to decrypt all files stored in $message."); |
||
| 144 | $output->writeln('It will depend on the encryption module and your setup if this is possible.'); |
||
| 145 | $output->writeln('Depending on the number and size of your files this can take some time'); |
||
| 146 | $output->writeln('Please make sure that no user access his files during this process!'); |
||
| 147 | $output->writeln(''); |
||
| 148 | $question = new ConfirmationQuestion('Do you really want to continue? (y/n) ', false); |
||
| 149 | if ($this->questionHelper->ask($input, $output, $question)) { |
||
| 150 | $this->forceMaintenanceAndTrashbin(); |
||
| 151 | $user = $input->getArgument('user'); |
||
| 152 | $result = $this->decryptAll->decryptAll($input, $output, $user); |
||
| 153 | if ($result === false) { |
||
| 154 | $output->writeln(' aborted.'); |
||
| 155 | $output->writeln('Server side encryption remains enabled'); |
||
| 156 | $this->config->setAppValue('core', 'encryption_enabled', 'yes'); |
||
| 157 | } else if ($uid !== '') { |
||
| 158 | $output->writeln('Server side encryption remains enabled'); |
||
| 159 | $this->config->setAppValue('core', 'encryption_enabled', 'yes'); |
||
| 160 | } |
||
| 161 | $this->resetMaintenanceAndTrashbin(); |
||
| 162 | } else { |
||
| 163 | $output->write('Enable server side encryption... '); |
||
| 164 | $this->config->setAppValue('core', 'encryption_enabled', 'yes'); |
||
| 165 | $output->writeln('done.'); |
||
| 166 | $output->writeln('aborted'); |
||
| 167 | } |
||
| 168 | } catch (\Exception $e) { |
||
| 169 | // enable server side encryption again if something went wrong |
||
| 170 | $this->config->setAppValue('core', 'encryption_enabled', 'yes'); |
||
| 171 | $this->resetMaintenanceAndTrashbin(); |
||
| 172 | throw $e; |
||
| 173 | } |
||
| 174 | |||
| 175 | } |
||
| 176 | } |
||
| 177 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.