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 |
||
21 | class MonologServiceProvider implements ServiceProviderInterface |
||
22 | { |
||
23 | /** |
||
24 | * Registers the service provider with a DI container. |
||
25 | * |
||
26 | * @param Container $container The DI container. |
||
27 | * |
||
28 | * @return void |
||
29 | */ |
||
30 | 11 | public function register(Container $container): void |
|
53 | |||
54 | /** |
||
55 | * Get the `monolog.processor.psr3` service |
||
56 | * |
||
57 | * @param Container $container The DI container. |
||
58 | * |
||
59 | * @return PsrLogMessageProcessor |
||
60 | */ |
||
61 | public function getMonologProcessorPsr3Service(Container $container): PsrLogMessageProcessor |
||
65 | |||
66 | /** |
||
67 | * Get the `monolog.processor.web` service |
||
68 | * |
||
69 | * @param Container $container The DI container. |
||
70 | * |
||
71 | * @return WebProcessor |
||
72 | */ |
||
73 | 6 | public function getMonologProcessorWebService(Container $container): WebProcessor |
|
77 | |||
78 | /** |
||
79 | * Get the `monolog.handler.application` service |
||
80 | * |
||
81 | * @param Container $container The DI container. |
||
82 | * |
||
83 | * @return StreamHandler |
||
84 | */ |
||
85 | 7 | View Code Duplication | public function getMonologHandlerApplicationService(Container $container): StreamHandler |
94 | |||
95 | /** |
||
96 | * Get the `monolog.handler.database` service |
||
97 | * |
||
98 | * @param Container $container The DI container. |
||
99 | * |
||
100 | * @return StreamHandler |
||
101 | */ |
||
102 | View Code Duplication | public function getMonologHandlerDatabaseService(Container $container): StreamHandler |
|
111 | |||
112 | /** |
||
113 | * Get the `monolog.logger.application` service |
||
114 | * |
||
115 | * @param Container $container The DI container. |
||
116 | * |
||
117 | * @return Logger |
||
118 | */ |
||
119 | 6 | public function getMonologLoggerApplicationService(Container $container): Logger |
|
131 | |||
132 | /** |
||
133 | * Get the `monolog.logger.cli` service |
||
134 | * |
||
135 | * @param Container $container The DI container. |
||
136 | * |
||
137 | * @return Logger |
||
138 | */ |
||
139 | 1 | public function getMonologLoggerCliService(Container $container): Logger |
|
148 | |||
149 | /** |
||
150 | * Get the `monolog.logger.database` service |
||
151 | * |
||
152 | * @param Container $container The DI container. |
||
153 | * |
||
154 | * @return Logger |
||
155 | */ |
||
156 | public function getMonologLoggerDatabaseService(Container $container): Logger |
||
169 | } |
||
170 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.