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 |
||
| 41 | class UserHooks implements IHook { |
||
| 42 | /** |
||
| 43 | * @var KeyManager |
||
| 44 | */ |
||
| 45 | private $keyManager; |
||
| 46 | /** |
||
| 47 | * @var IUserManager |
||
| 48 | */ |
||
| 49 | private $userManager; |
||
| 50 | /** |
||
| 51 | * @var ILogger |
||
| 52 | */ |
||
| 53 | private $logger; |
||
| 54 | /** |
||
| 55 | * @var Setup |
||
| 56 | */ |
||
| 57 | private $userSetup; |
||
| 58 | /** |
||
| 59 | * @var IUserSession |
||
| 60 | */ |
||
| 61 | private $user; |
||
| 62 | /** |
||
| 63 | * @var Util |
||
| 64 | */ |
||
| 65 | private $util; |
||
| 66 | /** |
||
| 67 | * @var Session |
||
| 68 | */ |
||
| 69 | private $session; |
||
| 70 | /** |
||
| 71 | * @var Recovery |
||
| 72 | */ |
||
| 73 | private $recovery; |
||
| 74 | /** |
||
| 75 | * @var Crypt |
||
| 76 | */ |
||
| 77 | private $crypt; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * UserHooks constructor. |
||
| 81 | * |
||
| 82 | * @param KeyManager $keyManager |
||
| 83 | * @param IUserManager $userManager |
||
| 84 | * @param ILogger $logger |
||
| 85 | * @param Setup $userSetup |
||
| 86 | * @param IUserSession $user |
||
| 87 | * @param Util $util |
||
| 88 | * @param Session $session |
||
| 89 | * @param Crypt $crypt |
||
| 90 | * @param Recovery $recovery |
||
| 91 | 9 | */ |
|
| 92 | View Code Duplication | public function __construct(KeyManager $keyManager, |
|
| 112 | |||
| 113 | /** |
||
| 114 | * Connects Hooks |
||
| 115 | * |
||
| 116 | * @return null |
||
| 117 | */ |
||
| 118 | public function addHooks() { |
||
| 138 | |||
| 139 | |||
| 140 | /** |
||
| 141 | * Startup encryption backend upon user login |
||
| 142 | * |
||
| 143 | * @note This method should never be called for users using client side encryption |
||
| 144 | * @param array $params |
||
| 145 | * @return bool |
||
| 146 | 1 | */ |
|
| 147 | public function login($params) { |
||
| 165 | |||
| 166 | /** |
||
| 167 | * remove keys from session during logout |
||
| 168 | 1 | */ |
|
| 169 | 1 | public function logout() { |
|
| 172 | |||
| 173 | /** |
||
| 174 | * setup encryption backend upon user created |
||
| 175 | * |
||
| 176 | * @note This method should never be called for users using client side encryption |
||
| 177 | * @param array $params |
||
| 178 | 1 | */ |
|
| 179 | public function postCreateUser($params) { |
||
| 185 | |||
| 186 | /** |
||
| 187 | * cleanup encryption backend upon user deleted |
||
| 188 | * |
||
| 189 | * @param array $params : uid, password |
||
| 190 | * @note This method should never be called for users using client side encryption |
||
| 191 | 1 | */ |
|
| 192 | public function postDeleteUser($params) { |
||
| 198 | |||
| 199 | /** |
||
| 200 | * If the password can't be changed within ownCloud, than update the key password in advance. |
||
| 201 | * |
||
| 202 | * @param array $params : uid, password |
||
| 203 | * @return bool |
||
| 204 | 2 | */ |
|
| 205 | 2 | public function preSetPassphrase($params) { |
|
| 215 | |||
| 216 | /** |
||
| 217 | * Change a user's encryption passphrase |
||
| 218 | * |
||
| 219 | * @param array $params keys: uid, password |
||
| 220 | * @return bool |
||
| 221 | 2 | */ |
|
| 222 | public function setPassphrase($params) { |
||
| 285 | |||
| 286 | /** |
||
| 287 | * init mount points for given user |
||
| 288 | * |
||
| 289 | * @param string $user |
||
| 290 | * @throws \OC\User\NoUserException |
||
| 291 | 1 | */ |
|
| 292 | 1 | protected function initMountPoints($user) { |
|
| 295 | 1 | ||
| 296 | 1 | ||
| 297 | /** |
||
| 298 | * after password reset we create a new key pair for the user |
||
| 299 | * |
||
| 300 | * @param array $params |
||
| 301 | */ |
||
| 302 | public function postPasswordReset($params) { |
||
| 308 | } |
||
| 309 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: