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 ChangePasswordLdapDriver implements \RainLoop\Providers\ChangePassword\ChangePasswordInterface |
||
|
|
|||
| 4 | { |
||
| 5 | /** |
||
| 6 | * @var string |
||
| 7 | */ |
||
| 8 | private $sHostName = '127.0.0.1'; |
||
| 9 | |||
| 10 | /** |
||
| 11 | * @var int |
||
| 12 | */ |
||
| 13 | private $iHostPort = 389; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @var string |
||
| 17 | */ |
||
| 18 | private $sUserDnFormat = ''; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @var string |
||
| 22 | */ |
||
| 23 | private $sPasswordField = 'userPassword'; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var string |
||
| 27 | */ |
||
| 28 | private $sPasswordEncType = 'SHA'; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var \MailSo\Log\Logger |
||
| 32 | */ |
||
| 33 | private $oLogger = null; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @var string |
||
| 37 | */ |
||
| 38 | private $sAllowedEmails = ''; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @param string $sHostName |
||
| 42 | * @param int $iHostPort |
||
| 43 | * @param string $sUserDnFormat |
||
| 44 | * @param string $sPasswordField |
||
| 45 | * @param string $sPasswordEncType |
||
| 46 | * |
||
| 47 | * @return \ChangePasswordLdapDriver |
||
| 48 | */ |
||
| 49 | public function SetConfig($sHostName, $iHostPort, $sUserDnFormat, $sPasswordField, $sPasswordEncType) |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @param string $sAllowedEmails |
||
| 62 | * |
||
| 63 | * @return \ChangePasswordLdapDriver |
||
| 64 | */ |
||
| 65 | public function SetAllowedEmails($sAllowedEmails) |
||
| 71 | |||
| 72 | /** |
||
| 73 | * @param \MailSo\Log\Logger $oLogger |
||
| 74 | * |
||
| 75 | * @return \ChangePasswordLdapDriver |
||
| 76 | */ |
||
| 77 | public function SetLogger($oLogger) |
||
| 86 | |||
| 87 | /** |
||
| 88 | * @param \RainLoop\Account $oAccount |
||
| 89 | * |
||
| 90 | * @return bool |
||
| 91 | */ |
||
| 92 | public function PasswordChangePossibility($oAccount) |
||
| 97 | |||
| 98 | /** |
||
| 99 | * @param \RainLoop\Model\Account $oAccount |
||
| 100 | * @param string $sPrevPassword |
||
| 101 | * @param string $sNewPassword |
||
| 102 | * |
||
| 103 | * @return bool |
||
| 104 | */ |
||
| 105 | public function ChangePassword(\RainLoop\Account $oAccount, $sPrevPassword, $sNewPassword) |
||
| 211 | |||
| 212 | /** |
||
| 213 | * @param int $iLength |
||
| 214 | * |
||
| 215 | * @return string |
||
| 216 | */ |
||
| 217 | private function getSalt($iLength) |
||
| 230 | } |
||
| 231 |
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.