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 |
||
| 22 | * @license GNU GPL (http://www.gnu.org/licenses/gpl-2.0.html/) |
||
| 23 | * @package SmallWorld |
||
| 24 | * @since 1.0 |
||
| 25 | * @author Michael Albertsen (http://culex.dk) <[email protected]> |
||
| 26 | */ |
||
| 27 | class Friends |
||
| 28 | { |
||
| 29 | /** |
||
| 30 | * Show friends of ID |
||
| 31 | * |
||
| 32 | * @deprecated - DO NOT USE |
||
| 33 | * @todo unfinished - needs completion |
||
| 34 | * |
||
| 35 | * @param int $id |
||
| 36 | * @return string |
||
|
|
|||
| 37 | */ |
||
| 38 | public function showFriends($id) |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Get friends array of ID |
||
| 52 | * |
||
| 53 | * must be registered user to call this function |
||
| 54 | * |
||
| 55 | * @param int $id |
||
| 56 | * @param string $action |
||
| 57 | * @return array - empty if nothing found or not authorized |
||
| 58 | */ |
||
| 59 | public function getFriends($id, $action) |
||
| 60 | { |
||
| 61 | $id = (int)$id; |
||
| 62 | $data = []; |
||
| 63 | if ($GLOBALS['xoopsUser'] && ($GLOBALS['xoopsUser'] instanceof \XoopsUser)) { |
||
| 64 | switch ($action) { |
||
| 65 | View Code Duplication | case 'pending': |
|
| 66 | $sql = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_friends') . " WHERE me = '" . $id . "' AND status = " . Constants::FRIEND_STATUS_PENDING; |
||
| 67 | break; |
||
| 68 | View Code Duplication | case 'friends': |
|
| 69 | $sql = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_friends') . " WHERE me = '" . $id . "' AND status = " . Constants::FRIEND_STATUS_APPROVED; |
||
| 70 | break; |
||
| 71 | View Code Duplication | case 'following': |
|
| 72 | $sql = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_followers') . " WHERE me = '" . $id . "'"; |
||
| 73 | break; |
||
| 74 | View Code Duplication | case 'followingme': |
|
| 75 | $sql = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_followers') . " WHERE you = '" . $id . "'"; |
||
| 76 | break; |
||
| 89 |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.