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 GroupPluginManager { |
||
| 29 | |||
| 30 | private $respondToActions = 0; |
||
| 31 | |||
| 32 | private $which = array( |
||
| 33 | GroupInterface::CREATE_GROUP => null, |
||
| 34 | GroupInterface::DELETE_GROUP => null, |
||
| 35 | GroupInterface::ADD_TO_GROUP => null, |
||
| 36 | GroupInterface::REMOVE_FROM_GROUP => null, |
||
| 37 | GroupInterface::COUNT_USERS => null, |
||
| 38 | GroupInterface::GROUP_DETAILS => null |
||
| 39 | ); |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @return int All implemented actions |
||
| 43 | */ |
||
| 44 | public function getImplementedActions() { |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Registers a group plugin that may implement some actions, overriding User_LDAP's group actions. |
||
| 50 | * @param ILDAPGroupPlugin $plugin |
||
| 51 | */ |
||
| 52 | public function register(ILDAPGroupPlugin $plugin) { |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Signal if there is a registered plugin that implements some given actions |
||
| 66 | * @param int $actions Actions defined in \OCP\GroupInterface, like GroupInterface::REMOVE_FROM_GROUP |
||
| 67 | * @return bool |
||
| 68 | */ |
||
| 69 | public function implementsActions($actions) { |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Create a group |
||
| 75 | * @param string $gid Group Id |
||
| 76 | * @return string | null The group DN if group creation was successful. |
||
| 77 | * @throws \Exception |
||
| 78 | */ |
||
| 79 | View Code Duplication | public function createGroup($gid) { |
|
| 87 | |||
| 88 | /** |
||
| 89 | * Delete a group |
||
| 90 | * @param string $gid Group Id of the group to delete |
||
| 91 | * @return bool |
||
| 92 | * @throws \Exception |
||
| 93 | */ |
||
| 94 | View Code Duplication | public function deleteGroup($gid) { |
|
| 102 | |||
| 103 | /** |
||
| 104 | * Add a user to a group |
||
| 105 | * @param string $uid ID of the user to add to group |
||
| 106 | * @param string $gid ID of the group in which add the user |
||
| 107 | * @return bool |
||
| 108 | * @throws \Exception |
||
| 109 | * |
||
| 110 | * Adds a user to a group. |
||
| 111 | */ |
||
| 112 | View Code Duplication | public function addToGroup($uid, $gid) { |
|
| 120 | |||
| 121 | /** |
||
| 122 | * Removes a user from a group |
||
| 123 | * @param string $uid ID of the user to remove from group |
||
| 124 | * @param string $gid ID of the group from which remove the user |
||
| 125 | * @return bool |
||
| 126 | * @throws \Exception |
||
| 127 | * |
||
| 128 | * removes the user from a group. |
||
| 129 | */ |
||
| 130 | View Code Duplication | public function removeFromGroup($uid, $gid) { |
|
| 138 | |||
| 139 | /** |
||
| 140 | * get the number of all users matching the search string in a group |
||
| 141 | * @param string $gid ID of the group |
||
| 142 | * @param string $search query string |
||
| 143 | * @return int|false |
||
| 144 | * @throws \Exception |
||
| 145 | */ |
||
| 146 | public function countUsersInGroup($gid, $search = '') { |
||
| 154 | |||
| 155 | /** |
||
| 156 | * get an array with group details |
||
| 157 | * @param string $gid |
||
| 158 | * @return array|false |
||
| 159 | * @throws \Exception |
||
| 160 | */ |
||
| 161 | View Code Duplication | public function getGroupDetails($gid) { |
|
| 169 | } |
||
| 170 |