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 |
||
17 | class AppConfig extends AbstractConfig |
||
18 | { |
||
19 | /** |
||
20 | * @var array $routes |
||
21 | */ |
||
22 | private $routes = []; |
||
23 | |||
24 | /** |
||
25 | * @var array $routables |
||
26 | */ |
||
27 | private $routables = []; |
||
28 | |||
29 | /** |
||
30 | * @var array $modules |
||
31 | */ |
||
32 | private $modules = []; |
||
33 | |||
34 | /** |
||
35 | * @param array $routes |
||
36 | * @return AppConfig Chainable |
||
37 | */ |
||
38 | public function set_routes(array $routes) |
||
43 | |||
44 | /** |
||
45 | * @return array |
||
46 | */ |
||
47 | public function routes() |
||
51 | |||
52 | /** |
||
53 | * @param array $routes |
||
|
|||
54 | * @return AppConfig Chainable |
||
55 | */ |
||
56 | public function set_routables(array $routables) |
||
61 | |||
62 | /** |
||
63 | * @return array |
||
64 | */ |
||
65 | public function routables() |
||
69 | |||
70 | /** |
||
71 | * @param array $modules |
||
72 | * @return AppConfig Chainable |
||
73 | */ |
||
74 | public function set_modules(array $modules) |
||
79 | |||
80 | /** |
||
81 | * @return array |
||
82 | */ |
||
83 | public function modules() |
||
87 | |||
88 | /** |
||
89 | * Set the application's available languages |
||
90 | * |
||
91 | * @param Language[] $lang |
||
92 | * @return self |
||
93 | */ |
||
94 | public function set_languages(array $languages) |
||
99 | |||
100 | /** |
||
101 | * Add or update an available language to the application |
||
102 | * |
||
103 | * @param Language $lang |
||
104 | * @return self |
||
105 | */ |
||
106 | public function add_language(Language $lang) |
||
111 | |||
112 | /** |
||
113 | * Get the application's list of available languages |
||
114 | * |
||
115 | * @return Language[] |
||
116 | */ |
||
117 | public function languages() |
||
121 | |||
122 | /** |
||
123 | * Set the application's global TranslationConfig |
||
124 | * |
||
125 | * @param array|TranslationConfig $translation |
||
126 | * @return self |
||
127 | */ |
||
128 | View Code Duplication | public function set_translation($translation) |
|
137 | |||
138 | /** |
||
139 | * Get the application's global TranslationConfig |
||
140 | * |
||
141 | * @return TranslationConfig |
||
142 | */ |
||
143 | public function translation() |
||
147 | } |
||
148 |
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.