| Conditions | 10 |
| Paths | 19 |
| Total Lines | 57 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 16 | ||
| Bugs | 1 | Features | 6 |
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 |
||
| 53 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 54 | { |
||
| 55 | $destOption = $input->getOption('dest'); |
||
| 56 | if ($destOption) { |
||
| 57 | $dest = realpath($destOption); |
||
| 58 | if (false === $dest) { |
||
| 59 | throw new \RuntimeException(sprintf('The provided destination folder \'%s\' does not exist!', $destOption)); |
||
| 60 | } |
||
| 61 | } else { |
||
| 62 | $dest = $this->getContainer()->get('kernel')->getRootDir(); |
||
| 63 | } |
||
| 64 | |||
| 65 | $namespace = $input->getOption('namespace'); |
||
| 66 | if ($namespace) { |
||
| 67 | if (!preg_match('/^(?:(?:[[:alnum:]]+|:vendor)\\\\?)+$/', $namespace)) { |
||
| 68 | throw new \InvalidArgumentException('The provided namespace \'%s\' is not a valid namespace!', $namespace); |
||
| 69 | } |
||
| 70 | } else { |
||
| 71 | $namespace = 'Application\:vendor'; |
||
| 72 | } |
||
| 73 | |||
| 74 | $configuration = array( |
||
| 75 | 'application_dir' => sprintf('%s%s%s', $dest, DIRECTORY_SEPARATOR, str_replace('\\', DIRECTORY_SEPARATOR, $namespace)), |
||
| 76 | 'namespace' => $namespace, |
||
| 77 | ); |
||
| 78 | |||
| 79 | $bundleNames = $input->getArgument('bundle'); |
||
| 80 | |||
| 81 | if (empty($bundleNames)) { |
||
| 82 | $output->writeln(''); |
||
| 83 | $output->writeln('<error>You must provide a bundle name!</error>'); |
||
| 84 | $output->writeln(''); |
||
| 85 | $output->writeln(' Bundles availables :'); |
||
| 86 | /** @var BundleInterface $bundle */ |
||
| 87 | foreach ($this->getContainer()->get('kernel')->getBundles() as $bundle) { |
||
| 88 | $bundleMetadata = new BundleMetadata($bundle, $configuration); |
||
| 89 | |||
| 90 | if (!$bundleMetadata->isExtendable()) { |
||
| 91 | continue; |
||
| 92 | } |
||
| 93 | |||
| 94 | $output->writeln(sprintf(' - %s', $bundle->getName())); |
||
| 95 | } |
||
| 96 | |||
| 97 | $output->writeln(''); |
||
| 98 | } else { |
||
| 99 | foreach ($bundleNames as $bundleName) { |
||
| 100 | $processed = $this->generate($bundleName, $configuration, $output); |
||
| 101 | |||
| 102 | if (!$processed) { |
||
| 103 | throw new \RuntimeException(sprintf('<error>The bundle \'%s\' does not exist or not defined in the kernel file!</error>', $bundleName)); |
||
| 104 | } |
||
| 105 | } |
||
| 106 | } |
||
| 107 | |||
| 108 | $output->writeln('done!'); |
||
| 109 | } |
||
| 110 | |||
| 172 |