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 | class OC_Group_Database extends OC_Group_Backend { |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Try to create a new group |
||
| 55 | * @param string $gid The name of the group to create |
||
| 56 | * @return bool |
||
| 57 | * |
||
| 58 | * Tries to create a new group. If the group name already exists, false will |
||
| 59 | * be returned. |
||
| 60 | */ |
||
| 61 | 338 | public function createGroup( $gid ) { |
|
| 78 | |||
| 79 | /** |
||
| 80 | * delete a group |
||
| 81 | * @param string $gid gid of the group to delete |
||
| 82 | * @return bool |
||
| 83 | * |
||
| 84 | * Deletes a group and removes it from the group_user-table |
||
| 85 | */ |
||
| 86 | 332 | public function deleteGroup( $gid ) { |
|
| 101 | |||
| 102 | /** |
||
| 103 | * is user in group? |
||
| 104 | * @param string $uid uid of the user |
||
| 105 | * @param string $gid gid of the group |
||
| 106 | * @return bool |
||
| 107 | * |
||
| 108 | * Checks whether the user is member of a group or not. |
||
| 109 | */ |
||
| 110 | 357 | View Code Duplication | public function inGroup( $uid, $gid ) { |
| 117 | |||
| 118 | /** |
||
| 119 | * Add a user to a group |
||
| 120 | * @param string $uid Name of the user to add to group |
||
| 121 | * @param string $gid Name of the group in which add the user |
||
| 122 | * @return bool |
||
| 123 | * |
||
| 124 | * Adds a user to a group. |
||
| 125 | */ |
||
| 126 | 348 | View Code Duplication | public function addToGroup( $uid, $gid ) { |
| 136 | |||
| 137 | /** |
||
| 138 | * Removes a user from a group |
||
| 139 | * @param string $uid Name of the user to remove from group |
||
| 140 | * @param string $gid Name of the group from which remove the user |
||
| 141 | * @return bool |
||
| 142 | * |
||
| 143 | * removes the user from a group. |
||
| 144 | */ |
||
| 145 | 339 | public function removeFromGroup( $uid, $gid ) { |
|
| 151 | |||
| 152 | /** |
||
| 153 | * Get all groups a user belongs to |
||
| 154 | * @param string $uid Name of the user |
||
| 155 | * @return array an array of group names |
||
| 156 | * |
||
| 157 | * This function fetches all groups a user belongs to. It does not check |
||
| 158 | * if the user exists at all. |
||
| 159 | */ |
||
| 160 | 480 | View Code Duplication | public function getUserGroups( $uid ) { |
| 172 | |||
| 173 | /** |
||
| 174 | * get a list of all groups |
||
| 175 | * @param string $search |
||
| 176 | * @param int $limit |
||
| 177 | * @param int $offset |
||
| 178 | * @return array an array of group names |
||
| 179 | * |
||
| 180 | * Returns a list with all groups |
||
| 181 | */ |
||
| 182 | 3 | View Code Duplication | public function getGroups($search = '', $limit = null, $offset = null) { |
| 198 | |||
| 199 | /** |
||
| 200 | * check if a group exists |
||
| 201 | * @param string $gid |
||
| 202 | * @return bool |
||
| 203 | */ |
||
| 204 | 339 | View Code Duplication | public function groupExists($gid) { |
| 212 | |||
| 213 | /** |
||
| 214 | * get a list of all users in a group |
||
| 215 | * @param string $gid |
||
| 216 | * @param string $search |
||
| 217 | * @param int $limit |
||
| 218 | * @param int $offset |
||
| 219 | * @return array an array of user ids |
||
| 220 | */ |
||
| 221 | 4 | View Code Duplication | public function usersInGroup($gid, $search = '', $limit = null, $offset = null) { |
| 239 | |||
| 240 | /** |
||
| 241 | * get the number of all users matching the search string in a group |
||
| 242 | * @param string $gid |
||
| 243 | * @param string $search |
||
| 244 | * @return int|false |
||
| 245 | * @throws \OC\DatabaseException |
||
| 246 | */ |
||
| 247 | 1 | public function countUsersInGroup($gid, $search = '') { |
|
| 263 | |||
| 264 | private function escapeLikeParameter($param) { |
||
| 267 | |||
| 268 | } |
||
| 269 |