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 |
||
| 29 | class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP { |
||
| 30 | private $backends = array(); |
||
| 31 | private $refBackend = null; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Constructor |
||
| 35 | * @param string[] $serverConfigPrefixes array containing the config Prefixes |
||
| 36 | */ |
||
| 37 | public function __construct($serverConfigPrefixes, ILDAPWrapper $ldap, GroupPluginManager $groupPluginManager) { |
||
| 38 | parent::__construct($ldap); |
||
| 39 | View Code Duplication | foreach($serverConfigPrefixes as $configPrefix) { |
|
| 40 | $this->backends[$configPrefix] = |
||
| 41 | new \OCA\User_LDAP\Group_LDAP($this->getAccess($configPrefix), $groupPluginManager); |
||
| 42 | if(is_null($this->refBackend)) { |
||
| 43 | $this->refBackend = &$this->backends[$configPrefix]; |
||
| 44 | } |
||
| 45 | } |
||
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Tries the backends one after the other until a positive result is returned from the specified method |
||
| 50 | * @param string $gid the gid connected to the request |
||
| 51 | * @param string $method the method of the group backend that shall be called |
||
| 52 | * @param array $parameters an array of parameters to be passed |
||
| 53 | * @return mixed, the result of the method or false |
||
|
|
|||
| 54 | */ |
||
| 55 | protected function walkBackends($gid, $method, $parameters) { |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Asks the backend connected to the server that supposely takes care of the gid from the request. |
||
| 68 | * @param string $gid the gid connected to the request |
||
| 69 | * @param string $method the method of the group backend that shall be called |
||
| 70 | * @param array $parameters an array of parameters to be passed |
||
| 71 | * @param mixed $passOnWhen the result matches this variable |
||
| 72 | * @return mixed, the result of the method or false |
||
| 73 | */ |
||
| 74 | protected function callOnLastSeenOn($gid, $method, $parameters, $passOnWhen) { |
||
| 97 | |||
| 98 | /** |
||
| 99 | * is user in group? |
||
| 100 | * @param string $uid uid of the user |
||
| 101 | * @param string $gid gid of the group |
||
| 102 | * @return bool |
||
| 103 | * |
||
| 104 | * Checks whether the user is member of a group or not. |
||
| 105 | */ |
||
| 106 | public function inGroup($uid, $gid) { |
||
| 109 | |||
| 110 | /** |
||
| 111 | * Get all groups a user belongs to |
||
| 112 | * @param string $uid Name of the user |
||
| 113 | * @return string[] with group names |
||
| 114 | * |
||
| 115 | * This function fetches all groups a user belongs to. It does not check |
||
| 116 | * if the user exists at all. |
||
| 117 | */ |
||
| 118 | public function getUserGroups($uid) { |
||
| 130 | |||
| 131 | /** |
||
| 132 | * get a list of all users in a group |
||
| 133 | * @return string[] with user ids |
||
| 134 | */ |
||
| 135 | View Code Duplication | public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) { |
|
| 147 | |||
| 148 | /** |
||
| 149 | * @param string $gid |
||
| 150 | * @return bool |
||
| 151 | */ |
||
| 152 | public function createGroup($gid) { |
||
| 156 | |||
| 157 | /** |
||
| 158 | * delete a group |
||
| 159 | * @param string $gid gid of the group to delete |
||
| 160 | * @return bool |
||
| 161 | */ |
||
| 162 | public function deleteGroup($gid) { |
||
| 166 | |||
| 167 | /** |
||
| 168 | * Add a user to a group |
||
| 169 | * @param string $uid Name of the user to add to group |
||
| 170 | * @param string $gid Name of the group in which add the user |
||
| 171 | * @return bool |
||
| 172 | * |
||
| 173 | * Adds a user to a group. |
||
| 174 | */ |
||
| 175 | public function addToGroup($uid, $gid) { |
||
| 179 | |||
| 180 | /** |
||
| 181 | * Removes a user from a group |
||
| 182 | * @param string $uid Name of the user to remove from group |
||
| 183 | * @param string $gid Name of the group from which remove the user |
||
| 184 | * @return bool |
||
| 185 | * |
||
| 186 | * removes the user from a group. |
||
| 187 | */ |
||
| 188 | public function removeFromGroup($uid, $gid) { |
||
| 192 | |||
| 193 | /** |
||
| 194 | * returns the number of users in a group, who match the search term |
||
| 195 | * @param string $gid the internal group name |
||
| 196 | * @param string $search optional, a search string |
||
| 197 | * @return int|bool |
||
| 198 | */ |
||
| 199 | public function countUsersInGroup($gid, $search = '') { |
||
| 203 | |||
| 204 | /** |
||
| 205 | * get an array with group details |
||
| 206 | * @param string $gid |
||
| 207 | * @return array|false |
||
| 208 | */ |
||
| 209 | public function getGroupDetails($gid) { |
||
| 213 | |||
| 214 | /** |
||
| 215 | * get a list of all groups |
||
| 216 | * @return string[] with group names |
||
| 217 | * |
||
| 218 | * Returns a list with all groups |
||
| 219 | */ |
||
| 220 | View Code Duplication | public function getGroups($search = '', $limit = -1, $offset = 0) { |
|
| 232 | |||
| 233 | /** |
||
| 234 | * check if a group exists |
||
| 235 | * @param string $gid |
||
| 236 | * @return bool |
||
| 237 | */ |
||
| 238 | public function groupExists($gid) { |
||
| 241 | |||
| 242 | /** |
||
| 243 | * Check if backend implements actions |
||
| 244 | * @param int $actions bitwise-or'ed actions |
||
| 245 | * @return boolean |
||
| 246 | * |
||
| 247 | * Returns the supported actions as int to be |
||
| 248 | * compared with \OCP\GroupInterface::CREATE_GROUP etc. |
||
| 249 | */ |
||
| 250 | public function implementsActions($actions) { |
||
| 254 | |||
| 255 | /** |
||
| 256 | * Return access for LDAP interaction. |
||
| 257 | * @param string $gid |
||
| 258 | * @return Access instance of Access for LDAP interaction |
||
| 259 | */ |
||
| 260 | public function getLDAPAccess($gid) { |
||
| 263 | |||
| 264 | /** |
||
| 265 | * Return a new LDAP connection for the specified group. |
||
| 266 | * The connection needs to be closed manually. |
||
| 267 | * @param string $gid |
||
| 268 | * @return resource of the LDAP connection |
||
| 269 | */ |
||
| 270 | public function getNewLDAPConnection($gid) { |
||
| 273 | |||
| 274 | } |
||
| 275 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.