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 |
||
15 | class AdminLTETemplateServiceProvider extends ServiceProvider |
||
16 | { |
||
17 | |||
18 | /** |
||
19 | * Register the application services. |
||
20 | */ |
||
21 | public function register() |
||
59 | |||
60 | /** |
||
61 | * Register Gravatar Service Provider. |
||
62 | */ |
||
63 | protected function registerGravatarServiceProvider() |
||
70 | |||
71 | /** |
||
72 | * Bootstrap the application services. |
||
73 | */ |
||
74 | View Code Duplication | public function boot(Router $router) |
|
99 | |||
100 | /** |
||
101 | * Publish Home Controller. |
||
102 | */ |
||
103 | private function publishHomeController() |
||
107 | |||
108 | /** |
||
109 | * Change default Laravel RegisterController. |
||
110 | */ |
||
111 | private function changeRegisterController() |
||
115 | |||
116 | /** |
||
117 | * Change default Laravel LoginController. |
||
118 | */ |
||
119 | private function changeLoginController() |
||
123 | |||
124 | /** |
||
125 | * Change default Laravel forgot password Controller. |
||
126 | */ |
||
127 | private function changeForgotPasswordController() |
||
131 | |||
132 | /** |
||
133 | * Publish no guest forgot password Controller. |
||
134 | */ |
||
135 | private function publishNoGuestForgotPasswordController() |
||
139 | |||
140 | /** |
||
141 | * Change default Laravel reset password Controller. |
||
142 | */ |
||
143 | private function changeResetPasswordController() |
||
147 | |||
148 | /** |
||
149 | * Publish public resource assets to Laravel project. |
||
150 | */ |
||
151 | private function publishPublicAssets() |
||
155 | |||
156 | /** |
||
157 | * Publish package views to Laravel project. |
||
158 | */ |
||
159 | private function publishViews() |
||
165 | |||
166 | /** |
||
167 | * Publish package resource assets to Laravel project. |
||
168 | */ |
||
169 | private function publishResourceAssets() |
||
173 | |||
174 | /** |
||
175 | * Publish package tests to Laravel project. |
||
176 | */ |
||
177 | private function publishTests() |
||
181 | |||
182 | /** |
||
183 | * Publish package language to Laravel project. |
||
184 | */ |
||
185 | private function publishLanguages() |
||
191 | |||
192 | /** |
||
193 | * Publish config Gravatar file using group. |
||
194 | */ |
||
195 | private function publishGravatar() |
||
199 | |||
200 | /** |
||
201 | * Publish adminlte package config. |
||
202 | */ |
||
203 | private function publishConfig() |
||
207 | |||
208 | /** |
||
209 | * Publish routes/web.php file. |
||
210 | */ |
||
211 | private function publishWebRoutes() |
||
215 | |||
216 | /** |
||
217 | * Publish routes/api.php file. |
||
218 | */ |
||
219 | private function publishApiRoutes() |
||
223 | |||
224 | /** |
||
225 | * Publish dusk tests files. |
||
226 | */ |
||
227 | private function publishDusk() |
||
231 | |||
232 | /** |
||
233 | * Publish dusk environment files. |
||
234 | */ |
||
235 | private function publishDuskEnvironment() |
||
239 | |||
240 | /** |
||
241 | * Publish database config files. |
||
242 | */ |
||
243 | private function publishDatabaseConfig() |
||
247 | |||
248 | /** |
||
249 | * Enable (if active) spatie menu. |
||
250 | */ |
||
251 | private function enableSpatieMenu() |
||
257 | } |
||
258 |
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.