Conditions | 9 |
Paths | 17 |
Total Lines | 58 |
Code Lines | 34 |
Lines | 11 |
Ratio | 18.97 % |
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 |
||
31 | protected function execute(InputInterface $input, OutputInterface $output) { |
||
32 | Config::load(); |
||
33 | |||
34 | $force = $input->getOption(self::FORCE); |
||
35 | $publicDir = Config::get('directories.public'); |
||
36 | $cacheDir = Config::get('directories.cache'); |
||
37 | |||
38 | if (!$force) { |
||
39 | $questionHelper = $this->getHelper('question'); |
||
40 | $question = new Question("Are you sure you want to clean all generated files ({$publicDir} and {$cacheDir}) [y/N] ", false); |
||
41 | |||
42 | if (!$questionHelper->ask($input, $output, $question)) { |
||
43 | return; |
||
44 | } |
||
45 | } |
||
46 | |||
47 | $fs = new Filesystem(); |
||
48 | $finder = new Finder(); |
||
49 | $log = []; |
||
50 | |||
51 | if ($fs->exists($publicDir)) { |
||
52 | $publicDirectories = $finder->directories()->in($publicDir); |
||
53 | $directoryPaths = []; |
||
54 | foreach ($publicDirectories as $directory) { |
||
55 | $directoryPaths[] = $directory->getPathname(); |
||
56 | } |
||
57 | $fs->remove($directoryPaths); |
||
58 | |||
59 | $publicFiles = $finder->files()->in($publicDir)->notName('.htaccess')->ignoreDotFiles(true); |
||
60 | foreach ($publicFiles as $file) { |
||
61 | $fs->remove($file->getPathname()); |
||
62 | } |
||
63 | |||
64 | $log[] = "Cleaned the public directory: {$publicDir}"; |
||
65 | } |
||
66 | |||
67 | if ($fs->exists($cacheDir)) { |
||
68 | $fs->remove($cacheDir); |
||
69 | |||
70 | $log[] = "Removed the cache directory: {$cacheDir}"; |
||
71 | } |
||
72 | |||
73 | View Code Duplication | if (count($log)) { |
|
|
|||
74 | $output->writeln("Successfully cleaned up\n"); |
||
75 | |||
76 | foreach ($log as $line) { |
||
77 | $output->writeln("- {$line}"); |
||
78 | } |
||
79 | |||
80 | $output->writeln("\nRun <fg=green>site:generate</> to generate these files again."); |
||
81 | } else { |
||
82 | $output->writeln('No files were found'); |
||
83 | } |
||
84 | |||
85 | |||
86 | return; |
||
87 | |||
88 | } |
||
89 | } |
||
90 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.