| Conditions | 10 |
| Paths | 10 |
| Total Lines | 52 |
| Code Lines | 28 |
| 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 |
||
| 34 | protected function execute(InputInterface $input, OutputInterface $output): int |
||
| 35 | { |
||
| 36 | $io = new SymfonyStyle($input, $output); |
||
| 37 | $bundleName = $input->getArgument('bundle_name'); |
||
| 38 | |||
| 39 | if (false === $extension = $this->isInstalled($bundleName)) { |
||
|
|
|||
| 40 | if ($input->isInteractive()) { |
||
| 41 | $io->error('The extension is not installed and therefore cannot be uninstalled.'); |
||
| 42 | } |
||
| 43 | |||
| 44 | return 1; |
||
| 45 | } |
||
| 46 | |||
| 47 | if (Constant::STATE_MISSING === $extension->getState()) { |
||
| 48 | if ($input->isInteractive()) { |
||
| 49 | $io->error('The extension cannot be uninstalled because its files are missing.'); |
||
| 50 | } |
||
| 51 | |||
| 52 | return 2; |
||
| 53 | } |
||
| 54 | |||
| 55 | $requiredDependents = $this->dependencyHelper->getDependentExtensions($extension); |
||
| 56 | if (!empty($requiredDependents)) { |
||
| 57 | if ($input->isInteractive()) { |
||
| 58 | $names = implode(', ', array_map(function ($dependent) { |
||
| 59 | return $dependent->getModname(); |
||
| 60 | }, $requiredDependents)); |
||
| 61 | |||
| 62 | $io->error(sprintf('The extension is a required dependency of [%s]. Please uninstall these extensions first.', $names)); |
||
| 63 | } |
||
| 64 | |||
| 65 | return 3; |
||
| 66 | } |
||
| 67 | |||
| 68 | $blocks = $this->blockRepository->findBy(['module' => $extension]); |
||
| 69 | $this->blockRepository->remove($blocks); |
||
| 70 | |||
| 71 | if (false === $this->extensionHelper->uninstall($extension)) { |
||
| 72 | if ($input->isInteractive()) { |
||
| 73 | $io->error('Could not uninstall the extension'); |
||
| 74 | } |
||
| 75 | |||
| 76 | return 4; |
||
| 77 | } |
||
| 78 | |||
| 79 | $this->reSync(); |
||
| 80 | |||
| 81 | if ($input->isInteractive()) { |
||
| 82 | $io->success('The extension has been uninstalled.'); |
||
| 83 | } |
||
| 84 | |||
| 85 | return 0; |
||
| 86 | } |
||
| 88 |