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 |
||
14 | class TemplateFunctions |
||
15 | { |
||
16 | |||
17 | const ASSETS_FUNCTION = "\\PSFS\\base\\extension\\TemplateFunctions::asset"; |
||
18 | const ROUTE_FUNCTION = "\\PSFS\\base\\extension\\TemplateFunctions::route"; |
||
19 | const CONFIG_FUNCTION = "\\PSFS\\base\\extension\\TemplateFunctions::config"; |
||
20 | const BUTTON_FUNCTION = "\\PSFS\\base\\extension\\TemplateFunctions::button"; |
||
21 | const WIDGET_FUNCTION = "\\PSFS\\base\\extension\\TemplateFunctions::widget"; |
||
22 | const FORM_FUNCTION = "\\PSFS\\base\\extension\\TemplateFunctions::form"; |
||
23 | const RESOURCE_FUNCTION = "\\PSFS\\base\\extension\\TemplateFunctions::resource"; |
||
24 | const SESSION_FUNCTION = "\\PSFS\\base\\extension\\TemplateFunctions::session"; |
||
25 | const EXISTS_FLASH_FUNCTION = "\\PSFS\\base\\extension\\TemplateFunctions::existsFlash"; |
||
26 | const GET_FLASH_FUNCTION = "\\PSFS\\base\\extension\\TemplateFunctions::getFlash"; |
||
27 | const GET_QUERY_FUNCTION = "\\PSFS\\base\\extension\\TemplateFunctions::query"; |
||
28 | |||
29 | /** |
||
30 | * Función que copia los recursos de las carpetas Public al DocumentRoot |
||
31 | * @param $string |
||
32 | * @param null $name |
||
33 | * @param bool|TRUE $return |
||
34 | * |
||
35 | * @return string |
||
36 | */ |
||
37 | 1 | public static function asset($string, $name = null, $return = true) |
|
51 | |||
52 | /** |
||
53 | * Función que devuelve una url correspondiente a una ruta |
||
54 | * @param string $path |
||
55 | * @param bool|FALSE $absolute |
||
56 | * @param array $params |
||
57 | * |
||
58 | * @return string|null |
||
59 | */ |
||
60 | 1 | public static function route($path = '', $absolute = false, array $params = []) |
|
69 | |||
70 | /** |
||
71 | * Función que devuelve un parámetro de la configuración |
||
72 | * @param $param |
||
73 | * @param string $default |
||
74 | * |
||
75 | * @return string |
||
76 | */ |
||
77 | 1 | public static function config($param, $default = '') |
|
81 | |||
82 | /** |
||
83 | * Función que devuelve un query string |
||
84 | * @param string $query |
||
85 | * |
||
86 | * @return string |
||
87 | */ |
||
88 | public static function query($query) |
||
92 | |||
93 | /** |
||
94 | * Método que devuelve un botón en html para la plantilla de formularios |
||
95 | * @param array $button |
||
96 | */ |
||
97 | public static function button(array $button) |
||
103 | |||
104 | /** |
||
105 | * Función que pinta parte de un formulario |
||
106 | * @param array $field |
||
107 | * @param StringClass $label |
||
108 | */ |
||
109 | public static function widget(array $field, StringClass $label = null) |
||
124 | |||
125 | /** |
||
126 | * Función que deveulve un formulario en html |
||
127 | * @param Form $form |
||
128 | */ |
||
129 | public static function form(Form $form) |
||
135 | |||
136 | /** |
||
137 | * Función que copia un recurso directamente en el DocumentRoot |
||
138 | * @param string $path |
||
139 | * @param string $dest |
||
140 | * @param bool|FALSE $force |
||
141 | * |
||
142 | * @return string |
||
143 | * @throws ConfigException |
||
144 | */ |
||
145 | 1 | public static function resource($path, $dest, $force = false) |
|
153 | |||
154 | /** |
||
155 | * Método que extrae el pathname para un dominio |
||
156 | * @param string $path |
||
157 | * @param $domains |
||
158 | * |
||
159 | * @return mixed |
||
|
|||
160 | */ |
||
161 | 1 | private static function extractPathname($path, $domains) |
|
177 | |||
178 | /** |
||
179 | * @param string $filename_path |
||
180 | */ |
||
181 | private static function processCssLines($filename_path) |
||
191 | |||
192 | /** |
||
193 | * Método que copia el contenido de un recurso en su destino correspondiente |
||
194 | * @param string $name |
||
195 | * @param string $filename_path |
||
196 | * @param string $base |
||
197 | * @param string $file_path |
||
198 | */ |
||
199 | 1 | private static function putResourceContent($name, $filename_path, $base, $file_path) |
|
205 | |||
206 | /** |
||
207 | * Método que procesa un recurso para su copia en el DocumentRoot |
||
208 | * @param string $string |
||
209 | * @param string $name |
||
210 | * @param boolean $return |
||
211 | * @param string $filename_path |
||
212 | * |
||
213 | * @return string |
||
214 | */ |
||
215 | 1 | private static function processAsset($string, $name, $return, $filename_path) |
|
233 | |||
234 | /** |
||
235 | * Template function for get a session var |
||
236 | * @param string $key |
||
237 | * @return mixed |
||
238 | */ |
||
239 | 1 | public static function session($key) |
|
243 | |||
244 | /** |
||
245 | * Template function that check if exists any flash session var |
||
246 | * @param string $key |
||
247 | * @return bool |
||
248 | */ |
||
249 | 1 | public static function existsFlash($key = '') |
|
253 | |||
254 | /** |
||
255 | * Template function that get a flash session var |
||
256 | * @param string $key |
||
257 | * @return mixed |
||
258 | */ |
||
259 | public static function getFlash($key) |
||
265 | |||
266 | } |
This check looks for the generic type
array
as a return type and suggests a more specific type. This type is inferred from the actual code.