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 |
||
15 | class PlaceholdersRepository |
||
16 | { |
||
17 | |||
18 | private $configs; |
||
19 | |||
20 | /** |
||
21 | * @var string |
||
22 | */ |
||
23 | private $environment; |
||
24 | |||
25 | public function __construct($configs_mapping) |
||
29 | |||
30 | /** |
||
31 | * |
||
32 | * @return string[] |
||
33 | * @todo read configs and also bring alternative @config:section tags |
||
34 | */ |
||
35 | public function getTags() |
||
39 | |||
40 | /** |
||
41 | * |
||
42 | * @param type $config_files |
||
|
|||
43 | * @todo user %paths.base% value |
||
44 | */ |
||
45 | private function loadConfigFiles($configs_mapping) |
||
54 | |||
55 | View Code Duplication | public function getConfig($key) |
|
62 | |||
63 | View Code Duplication | public function getFilePath($key) |
|
70 | |||
71 | public function getEnvironment() |
||
75 | |||
76 | public function setEnvironment($environment) |
||
80 | |||
81 | public function getReplacement($placeholder, PlaceholderContainer $container) { |
||
94 | |||
95 | private function recursivePlaceholderSearch($keys, $values, $treePosition) |
||
109 | |||
110 | private function getSectionPlaceholders(PlaceholderContainer $container){ |
||
122 | |||
123 | } |
||
124 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.