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 | public static function asset($string, $name = null, $return = true) |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Función que devuelve una url correspondiente a una ruta |
||
| 53 | * @param string $path |
||
| 54 | * @param bool|FALSE $absolute |
||
| 55 | * @param array $params |
||
|
|
|||
| 56 | * |
||
| 57 | * @return string|null |
||
| 58 | */ |
||
| 59 | 1 | public static function route($path = '', $absolute = false, array $params = null) |
|
| 68 | |||
| 69 | /** |
||
| 70 | * Función que devuelve un parámetro de la configuración |
||
| 71 | * @param $param |
||
| 72 | * @param string $default |
||
| 73 | * |
||
| 74 | * @return string |
||
| 75 | */ |
||
| 76 | 1 | public static function config($param, $default = '') |
|
| 80 | |||
| 81 | /** |
||
| 82 | * Función que devuelve un query string |
||
| 83 | * @param string $query |
||
| 84 | * |
||
| 85 | * @return string |
||
| 86 | */ |
||
| 87 | public static function query($query) |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Método que devuelve un botón en html para la plantilla de formularios |
||
| 94 | * @param array $button |
||
| 95 | */ |
||
| 96 | public static function button(array $button) |
||
| 102 | |||
| 103 | /** |
||
| 104 | * Función que pinta parte de un formulario |
||
| 105 | * @param array $field |
||
| 106 | * @param StringClass $label |
||
| 107 | */ |
||
| 108 | public static function widget(array $field, StringClass $label = null) |
||
| 123 | |||
| 124 | /** |
||
| 125 | * Función que deveulve un formulario en html |
||
| 126 | * @param Form $form |
||
| 127 | */ |
||
| 128 | public static function form(Form $form) |
||
| 134 | |||
| 135 | /** |
||
| 136 | * Función que copia un recurso directamente en el DocumentRoot |
||
| 137 | * @param string $path |
||
| 138 | * @param string $dest |
||
| 139 | * @param bool|FALSE $force |
||
| 140 | * |
||
| 141 | * @return string |
||
| 142 | * @throws ConfigException |
||
| 143 | */ |
||
| 144 | public static function resource($path, $dest, $force = false) |
||
| 152 | |||
| 153 | /** |
||
| 154 | * Método que extrae el pathname para un dominio |
||
| 155 | * @param string $path |
||
| 156 | * @param $domains |
||
| 157 | * |
||
| 158 | * @return mixed |
||
| 159 | */ |
||
| 160 | private static function extractPathname($path, $domains) |
||
| 176 | |||
| 177 | /** |
||
| 178 | * @param string $filename_path |
||
| 179 | */ |
||
| 180 | private static function processCssLines($filename_path) |
||
| 190 | |||
| 191 | /** |
||
| 192 | * Método que copia el contenido de un recurso en su destino correspondiente |
||
| 193 | * @param string $name |
||
| 194 | * @param string $filename_path |
||
| 195 | * @param string $base |
||
| 196 | * @param string $file_path |
||
| 197 | */ |
||
| 198 | private static function putResourceContent($name, $filename_path, $base, $file_path) |
||
| 204 | |||
| 205 | /** |
||
| 206 | * Método que procesa un recurso para su copia en el DocumentRoot |
||
| 207 | * @param string $string |
||
| 208 | * @param string $name |
||
| 209 | * @param boolean $return |
||
| 210 | * @param string $filename_path |
||
| 211 | * |
||
| 212 | * @return string |
||
| 213 | */ |
||
| 214 | private static function processAsset($string, $name, $return, $filename_path) |
||
| 232 | |||
| 233 | /** |
||
| 234 | * Template function for get a session var |
||
| 235 | * @param string $key |
||
| 236 | * @return mixed |
||
| 237 | */ |
||
| 238 | public static function session($key) |
||
| 242 | |||
| 243 | /** |
||
| 244 | * Template function that check if exists any flash session var |
||
| 245 | * @param string $key |
||
| 246 | * @return bool |
||
| 247 | */ |
||
| 248 | 1 | public static function existsFlash($key = '') |
|
| 252 | |||
| 253 | /** |
||
| 254 | * Template function that get a flash session var |
||
| 255 | * @param string $key |
||
| 256 | * @return mixed |
||
| 257 | */ |
||
| 258 | public static function getFlash($key) |
||
| 264 | } |
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive. In addition it looks for parameters that have the generic type
arrayand suggests a stricter type likearray<String>.Most often this is a case of a parameter that can be null in addition to its declared types.