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 |
||
11 | class Builder |
||
12 | { |
||
13 | /** |
||
14 | * Get the trnaslation. |
||
15 | * |
||
16 | * @param string $string |
||
17 | * |
||
18 | * @return object |
||
19 | */ |
||
20 | public static function trans($string) |
||
35 | |||
36 | /** |
||
37 | * Get the languages that translations has been translated. |
||
38 | * |
||
39 | * @return array |
||
40 | */ |
||
41 | View Code Duplication | public static function toLanguages() |
|
51 | |||
52 | /** |
||
53 | * Get the languages from translations has been translated. |
||
54 | * |
||
55 | * @return array |
||
56 | */ |
||
57 | View Code Duplication | public static function fromLanguages() |
|
67 | |||
68 | /** |
||
69 | * Get all the available languages. |
||
70 | * |
||
71 | * @return array |
||
72 | */ |
||
73 | public static function allLanguages() |
||
88 | |||
89 | |||
90 | /** |
||
91 | * Return secure_asset method or asset method depending on config https |
||
92 | * |
||
93 | * @param string $asset |
||
94 | * |
||
95 | * @return string |
||
96 | */ |
||
97 | public static function checkAsset($asset) |
||
104 | |||
105 | /** |
||
106 | * Return secure_url method or url method depending on config https |
||
107 | * |
||
108 | * @param string $url |
||
109 | * |
||
110 | * @return string |
||
111 | */ |
||
112 | public static function checkUrl($url) |
||
119 | |||
120 | /** |
||
121 | * Return secure_url method or url method depending on config https |
||
122 | * |
||
123 | * @param string $url |
||
124 | * |
||
125 | * @return string |
||
126 | */ |
||
127 | public static function checkRoute($routeName, $routeArgs = NULL) |
||
140 | } |
||
141 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.