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 | const ASSETS_FUNCTION = "\\PSFS\\base\\extension\\TemplateFunctions::asset"; |
||
| 17 | const ROUTE_FUNCTION = "\\PSFS\\base\\extension\\TemplateFunctions::route"; |
||
| 18 | const CONFIG_FUNCTION = "\\PSFS\\base\\extension\\TemplateFunctions::config"; |
||
| 19 | const BUTTON_FUNCTION = "\\PSFS\\base\\extension\\TemplateFunctions::button"; |
||
| 20 | const WIDGET_FUNCTION = "\\PSFS\\base\\extension\\TemplateFunctions::widget"; |
||
| 21 | const FORM_FUNCTION = "\\PSFS\\base\\extension\\TemplateFunctions::form"; |
||
| 22 | const RESOURCE_FUNCTION = "\\PSFS\\base\\extension\\TemplateFunctions::resource"; |
||
| 23 | const SESSION_FUNCTION = "\\PSFS\\base\\extension\\TemplateFunctions::session"; |
||
| 24 | const EXISTS_FLASH_FUNCTION = "\\PSFS\\base\\extension\\TemplateFunctions::existsFlash"; |
||
| 25 | const GET_FLASH_FUNCTION = "\\PSFS\\base\\extension\\TemplateFunctions::getFlash"; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Función que copia los recursos de las carpetas Public al DocumentRoot |
||
| 29 | * @param $string |
||
| 30 | * @param null $name |
||
| 31 | * @param bool|TRUE $return |
||
| 32 | * |
||
| 33 | * @return string |
||
| 34 | */ |
||
| 35 | public static function asset($string, $name = null, $return = true) { |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Función que devuelve una url correspondiente a una ruta |
||
| 50 | * @param string $path |
||
| 51 | * @param bool|FALSE $absolute |
||
| 52 | * @param array $params |
||
|
|
|||
| 53 | * |
||
| 54 | * @return string|null |
||
| 55 | */ |
||
| 56 | public static function route($path = '', $absolute = false, array $params = null) { |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Función que devuelve un parámetro de la configuración |
||
| 68 | * @param $param |
||
| 69 | * @param string $default |
||
| 70 | * |
||
| 71 | * @return string |
||
| 72 | */ |
||
| 73 | public static function config($param, $default = '') { |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Método que devuelve un botón en html para la plantilla de formularios |
||
| 79 | * @param array $button |
||
| 80 | */ |
||
| 81 | public static function button(array $button) { |
||
| 86 | |||
| 87 | /** |
||
| 88 | * Función que pinta parte de un formulario |
||
| 89 | * @param array $field |
||
| 90 | * @param StringClass $label |
||
| 91 | */ |
||
| 92 | public static function widget(array $field, StringClass $label = null) { |
||
| 106 | |||
| 107 | /** |
||
| 108 | * Función que deveulve un formulario en html |
||
| 109 | * @param Form $form |
||
| 110 | */ |
||
| 111 | public static function form(Form $form) { |
||
| 116 | |||
| 117 | /** |
||
| 118 | * Función que copia un recurso directamente en el DocumentRoot |
||
| 119 | * @param string $path |
||
| 120 | * @param string $dest |
||
| 121 | * @param bool|FALSE $force |
||
| 122 | * |
||
| 123 | * @return string |
||
| 124 | * @throws ConfigException |
||
| 125 | */ |
||
| 126 | public static function resource($path, $dest, $force = false) { |
||
| 133 | |||
| 134 | /** |
||
| 135 | * Método que extrae el pathname para un dominio |
||
| 136 | * @param string $path |
||
| 137 | * @param $domains |
||
| 138 | * |
||
| 139 | * @return mixed |
||
| 140 | */ |
||
| 141 | private static function extractPathname($path, $domains) |
||
| 157 | |||
| 158 | /** |
||
| 159 | * @param string $filename_path |
||
| 160 | */ |
||
| 161 | private static function processCssLines($filename_path) |
||
| 171 | |||
| 172 | /** |
||
| 173 | * Método que copia el contenido de un recurso en su destino correspondiente |
||
| 174 | * @param string $name |
||
| 175 | * @param string $filename_path |
||
| 176 | * @param string $base |
||
| 177 | * @param string $file_path |
||
| 178 | */ |
||
| 179 | private static function putResourceContent($name, $filename_path, $base, $file_path) |
||
| 185 | |||
| 186 | /** |
||
| 187 | * Método que procesa un recurso para su copia en el DocumentRoot |
||
| 188 | * @param string $string |
||
| 189 | * @param string $name |
||
| 190 | * @param boolean $return |
||
| 191 | * @param string $filename_path |
||
| 192 | * |
||
| 193 | * @return string |
||
| 194 | */ |
||
| 195 | private static function processAsset($string, $name, $return, $filename_path) |
||
| 213 | |||
| 214 | /** |
||
| 215 | * Template function for get a session var |
||
| 216 | * @param string $key |
||
| 217 | * @return mixed |
||
| 218 | */ |
||
| 219 | public static function session($key) { |
||
| 222 | |||
| 223 | /** |
||
| 224 | * Template function that check if exists any flash session var |
||
| 225 | * @param string $key |
||
| 226 | * @return bool |
||
| 227 | */ |
||
| 228 | public static function existsFlash($key = '') { |
||
| 231 | |||
| 232 | /** |
||
| 233 | * Template function that get a flash session var |
||
| 234 | * @param string $key |
||
| 235 | * @return mixed |
||
| 236 | */ |
||
| 237 | public static function getFlash($key) { |
||
| 242 | } |
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.