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 |
||
| 3 | class ChangePasswordISPmailDriver implements \RainLoop\Providers\ChangePassword\ChangePasswordInterface |
||
|
|
|||
| 4 | { |
||
| 5 | /** |
||
| 6 | * @var string |
||
| 7 | */ |
||
| 8 | private $sHost = '127.0.0.1'; |
||
| 9 | |||
| 10 | /** |
||
| 11 | * @var int |
||
| 12 | */ |
||
| 13 | private $iPort = 3306; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @var string |
||
| 17 | */ |
||
| 18 | private $sDatabase = 'mailserver'; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @var string |
||
| 22 | */ |
||
| 23 | private $sTable = 'virtual_users'; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var string |
||
| 27 | */ |
||
| 28 | private $sUsercol = 'email'; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var string |
||
| 32 | */ |
||
| 33 | private $sPasscol = 'password'; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @var string |
||
| 37 | */ |
||
| 38 | private $sUser = 'mailuser'; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @var string |
||
| 42 | */ |
||
| 43 | private $sPassword = ''; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @var string |
||
| 47 | */ |
||
| 48 | private $sEncrypt = ''; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @var string |
||
| 52 | */ |
||
| 53 | private $sAllowedEmails = ''; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @var \MailSo\Log\Logger |
||
| 57 | */ |
||
| 58 | private $oLogger = null; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @param string $sHost |
||
| 62 | * |
||
| 63 | * @return \ChangePasswordISPmailDriver |
||
| 64 | */ |
||
| 65 | public function SetHost($sHost) |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @param int $iPort |
||
| 73 | * |
||
| 74 | * @return \ChangePasswordISPmailDriver |
||
| 75 | */ |
||
| 76 | public function SetPort($iPort) |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @param string $sDatabase |
||
| 84 | * |
||
| 85 | * @return \ChangePasswordISPmailDriver |
||
| 86 | */ |
||
| 87 | public function SetDatabase($sDatabase) |
||
| 92 | |||
| 93 | /** |
||
| 94 | * @param string $sTable |
||
| 95 | * |
||
| 96 | * @return \ChangePasswordISPmailDriver |
||
| 97 | */ |
||
| 98 | public function SetTable($sTable) |
||
| 103 | |||
| 104 | /** |
||
| 105 | * @param string $sUsercol |
||
| 106 | * |
||
| 107 | * @return \ChangePasswordISPmailDriver |
||
| 108 | */ |
||
| 109 | public function SetUserColumn($sUsercol) |
||
| 114 | |||
| 115 | /** |
||
| 116 | * @param string $sPasscol |
||
| 117 | * |
||
| 118 | * @return \ChangePasswordISPmailDriver |
||
| 119 | */ |
||
| 120 | public function SetPasswordColumn($sPasscol) |
||
| 125 | |||
| 126 | /** |
||
| 127 | * @param string $sUser |
||
| 128 | * |
||
| 129 | * @return \ChangePasswordISPmailDriver |
||
| 130 | */ |
||
| 131 | public function SetUser($sUser) |
||
| 136 | |||
| 137 | /** |
||
| 138 | * @param string $sPassword |
||
| 139 | * |
||
| 140 | * @return \ChangePasswordISPmailDriver |
||
| 141 | */ |
||
| 142 | public function SetPassword($sPassword) |
||
| 147 | |||
| 148 | /** |
||
| 149 | * @param string $sEncrypt |
||
| 150 | * |
||
| 151 | * @return \ChangePasswordISPmailDriver |
||
| 152 | */ |
||
| 153 | public function SetEncrypt($sEncrypt) |
||
| 158 | |||
| 159 | /** |
||
| 160 | * @param string $sAllowedEmails |
||
| 161 | * |
||
| 162 | * @return \ChangePasswordISPmailDriver |
||
| 163 | */ |
||
| 164 | public function SetAllowedEmails($sAllowedEmails) |
||
| 169 | |||
| 170 | /** |
||
| 171 | * @param \MailSo\Log\Logger $oLogger |
||
| 172 | * |
||
| 173 | * @return \ChangePasswordISPmailDriver |
||
| 174 | */ |
||
| 175 | public function SetLogger($oLogger) |
||
| 184 | |||
| 185 | /** |
||
| 186 | * @param \RainLoop\Model\Account $oAccount |
||
| 187 | * |
||
| 188 | * @return bool |
||
| 189 | */ |
||
| 190 | public function PasswordChangePossibility($oAccount) |
||
| 195 | |||
| 196 | /** |
||
| 197 | * @param \RainLoop\Model\Account $oAccount |
||
| 198 | * @param string $sPrevPassword |
||
| 199 | * @param string $sNewPassword |
||
| 200 | * |
||
| 201 | * @return bool |
||
| 202 | */ |
||
| 203 | View Code Duplication | public function ChangePassword(\RainLoop\Account $oAccount, $sPrevPassword, $sNewPassword) |
|
| 251 | |||
| 252 | /** |
||
| 253 | * @param string $sPassword |
||
| 254 | * @param \PDO $oPdo |
||
| 255 | * |
||
| 256 | * @return string |
||
| 257 | */ |
||
| 258 | private function cryptPassword($sPassword, $oPdo) |
||
| 276 | } |
||
| 277 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.