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 |
||
9 | class PublishConfigurationCommand extends Command |
||
10 | { |
||
11 | /** |
||
12 | * The console command name. |
||
13 | * |
||
14 | * @var string |
||
15 | */ |
||
16 | protected $name = 'module:publish-config'; |
||
17 | |||
18 | /** |
||
19 | * The console command description. |
||
20 | * |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $description = 'Publish a module\'s config files to the application'; |
||
24 | |||
25 | /** |
||
26 | * Execute the console command. |
||
27 | */ |
||
28 | View Code Duplication | public function handle() |
|
1 ignored issue
–
show
|
|||
29 | { |
||
30 | if ($module = $this->argument('module')) { |
||
31 | $this->publishConfiguration($module); |
||
32 | |||
33 | return; |
||
34 | } |
||
35 | |||
36 | foreach ($this->laravel['modules']->enabled() as $module) { |
||
37 | $this->publishConfiguration($module->getName()); |
||
38 | } |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * @param string $module |
||
43 | * @return string |
||
44 | */ |
||
45 | private function getServiceProviderForModule($module) |
||
52 | |||
53 | /** |
||
54 | * @param string $module |
||
55 | */ |
||
56 | private function publishConfiguration($module) |
||
64 | |||
65 | /** |
||
66 | * Get the console command arguments. |
||
67 | * |
||
68 | * @return array |
||
69 | */ |
||
70 | 56 | protected function getArguments() |
|
76 | |||
77 | /** |
||
78 | * @return array |
||
79 | */ |
||
80 | 56 | protected function getOptions() |
|
86 | } |
||
87 |
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.