Conditions | 10 |
Paths | 8 |
Total Lines | 47 |
Code Lines | 27 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | 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 |
||
68 | protected function execute(InputInterface $input, OutputInterface $output) |
||
69 | { |
||
70 | $targetArg = rtrim($input->getArgument('target'), '/'); |
||
71 | |||
72 | if (!is_dir($targetArg)) { |
||
73 | throw new \InvalidArgumentException(sprintf('The target directory "%s" does not exist.', $input->getArgument('target'))); |
||
74 | } |
||
75 | |||
76 | if (!function_exists('symlink') && $input->getOption('symlink')) { |
||
77 | throw new \InvalidArgumentException('The symlink() function is not available on your system. You need to install the assets without the --symlink option.'); |
||
78 | } |
||
79 | |||
80 | $filesystem = $this->getServiceManager()->get('filesystem'); |
||
81 | |||
82 | // Create the modules directory otherwise symlink will fail. |
||
83 | $filesystem->mkdir($targetArg . '/modules/', 0777); |
||
84 | |||
85 | $output->writeln(sprintf("Installing assets using the <comment>%s</comment> option", $input->getOption('symlink') ? 'symlink' : 'hard copy')); |
||
86 | |||
87 | foreach ($this->getServiceManager()->get('modulemanager')->getLoadedModules() as $module) { |
||
88 | if (!method_exists($module, 'getPath')) { |
||
89 | continue; |
||
90 | } |
||
91 | if (!is_dir($originDir = $module->getPath() . '/resources/public')) { |
||
92 | continue; |
||
93 | } |
||
94 | $modulesDir = $targetArg . '/modules/'; |
||
95 | $targetDir = $modulesDir . str_replace('module', '', strtolower($module->getName())); |
||
96 | |||
97 | $output->writeln(sprintf('Installing assets for <comment>%s</comment> into <comment>%s</comment>', $module->getNamespace(), $targetDir)); |
||
98 | |||
99 | $filesystem->remove($targetDir); |
||
100 | |||
101 | if ($input->getOption('symlink')) { |
||
102 | if ($input->getOption('relative')) { |
||
103 | $relativeOriginDir = $filesystem->makePathRelative($originDir, realpath($modulesDir)); |
||
104 | } else { |
||
105 | $relativeOriginDir = $originDir; |
||
106 | } |
||
107 | $filesystem->symlink($relativeOriginDir, $targetDir); |
||
108 | } else { |
||
109 | $filesystem->mkdir($targetDir, 0777); |
||
110 | // We use a custom iterator to ignore VCS files |
||
111 | $filesystem->mirror($originDir, $targetDir, Finder::create()->in($originDir)); |
||
112 | } |
||
113 | } |
||
114 | } |
||
115 | } |
||
116 |