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 UserPluginManager { |
||
| 29 | |||
| 30 | public $test = false; |
||
| 31 | |||
| 32 | private $respondToActions = 0; |
||
| 33 | |||
| 34 | private $which = array( |
||
| 35 | Backend::CREATE_USER => null, |
||
| 36 | Backend::SET_PASSWORD => null, |
||
| 37 | Backend::GET_HOME => null, |
||
| 38 | Backend::GET_DISPLAYNAME => null, |
||
| 39 | Backend::SET_DISPLAYNAME => null, |
||
| 40 | Backend::PROVIDE_AVATAR => null, |
||
| 41 | Backend::COUNT_USERS => null, |
||
| 42 | 'deleteUser' => null |
||
| 43 | ); |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @return int All implemented actions, except for 'deleteUser' |
||
| 47 | */ |
||
| 48 | public function getImplementedActions() { |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Registers a group plugin that may implement some actions, overriding User_LDAP's user actions. |
||
| 54 | * |
||
| 55 | * @param ILDAPUserPlugin $plugin |
||
| 56 | */ |
||
| 57 | public function register(ILDAPUserPlugin $plugin) { |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Signal if there is a registered plugin that implements some given actions |
||
| 75 | * @param int $actions Actions defined in \OC\User\Backend, like Backend::CREATE_USER |
||
| 76 | * @return bool |
||
| 77 | */ |
||
| 78 | public function implementsActions($actions) { |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Create a new user in LDAP Backend |
||
| 84 | * |
||
| 85 | * @param string $username The username of the user to create |
||
| 86 | * @param string $password The password of the new user |
||
| 87 | * @return bool |
||
| 88 | * @throws \Exception |
||
| 89 | */ |
||
| 90 | public function createUser($username, $password) { |
||
| 98 | |||
| 99 | /** |
||
| 100 | * Change the password of a user* |
||
| 101 | * @param string $uid The username |
||
| 102 | * @param string $password The new password |
||
| 103 | * @return bool |
||
| 104 | * @throws \Exception |
||
| 105 | */ |
||
| 106 | public function setPassword($uid, $password) { |
||
| 114 | |||
| 115 | /** |
||
| 116 | * checks whether the user is allowed to change his avatar in Nextcloud |
||
| 117 | * @param string $uid the Nextcloud user name |
||
| 118 | * @return boolean either the user can or cannot |
||
| 119 | * @throws \Exception |
||
| 120 | */ |
||
| 121 | View Code Duplication | public function canChangeAvatar($uid) { |
|
| 129 | |||
| 130 | /** |
||
| 131 | * Get the user's home directory |
||
| 132 | * @param string $uid the username |
||
| 133 | * @return boolean |
||
| 134 | * @throws \Exception |
||
| 135 | */ |
||
| 136 | View Code Duplication | public function getHome($uid) { |
|
| 144 | |||
| 145 | /** |
||
| 146 | * Get display name of the user |
||
| 147 | * @param string $uid user ID of the user |
||
| 148 | * @return string display name |
||
| 149 | * @throws \Exception |
||
| 150 | */ |
||
| 151 | View Code Duplication | public function getDisplayName($uid) { |
|
| 159 | |||
| 160 | /** |
||
| 161 | * Set display name of the user |
||
| 162 | * @param string $uid user ID of the user |
||
| 163 | * @param string $displayName new user's display name |
||
| 164 | * @return string display name |
||
| 165 | * @throws \Exception |
||
| 166 | */ |
||
| 167 | public function setDisplayName($uid, $displayName) { |
||
| 175 | |||
| 176 | /** |
||
| 177 | * Count the number of users |
||
| 178 | * @return int|bool |
||
| 179 | * @throws \Exception |
||
| 180 | */ |
||
| 181 | View Code Duplication | public function countUsers() { |
|
| 189 | |||
| 190 | /** |
||
| 191 | * @return bool |
||
| 192 | */ |
||
| 193 | public function canDeleteUser() { |
||
| 196 | |||
| 197 | /** |
||
| 198 | * @param $uid |
||
| 199 | * @return bool |
||
| 200 | * @throws \Exception |
||
| 201 | */ |
||
| 202 | public function deleteUser($uid) { |
||
| 209 | } |
||
| 210 | |||
| 211 |