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 VestaChangePasswordDriver implements \RainLoop\Providers\ChangePassword\ChangePasswordInterface |
||
| 4 | { |
||
| 5 | /** |
||
| 6 | * @var string |
||
| 7 | */ |
||
| 8 | private $sHost = ''; |
||
| 9 | |||
| 10 | /** |
||
| 11 | * @var string |
||
| 12 | */ |
||
| 13 | private $iPort = 8083; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @var string |
||
| 17 | */ |
||
| 18 | private $sAllowedEmails = ''; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @var \MailSo\Log\Logger |
||
| 22 | */ |
||
| 23 | private $oLogger = null; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @param string $sHost |
||
| 27 | * @param int $iPort |
||
| 28 | * |
||
| 29 | * @return \VestaChangePasswordDriver |
||
| 30 | */ |
||
| 31 | public function SetConfig($sHost, $iPort) |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @param string $sAllowedEmails |
||
| 41 | * |
||
| 42 | * @return \VestaChangePasswordDriver |
||
| 43 | */ |
||
| 44 | public function SetAllowedEmails($sAllowedEmails) |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @param \MailSo\Log\Logger $oLogger |
||
| 52 | * |
||
| 53 | * @return \VestaChangePasswordDriver |
||
| 54 | */ |
||
| 55 | public function SetLogger($oLogger) |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @param \RainLoop\Account $oAccount |
||
| 67 | * |
||
| 68 | * @return bool |
||
| 69 | */ |
||
| 70 | public function PasswordChangePossibility($oAccount) |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @param \RainLoop\Account $oAccount |
||
| 78 | * @param string $sPrevPassword |
||
| 79 | * @param string $sNewPassword |
||
| 80 | * |
||
| 81 | * @return bool |
||
| 82 | */ |
||
| 83 | public function ChangePassword(\RainLoop\Account $oAccount, $sPrevPassword, $sNewPassword) |
||
| 146 | } |
||
| 147 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.