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 |
||
36 | class ApplicationServiceProvider implements ServiceProviderInterface |
||
37 | { |
||
38 | /** |
||
39 | * Registers the service provider with a DI container. |
||
40 | * |
||
41 | * @param Container $container The DI container. |
||
42 | * |
||
43 | * @return void |
||
44 | */ |
||
45 | 1 | public function register(Container $container) |
|
46 | { |
||
47 | /* |
||
48 | * Application Classes |
||
49 | */ |
||
50 | |||
51 | 1 | $container->alias(CliApplication::class, JoomlaApplication\AbstractCliApplication::class) |
|
52 | 1 | ->share(JoomlaApplication\AbstractCliApplication::class, [$this, 'getCliApplicationService'], true); |
|
53 | |||
54 | 1 | $container->alias(WebApplication::class, JoomlaApplication\AbstractWebApplication::class) |
|
55 | 1 | ->share(JoomlaApplication\AbstractWebApplication::class, [$this, 'getWebApplicationService'], true); |
|
56 | |||
57 | /* |
||
58 | * Application Class Dependencies |
||
59 | */ |
||
60 | |||
61 | 1 | $container->share(Analytics::class, [$this, 'getAnalyticsService'], true); |
|
62 | 1 | $container->share(Cli::class, [$this, 'getInputCliService'], true); |
|
63 | 1 | $container->share(Console::class, [$this, 'getConsoleService'], true); |
|
64 | 1 | $container->share(Input::class, [$this, 'getInputService'], true); |
|
65 | 1 | $container->share(JoomlaApplication\Cli\Output\Processor\ColorProcessor::class, [$this, 'getColorProcessorService'], true); |
|
66 | 1 | $container->share(JoomlaApplication\Cli\CliInput::class, [$this, 'getCliInputService'], true); |
|
67 | 1 | $container->share(Router::class, [$this, 'getRouterService'], true); |
|
68 | |||
69 | 1 | $container->alias(JoomlaApplication\Cli\CliOutput::class, JoomlaApplication\Cli\Output\Stdout::class) |
|
70 | 1 | ->share(JoomlaApplication\Cli\Output\Stdout::class, [$this, 'getCliOutputService'], true); |
|
71 | |||
72 | /* |
||
73 | * Console Commands |
||
74 | */ |
||
75 | |||
76 | 1 | $container->share(AppCommands\HelpCommand::class, [$this, 'getHelpCommandService'], true); |
|
77 | 1 | $container->share(AppCommands\InstallCommand::class, [$this, 'getInstallCommandService'], true); |
|
78 | 1 | $container->share(AppCommands\Database\MigrateCommand::class, [$this, 'getDatabaseMigrateCommandService'], true); |
|
79 | 1 | $container->share(AppCommands\Database\StatusCommand::class, [$this, 'getDatabaseStatusCommandService'], true); |
|
80 | 1 | $container->share(AppCommands\Snapshot\RecentCommand::class, [$this, 'getSnapshotRecentCommandService'], true); |
|
81 | 1 | $container->share(AppCommands\SnapshotCommand::class, [$this, 'getSnapshotCommandService'], true); |
|
82 | 1 | $container->share(AppCommands\Tags\JoomlaCommand::class, [$this, 'getTagsJoomlaCommandService'], true); |
|
83 | 1 | $container->share(AppCommands\Tags\PhpCommand::class, [$this, 'getTagsPhpCommandService'], true); |
|
84 | 1 | $container->share(AppCommands\UpdateCommand::class, [$this, 'getUpdateCommandService'], true); |
|
85 | |||
86 | /* |
||
87 | * MVC Layer |
||
88 | */ |
||
89 | |||
90 | // Controllers |
||
91 | 1 | $container->share(DisplayControllerCreate::class, [$this, 'getDisplayControllerCreateService'], true); |
|
92 | 1 | $container->share(DisplayControllerGet::class, [$this, 'getDisplayControllerGetService'], true); |
|
93 | 1 | $container->share(SubmitControllerCreate::class, [$this, 'getSubmitControllerCreateService'], true); |
|
94 | 1 | $container->share(SubmitControllerGet::class, [$this, 'getSubmitControllerGetService'], true); |
|
95 | |||
96 | // Models |
||
97 | 1 | $container->share(StatsModel::class, [$this, 'getStatsModelService'], true); |
|
98 | |||
99 | // Views |
||
100 | 1 | $container->share(StatsJsonView::class, [$this, 'getStatsJsonViewService'], true); |
|
101 | 1 | } |
|
102 | |||
103 | /** |
||
104 | * Get the Analytics class service |
||
105 | * |
||
106 | * @param Container $container The DI container. |
||
107 | * |
||
108 | * @return Analytics |
||
109 | */ |
||
110 | 1 | public function getAnalyticsService(Container $container) |
|
114 | |||
115 | /** |
||
116 | * Get the CLI application service |
||
117 | * |
||
118 | * @param Container $container The DI container. |
||
119 | * |
||
120 | * @return CliApplication |
||
121 | */ |
||
122 | 1 | public function getCliApplicationService(Container $container) : CliApplication |
|
137 | |||
138 | /** |
||
139 | * Get the CliInput class service |
||
140 | * |
||
141 | * @param Container $container The DI container. |
||
142 | * |
||
143 | * @return JoomlaApplication\Cli\CliInput |
||
144 | */ |
||
145 | 1 | public function getCliInputService(Container $container) : JoomlaApplication\Cli\CliInput |
|
149 | |||
150 | /** |
||
151 | * Get the CliOutput class service |
||
152 | * |
||
153 | * @param Container $container The DI container. |
||
154 | * |
||
155 | * @return JoomlaApplication\Cli\CliOutput |
||
156 | */ |
||
157 | 1 | public function getCliOutputService(Container $container) : JoomlaApplication\Cli\Output\Stdout |
|
161 | |||
162 | /** |
||
163 | * Get the ColorProcessor class service |
||
164 | * |
||
165 | * @param Container $container The DI container. |
||
166 | * |
||
167 | * @return JoomlaApplication\Cli\Output\Processor\ColorProcessor |
||
168 | */ |
||
169 | 1 | public function getColorProcessorService(Container $container) : JoomlaApplication\Cli\Output\Processor\ColorProcessor |
|
186 | |||
187 | /** |
||
188 | * Get the console service |
||
189 | * |
||
190 | * @param Container $container The DI container. |
||
191 | * |
||
192 | * @return Console |
||
193 | */ |
||
194 | 1 | public function getConsoleService(Container $container) : Console |
|
201 | |||
202 | /** |
||
203 | * Get the Database\MigrateCommand class service |
||
204 | * |
||
205 | * @param Container $container The DI container. |
||
206 | * |
||
207 | * @return AppCommands\Database\MigrateCommand |
||
208 | */ |
||
209 | 1 | public function getDatabaseMigrateCommandService(Container $container) : AppCommands\Database\MigrateCommand |
|
219 | |||
220 | /** |
||
221 | * Get the Database\StatusCommand class service |
||
222 | * |
||
223 | * @param Container $container The DI container. |
||
224 | * |
||
225 | * @return AppCommands\Database\StatusCommand |
||
226 | */ |
||
227 | 1 | View Code Duplication | public function getDatabaseStatusCommandService(Container $container) : AppCommands\Database\StatusCommand |
236 | |||
237 | /** |
||
238 | * Get the DisplayControllerCreate class service |
||
239 | * |
||
240 | * @param Container $container The DI container. |
||
241 | * |
||
242 | * @return DisplayControllerCreate |
||
243 | */ |
||
244 | View Code Duplication | public function getDisplayControllerCreateService(Container $container) : DisplayControllerCreate |
|
253 | |||
254 | /** |
||
255 | * Get the DisplayControllerGet class service |
||
256 | * |
||
257 | * @param Container $container The DI container. |
||
258 | * |
||
259 | * @return DisplayControllerGet |
||
260 | */ |
||
261 | 1 | View Code Duplication | public function getDisplayControllerGetService(Container $container) : DisplayControllerGet |
272 | |||
273 | /** |
||
274 | * Get the HelpCommand class service |
||
275 | * |
||
276 | * @param Container $container The DI container. |
||
277 | * |
||
278 | * @return AppCommands\HelpCommand |
||
279 | */ |
||
280 | 1 | View Code Duplication | public function getHelpCommandService(Container $container) : AppCommands\HelpCommand |
289 | |||
290 | /** |
||
291 | * Get the Input\Cli class service |
||
292 | * |
||
293 | * @param Container $container The DI container. |
||
294 | * |
||
295 | * @return Cli |
||
296 | */ |
||
297 | 1 | public function getInputCliService(Container $container) : Cli |
|
301 | |||
302 | /** |
||
303 | * Get the Input class service |
||
304 | * |
||
305 | * @param Container $container The DI container. |
||
306 | * |
||
307 | * @return Input |
||
308 | */ |
||
309 | 1 | public function getInputService(Container $container) : Input |
|
313 | |||
314 | /** |
||
315 | * Get the InstallCommand class service |
||
316 | * |
||
317 | * @param Container $container The DI container. |
||
318 | * |
||
319 | * @return AppCommands\InstallCommand |
||
320 | */ |
||
321 | 1 | View Code Duplication | public function getInstallCommandService(Container $container) : AppCommands\InstallCommand |
330 | |||
331 | /** |
||
332 | * Get the router service |
||
333 | * |
||
334 | * @param Container $container The DI container. |
||
335 | * |
||
336 | * @return Router |
||
337 | */ |
||
338 | 1 | public function getRouterService(Container $container) : Router |
|
350 | |||
351 | /** |
||
352 | * Get the SnapshotCommand class service |
||
353 | * |
||
354 | * @param Container $container The DI container. |
||
355 | * |
||
356 | * @return AppCommands\SnapshotCommand |
||
357 | */ |
||
358 | 1 | View Code Duplication | public function getSnapshotCommandService(Container $container) : AppCommands\SnapshotCommand |
367 | |||
368 | /** |
||
369 | * Get the RecentCommand class service |
||
370 | * |
||
371 | * @param Container $container The DI container. |
||
372 | * |
||
373 | * @return AppCommands\Snapshot\RecentCommand |
||
374 | */ |
||
375 | View Code Duplication | public function getSnapshotRecentCommandService(Container $container) : AppCommands\Snapshot\RecentCommand |
|
384 | |||
385 | /** |
||
386 | * Get the StatsJsonView class service |
||
387 | * |
||
388 | * @param Container $container The DI container. |
||
389 | * |
||
390 | * @return StatsJsonView |
||
391 | */ |
||
392 | 1 | public function getStatsJsonViewService(Container $container) : StatsJsonView |
|
398 | |||
399 | /** |
||
400 | * Get the StatsModel class service |
||
401 | * |
||
402 | * @param Container $container The DI container. |
||
403 | * |
||
404 | * @return StatsModel |
||
405 | */ |
||
406 | 1 | public function getStatsModelService(Container $container) : StatsModel |
|
412 | |||
413 | /** |
||
414 | * Get the SubmitControllerCreate class service |
||
415 | * |
||
416 | * @param Container $container The DI container. |
||
417 | * |
||
418 | * @return SubmitControllerCreate |
||
419 | */ |
||
420 | 1 | View Code Duplication | public function getSubmitControllerCreateService(Container $container) : SubmitControllerCreate |
431 | |||
432 | /** |
||
433 | * Get the SubmitControllerGet class service |
||
434 | * |
||
435 | * @param Container $container The DI container. |
||
436 | * |
||
437 | * @return SubmitControllerGet |
||
438 | */ |
||
439 | 1 | View Code Duplication | public function getSubmitControllerGetService(Container $container) : SubmitControllerGet |
448 | |||
449 | /** |
||
450 | * Get the Tags\JoomlaCommand class service |
||
451 | * |
||
452 | * @param Container $container The DI container. |
||
453 | * |
||
454 | * @return AppCommands\Tags\JoomlaCommand |
||
455 | */ |
||
456 | 1 | View Code Duplication | public function getTagsJoomlaCommandService(Container $container) : AppCommands\Tags\JoomlaCommand |
465 | |||
466 | /** |
||
467 | * Get the Tags\PhpCommand class service |
||
468 | * |
||
469 | * @param Container $container The DI container. |
||
470 | * |
||
471 | * @return AppCommands\Tags\PhpCommand |
||
472 | */ |
||
473 | 1 | View Code Duplication | public function getTagsPhpCommandService(Container $container) : AppCommands\Tags\PhpCommand |
482 | |||
483 | /** |
||
484 | * Get the UpdateCommand class service |
||
485 | * |
||
486 | * @param Container $container The DI container. |
||
487 | * |
||
488 | * @return AppCommands\UpdateCommand |
||
489 | */ |
||
490 | 1 | View Code Duplication | public function getUpdateCommandService(Container $container) : AppCommands\UpdateCommand |
499 | |||
500 | /** |
||
501 | * Get the web application service |
||
502 | * |
||
503 | * @param Container $container The DI container. |
||
504 | * |
||
505 | * @return WebApplication |
||
506 | */ |
||
507 | 1 | public function getWebApplicationService(Container $container) : WebApplication |
|
518 | } |
||
519 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.