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 |
||
| 28 | class AdminXoopsCode |
||
| 29 | { |
||
| 30 | /* |
||
| 31 | * @public function constructor |
||
| 32 | * @param null |
||
| 33 | */ |
||
| 34 | /** |
||
| 35 | * |
||
| 36 | */ |
||
| 37 | public function __construct() |
||
| 42 | |||
| 43 | /* |
||
| 44 | * @static function &getInstance |
||
| 45 | * @param null |
||
| 46 | */ |
||
| 47 | /** |
||
| 48 | * @return AdminXoopsCode |
||
| 49 | */ |
||
| 50 | public static function &getInstance() |
||
| 59 | |||
| 60 | /* |
||
| 61 | * @public function getAdminTemplateMain |
||
| 62 | * @param $moduleDirname |
||
| 63 | * @param $tableName |
||
| 64 | * @return string |
||
| 65 | */ |
||
| 66 | public function getAdminTemplateMain($moduleDirname, $tableName) |
||
| 74 | |||
| 75 | /** |
||
| 76 | * @public function getAdminXoopsTplAssign |
||
| 77 | * |
||
| 78 | * @param string $tplString |
||
| 79 | * @param string $phpRender |
||
| 80 | * |
||
| 81 | * @return string |
||
| 82 | */ |
||
| 83 | public function getAdminXoopsTplAssign($tplString, $phpRender) |
||
| 91 | |||
| 92 | /** |
||
| 93 | * @public function getAdminXoopsTplAppend |
||
| 94 | * |
||
| 95 | * @param string $tplString |
||
| 96 | * @param string $phpRender |
||
| 97 | * |
||
| 98 | * @return string |
||
| 99 | */ |
||
| 100 | public function getAdminXoopsTplAppend($tplString, $phpRender) |
||
| 108 | |||
| 109 | /* |
||
| 110 | * @public function getAdminTemplateMain |
||
| 111 | * @param $moduleDirname |
||
| 112 | * @param $tableName |
||
| 113 | * @param $admin |
||
| 114 | * @return string |
||
| 115 | */ |
||
| 116 | public function getAdminItemButton($moduleDirname, $tableName, $admin = false) |
||
| 127 | |||
| 128 | /** |
||
| 129 | * @public function getAdminAddNavigation |
||
| 130 | * |
||
| 131 | * @param $tableName |
||
| 132 | * |
||
| 133 | * @return string |
||
| 134 | */ |
||
| 135 | public function getAdminAddNavigation($tableName) |
||
| 143 | |||
| 144 | /** |
||
| 145 | * @public function getAdminObjHandlerCreate |
||
| 146 | * |
||
| 147 | * @param string $tableName |
||
| 148 | * |
||
| 149 | * @return string |
||
| 150 | */ |
||
| 151 | public function getAdminObjHandlerCreate($tableName) |
||
| 159 | |||
| 160 | /** |
||
| 161 | * @public function getAdminXoopsCodeSetVarsObjects |
||
| 162 | * |
||
| 163 | * @param $moduleDirname |
||
| 164 | * @param $tableName |
||
| 165 | * @param $fields |
||
| 166 | * |
||
| 167 | * @return string |
||
| 168 | */ |
||
| 169 | View Code Duplication | public function getAdminXoopsCodeSetVarsObjects($moduleDirname, $tableName, $fields) |
|
| 210 | |||
| 211 | /** |
||
| 212 | * @public function getAdminXoopsCodeXoopsSecurity |
||
| 213 | * |
||
| 214 | * @param $tableName |
||
| 215 | * |
||
| 216 | * @return string |
||
| 217 | */ |
||
| 218 | public function getAdminXoopsCodeXoopsSecurity($tableName) |
||
| 228 | |||
| 229 | /* |
||
| 230 | * @public function getAdminXoopsCodeInsertData |
||
| 231 | * @param $tableName |
||
| 232 | * @param $language |
||
| 233 | * @return string |
||
| 234 | */ |
||
| 235 | public function getAdminXoopsCodeInsertData($tableName, $language) |
||
| 246 | |||
| 247 | /** |
||
| 248 | * @public function getAdminXoopsCodeGetFormError |
||
| 249 | * |
||
| 250 | * @param $tableName |
||
| 251 | * |
||
| 252 | * @return string |
||
| 253 | */ |
||
| 254 | public function getAdminXoopsCodeGetFormError($tableName) |
||
| 265 | |||
| 266 | /** |
||
| 267 | * @public function getAdminXoopsCodeGetFormId |
||
| 268 | * |
||
| 269 | * @param string $tableName |
||
| 270 | * @param string $fieldId |
||
| 271 | * |
||
| 272 | * @return string |
||
| 273 | */ |
||
| 274 | public function getAdminXoopsCodeGetFormId($tableName, $fieldId) |
||
| 285 | |||
| 286 | /** |
||
| 287 | * @public function getAdminXoopsCodeGetObjHandlerId |
||
| 288 | * |
||
| 289 | * @param string $tableName |
||
| 290 | * @param string $fieldId |
||
| 291 | * |
||
| 292 | * @return string |
||
| 293 | */ |
||
| 294 | public function getAdminXoopsCodeGetObjHandlerId($tableName, $fieldId) |
||
| 302 | |||
| 303 | /* |
||
| 304 | * @public function getAdminXoopsCodeDelete |
||
| 305 | * @param string $tableName |
||
| 306 | * @param string $language |
||
| 307 | * @param string $fieldId |
||
| 308 | * @param string $fieldMain |
||
| 309 | * @return string |
||
| 310 | */ |
||
| 311 | View Code Duplication | public function getAdminXoopsCodeDelete($tableName, $language, $fieldId, $fieldMain) |
|
| 333 | |||
| 334 | /* |
||
| 335 | * @public function getAdminXoopsCodeUpdate |
||
| 336 | * @param string $moduleDirname |
||
| 337 | * @param string $tableName |
||
| 338 | * @param string $language |
||
| 339 | * @param string $fieldId |
||
| 340 | * @param string $fieldMain |
||
| 341 | * @return string |
||
| 342 | */ |
||
| 343 | View Code Duplication | public function getAdminXoopsCodeUpdate($moduleDirname, $tableName, $language, $fieldId, $fieldMain) |
|
| 362 | } |
||
| 363 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.