Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
8 | class DumpCommand extends Command |
||
9 | { |
||
10 | /** |
||
11 | * The console command name. |
||
12 | * |
||
13 | * @var string |
||
14 | */ |
||
15 | protected $name = 'module:dump'; |
||
16 | |||
17 | /** |
||
18 | * The console command description. |
||
19 | * |
||
20 | * @var string |
||
21 | */ |
||
22 | protected $description = 'Dump-autoload the specified module or for all module.'; |
||
23 | |||
24 | /** |
||
25 | * Execute the console command. |
||
26 | */ |
||
27 | View Code Duplication | public function handle() |
|
1 ignored issue
–
show
|
|||
28 | { |
||
29 | $this->info('Generating optimized autoload modules.'); |
||
30 | |||
31 | if ($module = $this->argument('module')) { |
||
32 | $this->dump($module); |
||
33 | } else { |
||
34 | foreach ($this->laravel['modules']->all() as $module) { |
||
35 | $this->dump($module->getStudlyName()); |
||
36 | } |
||
37 | } |
||
38 | } |
||
39 | |||
40 | public function dump($module) |
||
50 | |||
51 | /** |
||
52 | * Get the console command arguments. |
||
53 | * |
||
54 | * @return array |
||
55 | */ |
||
56 | 56 | protected function getArguments() |
|
62 | } |
||
63 |
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.