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 |
||
37 | class ApplicationServiceProvider implements ServiceProviderInterface |
||
38 | { |
||
39 | /** |
||
40 | * Registers the service provider with a DI container. |
||
41 | * |
||
42 | * @param Container $container The DI container. |
||
43 | * |
||
44 | * @return void |
||
45 | */ |
||
46 | 1 | public function register(Container $container) |
|
103 | |||
104 | /** |
||
105 | * Get the Analytics class service |
||
106 | * |
||
107 | * @param Container $container The DI container. |
||
108 | * |
||
109 | * @return Analytics |
||
110 | */ |
||
111 | 1 | public function getAnalyticsService(Container $container) |
|
115 | |||
116 | /** |
||
117 | * Get the Cache\ClearCommand class service |
||
118 | * |
||
119 | * @param Container $container The DI container. |
||
120 | * |
||
121 | * @return AppCommands\Cache\ClearCommand |
||
122 | */ |
||
123 | 1 | View Code Duplication | public function getCacheClearCommandService(Container $container) : AppCommands\Cache\ClearCommand |
132 | |||
133 | /** |
||
134 | * Get the CLI application service |
||
135 | * |
||
136 | * @param Container $container The DI container. |
||
137 | * |
||
138 | * @return CliApplication |
||
139 | */ |
||
140 | 1 | public function getCliApplicationService(Container $container) : CliApplication |
|
155 | |||
156 | /** |
||
157 | * Get the CliInput class service |
||
158 | * |
||
159 | * @param Container $container The DI container. |
||
160 | * |
||
161 | * @return JoomlaApplication\Cli\CliInput |
||
162 | */ |
||
163 | 1 | public function getCliInputService(Container $container) : JoomlaApplication\Cli\CliInput |
|
167 | |||
168 | /** |
||
169 | * Get the CliOutput class service |
||
170 | * |
||
171 | * @param Container $container The DI container. |
||
172 | * |
||
173 | * @return JoomlaApplication\Cli\CliOutput |
||
174 | */ |
||
175 | 1 | public function getCliOutputService(Container $container) : JoomlaApplication\Cli\Output\Stdout |
|
179 | |||
180 | /** |
||
181 | * Get the ColorProcessor class service |
||
182 | * |
||
183 | * @param Container $container The DI container. |
||
184 | * |
||
185 | * @return JoomlaApplication\Cli\Output\Processor\ColorProcessor |
||
186 | */ |
||
187 | 1 | public function getColorProcessorService(Container $container) : JoomlaApplication\Cli\Output\Processor\ColorProcessor |
|
204 | |||
205 | /** |
||
206 | * Get the console service |
||
207 | * |
||
208 | * @param Container $container The DI container. |
||
209 | * |
||
210 | * @return Console |
||
211 | */ |
||
212 | 1 | public function getConsoleService(Container $container) : Console |
|
219 | |||
220 | /** |
||
221 | * Get the Database\MigrateCommand class service |
||
222 | * |
||
223 | * @param Container $container The DI container. |
||
224 | * |
||
225 | * @return AppCommands\Database\MigrateCommand |
||
226 | */ |
||
227 | 1 | public function getDatabaseMigrateCommandService(Container $container) : AppCommands\Database\MigrateCommand |
|
237 | |||
238 | /** |
||
239 | * Get the Database\StatusCommand class service |
||
240 | * |
||
241 | * @param Container $container The DI container. |
||
242 | * |
||
243 | * @return AppCommands\Database\StatusCommand |
||
244 | */ |
||
245 | 1 | View Code Duplication | public function getDatabaseStatusCommandService(Container $container) : AppCommands\Database\StatusCommand |
254 | |||
255 | /** |
||
256 | * Get the DisplayControllerCreate class service |
||
257 | * |
||
258 | * @param Container $container The DI container. |
||
259 | * |
||
260 | * @return DisplayControllerCreate |
||
261 | */ |
||
262 | View Code Duplication | public function getDisplayControllerCreateService(Container $container) : DisplayControllerCreate |
|
271 | |||
272 | /** |
||
273 | * Get the DisplayControllerGet class service |
||
274 | * |
||
275 | * @param Container $container The DI container. |
||
276 | * |
||
277 | * @return DisplayControllerGet |
||
278 | */ |
||
279 | 1 | View Code Duplication | public function getDisplayControllerGetService(Container $container) : DisplayControllerGet |
291 | |||
292 | /** |
||
293 | * Get the HelpCommand class service |
||
294 | * |
||
295 | * @param Container $container The DI container. |
||
296 | * |
||
297 | * @return AppCommands\HelpCommand |
||
298 | */ |
||
299 | 1 | View Code Duplication | public function getHelpCommandService(Container $container) : AppCommands\HelpCommand |
308 | |||
309 | /** |
||
310 | * Get the Input\Cli class service |
||
311 | * |
||
312 | * @param Container $container The DI container. |
||
313 | * |
||
314 | * @return Cli |
||
315 | */ |
||
316 | 1 | public function getInputCliService(Container $container) : Cli |
|
320 | |||
321 | /** |
||
322 | * Get the Input class service |
||
323 | * |
||
324 | * @param Container $container The DI container. |
||
325 | * |
||
326 | * @return Input |
||
327 | */ |
||
328 | 1 | public function getInputService(Container $container) : Input |
|
332 | |||
333 | /** |
||
334 | * Get the InstallCommand class service |
||
335 | * |
||
336 | * @param Container $container The DI container. |
||
337 | * |
||
338 | * @return AppCommands\InstallCommand |
||
339 | */ |
||
340 | 1 | View Code Duplication | public function getInstallCommandService(Container $container) : AppCommands\InstallCommand |
349 | |||
350 | /** |
||
351 | * Get the router service |
||
352 | * |
||
353 | * @param Container $container The DI container. |
||
354 | * |
||
355 | * @return Router |
||
356 | */ |
||
357 | 1 | public function getRouterService(Container $container) : Router |
|
369 | |||
370 | /** |
||
371 | * Get the SnapshotCommand class service |
||
372 | * |
||
373 | * @param Container $container The DI container. |
||
374 | * |
||
375 | * @return AppCommands\SnapshotCommand |
||
376 | */ |
||
377 | 1 | View Code Duplication | public function getSnapshotCommandService(Container $container) : AppCommands\SnapshotCommand |
386 | |||
387 | /** |
||
388 | * Get the StatsJsonView class service |
||
389 | * |
||
390 | * @param Container $container The DI container. |
||
391 | * |
||
392 | * @return StatsJsonView |
||
393 | */ |
||
394 | 1 | public function getStatsJsonViewService(Container $container) : StatsJsonView |
|
400 | |||
401 | /** |
||
402 | * Get the StatsModel class service |
||
403 | * |
||
404 | * @param Container $container The DI container. |
||
405 | * |
||
406 | * @return StatsModel |
||
407 | */ |
||
408 | 1 | public function getStatsModelService(Container $container) : StatsModel |
|
414 | |||
415 | /** |
||
416 | * Get the SubmitControllerCreate class service |
||
417 | * |
||
418 | * @param Container $container The DI container. |
||
419 | * |
||
420 | * @return SubmitControllerCreate |
||
421 | */ |
||
422 | 1 | View Code Duplication | public function getSubmitControllerCreateService(Container $container) : SubmitControllerCreate |
433 | |||
434 | /** |
||
435 | * Get the SubmitControllerGet class service |
||
436 | * |
||
437 | * @param Container $container The DI container. |
||
438 | * |
||
439 | * @return SubmitControllerGet |
||
440 | */ |
||
441 | 1 | View Code Duplication | public function getSubmitControllerGetService(Container $container) : SubmitControllerGet |
450 | |||
451 | /** |
||
452 | * Get the Tags\JoomlaCommand class service |
||
453 | * |
||
454 | * @param Container $container The DI container. |
||
455 | * |
||
456 | * @return AppCommands\Tags\JoomlaCommand |
||
457 | */ |
||
458 | 1 | View Code Duplication | public function getTagsJoomlaCommandService(Container $container) : AppCommands\Tags\JoomlaCommand |
467 | |||
468 | /** |
||
469 | * Get the Tags\PhpCommand class service |
||
470 | * |
||
471 | * @param Container $container The DI container. |
||
472 | * |
||
473 | * @return AppCommands\Tags\PhpCommand |
||
474 | */ |
||
475 | 1 | View Code Duplication | public function getTagsPhpCommandService(Container $container) : AppCommands\Tags\PhpCommand |
484 | |||
485 | /** |
||
486 | * Get the UpdateCommand class service |
||
487 | * |
||
488 | * @param Container $container The DI container. |
||
489 | * |
||
490 | * @return AppCommands\UpdateCommand |
||
491 | */ |
||
492 | 1 | View Code Duplication | public function getUpdateCommandService(Container $container) : AppCommands\UpdateCommand |
501 | |||
502 | /** |
||
503 | * Get the web application service |
||
504 | * |
||
505 | * @param Container $container The DI container. |
||
506 | * |
||
507 | * @return WebApplication |
||
508 | */ |
||
509 | 1 | public function getWebApplicationService(Container $container) : WebApplication |
|
520 | } |
||
521 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.