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 |
||
| 51 | if (!function_exists('InfoColumnExists')) { |
||
| 52 | /** |
||
| 53 | * @param $tablename |
||
| 54 | * @param $spalte |
||
| 55 | * |
||
| 56 | * @return bool |
||
| 57 | */ |
||
| 58 | function InfoColumnExists($tablename, $spalte) |
||
| 59 | { |
||
| 60 | if ('' === $tablename || '' === $spalte) { |
||
| 61 | return true; |
||
| 62 | } // Fehler!! |
||
| 63 | $result = $GLOBALS['xoopsDB']->queryF('SHOW COLUMNS FROM ' . $tablename . " LIKE '" . $spalte . "'"); |
||
| 64 | $ret = $GLOBALS['xoopsDB']->getRowsNum($result) > 0; |
||
| 65 | |||
| 66 | return $ret; |
||
| 67 | } |
||
| 68 | } |
||
| 69 | |||
| 70 | if (!function_exists('InfoTableExists')) { |
||
| 71 | /** |
||
| 72 | * @param $tablename |
||
| 73 | * |
||
| 74 | * @return bool |
||
| 75 | */ |
||
| 76 | function InfoTableExists($tablename) |
||
| 82 | } |
||
| 83 | } |
||
| 84 |