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 |
||
| 7 | class VirtualminChangePasswordDriver implements \RainLoop\Providers\ChangePassword\ChangePasswordInterface |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @var string |
||
| 11 | */ |
||
| 12 | private $sAllowedEmails = ''; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @var string |
||
| 16 | */ |
||
| 17 | private $sHost = ''; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @var string |
||
| 21 | */ |
||
| 22 | private $sAdminUser = ''; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @var string |
||
| 26 | */ |
||
| 27 | private $sAdminPassword = ''; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @var \MailSo\Log\Logger |
||
| 31 | */ |
||
| 32 | private $oLogger = null; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @param string $sHost |
||
| 36 | * @param string $sAdminUser |
||
| 37 | * @param string $sAdminPassword |
||
| 38 | * |
||
| 39 | * @return \VirtualminChangePasswordDriver |
||
| 40 | */ |
||
| 41 | public function SetConfig($sHost, $sAdminUser, $sAdminPassword) |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @param string $sAllowedEmails |
||
| 52 | * |
||
| 53 | * @return \VirtualminChangePasswordDriver |
||
| 54 | */ |
||
| 55 | public function SetAllowedEmails($sAllowedEmails) |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @param \MailSo\Log\Logger $oLogger |
||
| 64 | * |
||
| 65 | * @return \VirtualminChangePasswordDriver |
||
| 66 | */ |
||
| 67 | public function SetLogger($oLogger) |
||
| 76 | |||
| 77 | /** |
||
| 78 | * @param string $sDesc |
||
| 79 | * @param int $iType = \MailSo\Log\Enumerations\Type::INFO |
||
| 80 | * |
||
| 81 | * @return \VirtualminChangePasswordDriver |
||
| 82 | */ |
||
| 83 | public function WriteLog($sDesc, $iType = \MailSo\Log\Enumerations\Type::INFO) |
||
| 92 | |||
| 93 | /** |
||
| 94 | * @param \RainLoop\Model\Account $oAccount |
||
| 95 | * |
||
| 96 | * @return bool |
||
| 97 | */ |
||
| 98 | public function PasswordChangePossibility($oAccount) |
||
| 103 | |||
| 104 | /** |
||
| 105 | * @param \RainLoop\Model\Account $oAccount |
||
| 106 | * @param string $sPrevPassword |
||
| 107 | * @param string $sNewPassword |
||
| 108 | * |
||
| 109 | * @return bool |
||
| 110 | */ |
||
| 111 | public function ChangePassword(\RainLoop\Account $oAccount, $sPrevPassword, $sNewPassword) |
||
| 210 | } |
||
| 211 |
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.jsonfile (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.jsonto be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
requireorrequire-devsection?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceofchecks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.