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 |
||
10 | class PublishAdminLTE extends Command |
||
11 | { |
||
12 | /** |
||
13 | * The name and signature of the console command. |
||
14 | */ |
||
15 | protected $signature = 'adminlte-laravel:publish'; |
||
16 | |||
17 | /** |
||
18 | * The console command description. |
||
19 | * |
||
20 | * @var string |
||
21 | */ |
||
22 | protected $description = 'Publish Acacha AdminLTE Template files into laravel project'; |
||
23 | |||
24 | /** |
||
25 | * Execute the console command. |
||
26 | * |
||
27 | */ |
||
28 | View Code Duplication | public function handle() |
|
39 | |||
40 | /** |
||
41 | * Install Home Controller. |
||
42 | */ |
||
43 | private function publishHomeController() |
||
47 | |||
48 | /** |
||
49 | * Install Auth controller. |
||
50 | */ |
||
51 | private function changeRegisterController() |
||
55 | |||
56 | /** |
||
57 | * Install public assets. |
||
58 | */ |
||
59 | private function publishPublicAssets() |
||
63 | |||
64 | /** |
||
65 | * Install views. |
||
66 | */ |
||
67 | private function publishViews() |
||
71 | |||
72 | /** |
||
73 | * Install resource assets. |
||
74 | */ |
||
75 | private function publishResourceAssets() |
||
79 | |||
80 | /** |
||
81 | * Install resource assets. |
||
82 | */ |
||
83 | private function publishTests() |
||
87 | |||
88 | /** |
||
89 | * Install language assets. |
||
90 | */ |
||
91 | private function publishLanguages() |
||
95 | |||
96 | /** |
||
97 | * Install gravatar config file. |
||
98 | */ |
||
99 | private function publishGravatar() |
||
103 | |||
104 | /** |
||
105 | * Install files from array. |
||
106 | * |
||
107 | * @param $files |
||
108 | */ |
||
109 | private function install($files) |
||
119 | |||
120 | /** |
||
121 | * @param $fileName |
||
122 | * @param string $prompt |
||
123 | * |
||
124 | * @return bool |
||
125 | */ |
||
126 | protected function confirmOverwrite($fileName, $prompt = '') |
||
133 | } |
||
134 |
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.