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 |
||
10 | class Builder |
||
11 | { |
||
12 | /** |
||
13 | * Get the translation. |
||
14 | * |
||
15 | * @param string $string |
||
16 | * |
||
17 | * @return object |
||
18 | */ |
||
19 | public static function trans($string, $vars = []) |
||
34 | |||
35 | /** |
||
36 | * Generate files json for a specify package |
||
37 | * |
||
38 | * @param string $string |
||
|
|||
39 | * |
||
40 | * @return object |
||
41 | */ |
||
42 | public static function generateTranslations($is_package, $package, $translationsPath, $toLangs='es') |
||
65 | |||
66 | private static function transArray($array, $lang) |
||
87 | |||
88 | |||
89 | /** |
||
90 | * Get the languages that translations has been translated. |
||
91 | * |
||
92 | * @return array |
||
93 | */ |
||
94 | View Code Duplication | public static function toLanguages() |
|
104 | |||
105 | /** |
||
106 | * Get the languages from translations has been translated. |
||
107 | * |
||
108 | * @return array |
||
109 | */ |
||
110 | View Code Duplication | public static function fromLanguages() |
|
120 | |||
121 | /** |
||
122 | * Get all the available languages. |
||
123 | * |
||
124 | * @return array |
||
125 | */ |
||
126 | public static function allLanguages() |
||
141 | } |
||
142 |
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.