| Conditions | 10 |
| Paths | 18 |
| Total Lines | 51 |
| Code Lines | 28 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | 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 |
||
| 38 | protected function execute(InputInterface $input, OutputInterface $output): int |
||
| 39 | { |
||
| 40 | $io = new SymfonyStyle($input, $output); |
||
| 41 | $bundleName = $input->getArgument('bundle_name'); |
||
| 42 | |||
| 43 | if (false !== $this->isInstalled($bundleName)) { |
||
|
|
|||
| 44 | if ($input->isInteractive()) { |
||
| 45 | $io->error('Extension is already installed but possibly inactive.'); |
||
| 46 | } |
||
| 47 | |||
| 48 | return 1; |
||
| 49 | } |
||
| 50 | |||
| 51 | if (!$this->kernel->isBundle($bundleName)) { |
||
| 52 | $this->load($bundleName); |
||
| 53 | $io->note(sprintf('%s is now prepared for installation. Run this command again to complete installation.', $bundleName)); |
||
| 54 | |||
| 55 | return 0; |
||
| 56 | } |
||
| 57 | |||
| 58 | /** @var $extension ExtensionEntity */ |
||
| 59 | $extension = $this->extensionRepository->findOneBy(['name' => $bundleName]); |
||
| 60 | $unsatisfiedDependencies = $this->dependencyHelper->getUnsatisfiedExtensionDependencies($extension); |
||
| 61 | $dependencyNames = []; |
||
| 62 | foreach ($unsatisfiedDependencies as $dependency) { |
||
| 63 | if (MetaData::DEPENDENCY_REQUIRED !== $dependency->getStatus()) { |
||
| 64 | continue; |
||
| 65 | } |
||
| 66 | $dependencyNames[] = $dependency->getModname(); |
||
| 67 | } |
||
| 68 | if (!empty($dependencyNames)) { |
||
| 69 | $io->error(sprintf('Cannot install because this extension depends on other extensions. Please install the following extensions first: %s', implode(', ', $dependencyNames))); |
||
| 70 | |||
| 71 | return 2; |
||
| 72 | } |
||
| 73 | |||
| 74 | if (false === $this->extensionHelper->install($extension)) { |
||
| 75 | if ($input->isInteractive()) { |
||
| 76 | $io->error('Could not install the extension'); |
||
| 77 | } |
||
| 78 | |||
| 79 | return 3; |
||
| 80 | } |
||
| 81 | |||
| 82 | $this->eventDispatcher->dispatch(new ExtensionPostCacheRebuildEvent($this->kernel->getBundle($extension->getName()), $extension)); |
||
| 83 | |||
| 84 | if ($input->isInteractive()) { |
||
| 85 | $io->success('Extension installed'); |
||
| 86 | } |
||
| 87 | |||
| 88 | return 0; |
||
| 89 | } |
||
| 114 |