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