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 |
||
32 | class ApplicationServiceProvider implements ServiceProviderInterface |
||
33 | { |
||
34 | /** |
||
35 | * Registers the service provider with a DI container. |
||
36 | * |
||
37 | * @param Container $container The DI container. |
||
38 | * |
||
39 | * @return void |
||
40 | * |
||
41 | * @since 1.0 |
||
42 | */ |
||
43 | 1 | public function register(Container $container) |
|
99 | |||
100 | /** |
||
101 | * Get the Analytics class service |
||
102 | * |
||
103 | * @param Container $container The DI container. |
||
104 | * |
||
105 | * @return Analytics |
||
106 | * |
||
107 | * @since 1.0 |
||
108 | */ |
||
109 | 1 | public function getAnalyticsService(Container $container) |
|
113 | |||
114 | /** |
||
115 | * Get the Cache\ClearCommand class service |
||
116 | * |
||
117 | * @param Container $container The DI container. |
||
118 | * |
||
119 | * @return AppCommands\Cache\ClearCommand |
||
120 | * |
||
121 | * @since 1.0 |
||
122 | */ |
||
123 | 1 | View Code Duplication | public function getCacheClearCommandService(Container $container) |
132 | |||
133 | /** |
||
134 | * Get the CLI application service |
||
135 | * |
||
136 | * @param Container $container The DI container. |
||
137 | * |
||
138 | * @return CliApplication |
||
139 | * |
||
140 | * @since 1.0 |
||
141 | */ |
||
142 | 1 | public function getCliApplicationService(Container $container) |
|
158 | |||
159 | /** |
||
160 | * Get the CliInput class service |
||
161 | * |
||
162 | * @param Container $container The DI container. |
||
163 | * |
||
164 | * @return JoomlaApplication\Cli\CliInput |
||
165 | * |
||
166 | * @since 1.0 |
||
167 | */ |
||
168 | 1 | public function getCliInputService(Container $container) |
|
172 | |||
173 | /** |
||
174 | * Get the CliOutput class service |
||
175 | * |
||
176 | * @param Container $container The DI container. |
||
177 | * |
||
178 | * @return JoomlaApplication\Cli\CliOutput |
||
179 | * |
||
180 | * @since 1.0 |
||
181 | */ |
||
182 | 1 | public function getCliOutputService(Container $container) |
|
186 | |||
187 | /** |
||
188 | * Get the ColorProcessor class service |
||
189 | * |
||
190 | * @param Container $container The DI container. |
||
191 | * |
||
192 | * @return JoomlaApplication\Cli\Output\Processor\ColorProcessor |
||
193 | * |
||
194 | * @since 1.0 |
||
195 | */ |
||
196 | 1 | public function getColorProcessorService(Container $container) |
|
213 | |||
214 | /** |
||
215 | * Get the console service |
||
216 | * |
||
217 | * @param Container $container The DI container. |
||
218 | * |
||
219 | * @return Console |
||
220 | * |
||
221 | * @since 1.0 |
||
222 | */ |
||
223 | 1 | public function getConsoleService(Container $container) |
|
230 | |||
231 | /** |
||
232 | * Get the Database\MigrateCommand class service |
||
233 | * |
||
234 | * @param Container $container The DI container. |
||
235 | * |
||
236 | * @return AppCommands\Database\MigrateCommand |
||
237 | * |
||
238 | * @since 1.0 |
||
239 | */ |
||
240 | 1 | public function getDatabaseMigrateCommandService(Container $container) |
|
250 | |||
251 | /** |
||
252 | * Get the Database\StatusCommand class service |
||
253 | * |
||
254 | * @param Container $container The DI container. |
||
255 | * |
||
256 | * @return AppCommands\Database\StatusCommand |
||
257 | * |
||
258 | * @since 1.0 |
||
259 | */ |
||
260 | 1 | View Code Duplication | public function getDatabaseStatusCommandService(Container $container) |
269 | |||
270 | /** |
||
271 | * Get the DisplayControllerGet class service |
||
272 | * |
||
273 | * @param Container $container The DI container. |
||
274 | * |
||
275 | * @return DisplayControllerGet |
||
276 | * |
||
277 | * @since 1.0 |
||
278 | */ |
||
279 | 1 | View Code Duplication | public function getDisplayControllerGetService(Container $container) |
291 | |||
292 | /** |
||
293 | * Get the HelpCommand class service |
||
294 | * |
||
295 | * @param Container $container The DI container. |
||
296 | * |
||
297 | * @return AppCommands\HelpCommand |
||
298 | * |
||
299 | * @since 1.0 |
||
300 | */ |
||
301 | 1 | View Code Duplication | public function getHelpCommandService(Container $container) |
310 | |||
311 | /** |
||
312 | * Get the Input\Cli class service |
||
313 | * |
||
314 | * @param Container $container The DI container. |
||
315 | * |
||
316 | * @return Cli |
||
317 | * |
||
318 | * @since 1.0 |
||
319 | */ |
||
320 | 1 | public function getInputCliService(Container $container) |
|
324 | |||
325 | /** |
||
326 | * Get the Input class service |
||
327 | * |
||
328 | * @param Container $container The DI container. |
||
329 | * |
||
330 | * @return Input |
||
331 | * |
||
332 | * @since 1.0 |
||
333 | */ |
||
334 | 1 | public function getInputService(Container $container) |
|
338 | |||
339 | /** |
||
340 | * Get the InstallCommand class service |
||
341 | * |
||
342 | * @param Container $container The DI container. |
||
343 | * |
||
344 | * @return AppCommands\InstallCommand |
||
345 | * |
||
346 | * @since 1.0 |
||
347 | */ |
||
348 | 1 | View Code Duplication | public function getInstallCommandService(Container $container) |
357 | |||
358 | /** |
||
359 | * Get the router service |
||
360 | * |
||
361 | * @param Container $container The DI container. |
||
362 | * |
||
363 | * @return Router |
||
364 | * |
||
365 | * @since 1.0 |
||
366 | */ |
||
367 | 1 | public function getRouterService(Container $container) |
|
379 | |||
380 | /** |
||
381 | * Get the SnapshotCommand class service |
||
382 | * |
||
383 | * @param Container $container The DI container. |
||
384 | * |
||
385 | * @return AppCommands\SnapshotCommand |
||
386 | * |
||
387 | * @since 1.0 |
||
388 | */ |
||
389 | 1 | View Code Duplication | public function getSnapshotCommandService(Container $container) |
398 | |||
399 | /** |
||
400 | * Get the StatsJsonView class service |
||
401 | * |
||
402 | * @param Container $container The DI container. |
||
403 | * |
||
404 | * @return StatsJsonView |
||
405 | * |
||
406 | * @since 1.0 |
||
407 | */ |
||
408 | 1 | public function getStatsJsonViewService(Container $container) |
|
414 | |||
415 | /** |
||
416 | * Get the StatsModel class service |
||
417 | * |
||
418 | * @param Container $container The DI container. |
||
419 | * |
||
420 | * @return StatsModel |
||
421 | * |
||
422 | * @since 1.0 |
||
423 | */ |
||
424 | 1 | public function getStatsModelService(Container $container) |
|
430 | |||
431 | /** |
||
432 | * Get the SubmitControllerCreate class service |
||
433 | * |
||
434 | * @param Container $container The DI container. |
||
435 | * |
||
436 | * @return SubmitControllerCreate |
||
437 | * |
||
438 | * @since 1.0 |
||
439 | */ |
||
440 | 1 | View Code Duplication | public function getSubmitControllerCreateService(Container $container) |
451 | |||
452 | /** |
||
453 | * Get the SubmitControllerGet class service |
||
454 | * |
||
455 | * @param Container $container The DI container. |
||
456 | * |
||
457 | * @return SubmitControllerGet |
||
458 | * |
||
459 | * @since 1.0 |
||
460 | */ |
||
461 | 1 | View Code Duplication | public function getSubmitControllerGetService(Container $container) |
470 | |||
471 | /** |
||
472 | * Get the Tags\JoomlaCommand class service |
||
473 | * |
||
474 | * @param Container $container The DI container. |
||
475 | * |
||
476 | * @return AppCommands\Tags\JoomlaCommand |
||
477 | * |
||
478 | * @since 1.0 |
||
479 | */ |
||
480 | 1 | View Code Duplication | public function getTagsJoomlaCommandService(Container $container) |
489 | |||
490 | /** |
||
491 | * Get the Tags\PhpCommand class service |
||
492 | * |
||
493 | * @param Container $container The DI container. |
||
494 | * |
||
495 | * @return AppCommands\Tags\PhpCommand |
||
496 | * |
||
497 | * @since 1.0 |
||
498 | */ |
||
499 | 1 | View Code Duplication | public function getTagsPhpCommandService(Container $container) |
508 | |||
509 | /** |
||
510 | * Get the UpdateCommand class service |
||
511 | * |
||
512 | * @param Container $container The DI container. |
||
513 | * |
||
514 | * @return AppCommands\UpdateCommand |
||
515 | * |
||
516 | * @since 1.0 |
||
517 | */ |
||
518 | 1 | View Code Duplication | public function getUpdateCommandService(Container $container) |
527 | |||
528 | /** |
||
529 | * Get the web application service |
||
530 | * |
||
531 | * @param Container $container The DI container. |
||
532 | * |
||
533 | * @return WebApplication |
||
534 | * |
||
535 | * @since 1.0 |
||
536 | */ |
||
537 | 1 | public function getWebApplicationService(Container $container) |
|
548 | } |
||
549 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.