| Conditions | 11 |
| Paths | 35 |
| Total Lines | 76 |
| Code Lines | 48 |
| 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 |
||
| 62 | protected function execute(InputInterface $input, OutputInterface $output): void |
||
| 63 | { |
||
| 64 | $destOption = $input->getOption('dest'); |
||
| 65 | if ($destOption) { |
||
| 66 | $dest = realpath($destOption); |
||
| 67 | if (false === $dest) { |
||
| 68 | throw new \RuntimeException(sprintf( |
||
| 69 | 'The provided destination folder \'%s\' does not exist!', |
||
| 70 | $destOption |
||
| 71 | )); |
||
| 72 | } |
||
| 73 | } else { |
||
| 74 | $dest = $this->getContainer()->get('kernel')->getRootDir(); |
||
| 75 | } |
||
| 76 | |||
| 77 | $namespace = $input->getOption('namespace'); |
||
| 78 | if ($namespace) { |
||
| 79 | if (!preg_match('/^(?:(?:[[:alnum:]]+|:vendor)\\\\?)+$/', $namespace)) { |
||
| 80 | throw new \InvalidArgumentException( |
||
| 81 | 'The provided namespace \'%s\' is not a valid namespace!', |
||
| 82 | $namespace |
||
| 83 | ); |
||
| 84 | } |
||
| 85 | } else { |
||
| 86 | $namespace = 'Application\:vendor'; |
||
| 87 | } |
||
| 88 | |||
| 89 | $configuration = [ |
||
| 90 | 'application_dir' => sprintf( |
||
| 91 | '%s%s%s', |
||
| 92 | $dest, |
||
| 93 | DIRECTORY_SEPARATOR, |
||
| 94 | str_replace('\\', DIRECTORY_SEPARATOR, $namespace) |
||
| 95 | ), |
||
| 96 | 'namespace' => $namespace, |
||
| 97 | 'namespace_prefix' => '', |
||
| 98 | ]; |
||
| 99 | |||
| 100 | if ($namespacePrefix = $input->getOption('namespace_prefix')) { |
||
| 101 | $configuration['namespace_prefix'] = rtrim($namespacePrefix, '\\').'\\'; |
||
| 102 | } |
||
| 103 | |||
| 104 | $bundleNames = $input->getArgument('bundle'); |
||
| 105 | |||
| 106 | if (empty($bundleNames)) { |
||
| 107 | $output->writeln(''); |
||
| 108 | $output->writeln('<error>You must provide a bundle name!</error>'); |
||
| 109 | $output->writeln(''); |
||
| 110 | $output->writeln(' Bundles availables :'); |
||
| 111 | /** @var BundleInterface $bundle */ |
||
| 112 | foreach ($this->getContainer()->get('kernel')->getBundles() as $bundle) { |
||
| 113 | $bundleMetadata = new BundleMetadata($bundle, $configuration); |
||
| 114 | |||
| 115 | if (!$bundleMetadata->isExtendable()) { |
||
| 116 | continue; |
||
| 117 | } |
||
| 118 | |||
| 119 | $output->writeln(sprintf(' - %s', $bundle->getName())); |
||
| 120 | } |
||
| 121 | |||
| 122 | $output->writeln(''); |
||
| 123 | } else { |
||
| 124 | foreach ($bundleNames as $bundleName) { |
||
| 125 | $processed = $this->generate($bundleName, $configuration, $output); |
||
| 126 | |||
| 127 | if (!$processed) { |
||
| 128 | throw new \RuntimeException(sprintf( |
||
| 129 | '<error>The bundle \'%s\' does not exist or is not registered in the kernel!</error>', |
||
| 130 | $bundleName |
||
| 131 | )); |
||
| 132 | } |
||
| 133 | } |
||
| 134 | } |
||
| 135 | |||
| 136 | $output->writeln('done!'); |
||
| 137 | } |
||
| 138 | |||
| 205 |