| Conditions | 10 |
| Paths | 8 |
| Total Lines | 35 |
| Code Lines | 27 |
| 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 |
||
| 87 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 88 | { |
||
| 89 | $targetArg = rtrim($input->getArgument('target'), '/'); |
||
|
|
|||
| 90 | if (!is_dir($targetArg)) { |
||
| 91 | throw new InvalidArgumentException(sprintf('The target directory "%s" does not exist.', $input->getArgument('target'))); |
||
| 92 | } |
||
| 93 | if (!function_exists('symlink') && $input->getOption('symlink')) { |
||
| 94 | throw new InvalidArgumentException('The symlink() function is not available on your system. You need to install the assets without the --symlink option.'); |
||
| 95 | } |
||
| 96 | $array = [ |
||
| 97 | 'bundle' => $this->kernel->getJustBundles(), |
||
| 98 | 'module' => $this->kernel->getModules(), |
||
| 99 | 'theme' => $this->kernel->getThemes(), |
||
| 100 | ]; |
||
| 101 | foreach ($array as $type => $bundles) { |
||
| 102 | // Create the bundles directory otherwise symlink will fail. |
||
| 103 | $this->filesystem->mkdir($targetArg . "/{$type}s/", 0777); |
||
| 104 | $output->writeln(sprintf('Installing assets using the <comment>%s</comment> option', $input->getOption('symlink') ? 'symlink' : 'hard copy')); |
||
| 105 | foreach ($bundles as $bundle) { |
||
| 106 | if (is_dir($originDir = $bundle->getPath() . '/Resources/public')) { |
||
| 107 | $bundlesDir = $targetArg . '/' . $type . 's/'; |
||
| 108 | $targetDir = $bundlesDir . preg_replace('/' . $type . '$/', '', mb_strtolower($bundle->getName())); |
||
| 109 | $output->writeln(sprintf('Installing assets for <comment>%s</comment> into <comment>%s</comment>', $bundle->getNamespace(), $targetDir)); |
||
| 110 | $this->filesystem->remove($targetDir); |
||
| 111 | if ($input->getOption('symlink')) { |
||
| 112 | if ($input->getOption('relative')) { |
||
| 113 | $relativeOriginDir = $this->filesystem->makePathRelative($originDir, realpath($bundlesDir)); |
||
| 114 | } else { |
||
| 115 | $relativeOriginDir = $originDir; |
||
| 116 | } |
||
| 117 | $this->filesystem->symlink($relativeOriginDir, $targetDir); |
||
| 118 | } else { |
||
| 119 | $this->filesystem->mkdir($targetDir, 0777); |
||
| 120 | // We use a custom iterator to ignore VCS files |
||
| 121 | $this->filesystem->mirror($originDir, $targetDir, Finder::create()->in($originDir)); |
||
| 122 | } |
||
| 128 |