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 |
||
18 | final class PlaceholdersExtension implements Extension |
||
19 | { |
||
20 | |||
21 | const PLACEHOLDERS_REPLACER_ID = 'placeholders.replacer'; |
||
22 | const PLACEHOLDERS_REPOSITIORY_ID = 'placeholders.repository'; |
||
23 | const PLACEHOLDERS_CONTROLLER_ID = 'placeholders.controller'; |
||
24 | const VARIANTS_PREPROCESSOR_ID = 'placeholders.variants_preprocessor'; |
||
25 | |||
26 | /** |
||
27 | * Returns the extension config key. |
||
28 | * |
||
29 | * @return string |
||
30 | */ |
||
31 | public function getConfigKey() |
||
35 | |||
36 | /** |
||
37 | * {@inheritdoc} |
||
38 | */ |
||
39 | public function process(ContainerBuilder $container) |
||
43 | |||
44 | /** |
||
45 | * {@inheritdoc} |
||
46 | */ |
||
47 | public function initialize(ExtensionManager $extensionManager) |
||
51 | |||
52 | /** |
||
53 | * {@inheritdoc} |
||
54 | */ |
||
55 | public function configure(ArrayNodeDefinition $builder) |
||
72 | |||
73 | /** |
||
74 | * Loads extension services into temporary container. |
||
75 | * |
||
76 | * @param ContainerBuilder $container |
||
77 | * @param array $config |
||
78 | */ |
||
79 | public function load(ContainerBuilder $container, array $config) |
||
86 | |||
87 | /** |
||
88 | * @param ContainerBuilder $container |
||
89 | */ |
||
90 | private function loadPlaceholdersController(ContainerBuilder $container) |
||
97 | |||
98 | /** |
||
99 | * Loads event-dispatching feature tester. |
||
100 | * |
||
101 | * @param ContainerBuilder $container |
||
102 | */ |
||
103 | protected function loadPlaceholdersRepository(ContainerBuilder $container, $configs_mapping) |
||
110 | |||
111 | /** |
||
112 | * Loads event-dispatching feature tester. |
||
113 | * |
||
114 | * @param ContainerBuilder $container |
||
115 | */ |
||
116 | View Code Duplication | protected function loadScenarioForkingFeatureTester(ContainerBuilder $container, $variantTags) |
|
126 | |||
127 | /** |
||
128 | * Loads step tester. |
||
129 | * |
||
130 | * @param ContainerBuilder $container |
||
131 | */ |
||
132 | View Code Duplication | protected function loadStepTester(ContainerBuilder $container, $variantTags) |
|
142 | } |
||
143 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.