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 ChangePasswordPostfixAdminDriver implements \RainLoop\Providers\ChangePassword\ChangePasswordInterface |
||
| 4 | { |
||
| 5 | /** |
||
| 6 | * @var string |
||
| 7 | */ |
||
| 8 | private $sEngine = 'MySQL'; |
||
| 9 | |||
| 10 | /** |
||
| 11 | * @var string |
||
| 12 | */ |
||
| 13 | private $sHost = '127.0.0.1'; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @var int |
||
| 17 | */ |
||
| 18 | private $iPort = 3306; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @var string |
||
| 22 | */ |
||
| 23 | private $sDatabase = 'postfixadmin'; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var string |
||
| 27 | */ |
||
| 28 | private $sTable = 'mailbox'; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var string |
||
| 32 | */ |
||
| 33 | private $sUsercol = 'username'; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @var string |
||
| 37 | */ |
||
| 38 | private $sPasscol = 'password'; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @var string |
||
| 42 | */ |
||
| 43 | private $sUser = 'postfixadmin'; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @var string |
||
| 47 | */ |
||
| 48 | private $sPassword = ''; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @var string |
||
| 52 | */ |
||
| 53 | private $sEncrypt = ''; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @var string |
||
| 57 | */ |
||
| 58 | private $sAllowedEmails = ''; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @var \MailSo\Log\Logger |
||
| 62 | */ |
||
| 63 | private $oLogger = null; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @param string $sEngine |
||
| 67 | * |
||
| 68 | * @return \ChangePasswordPostfixAdminDriver |
||
| 69 | */ |
||
| 70 | public function SetEngine($sEngine) |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @param string $sHost |
||
| 78 | * |
||
| 79 | * @return \ChangePasswordPostfixAdminDriver |
||
| 80 | */ |
||
| 81 | public function SetHost($sHost) |
||
| 86 | |||
| 87 | /** |
||
| 88 | * @param int $iPort |
||
| 89 | * |
||
| 90 | * @return \ChangePasswordPostfixAdminDriver |
||
| 91 | */ |
||
| 92 | public function SetPort($iPort) |
||
| 97 | |||
| 98 | /** |
||
| 99 | * @param string $sDatabase |
||
| 100 | * |
||
| 101 | * @return \ChangePasswordPostfixAdminDriver |
||
| 102 | */ |
||
| 103 | public function SetDatabase($sDatabase) |
||
| 108 | |||
| 109 | /** |
||
| 110 | * @param string $sTable |
||
| 111 | * |
||
| 112 | * @return \ChangePasswordPostfixAdminDriver |
||
| 113 | */ |
||
| 114 | public function SetTable($sTable) |
||
| 119 | |||
| 120 | /** |
||
| 121 | * @param string $sUsercol |
||
| 122 | * |
||
| 123 | * @return \ChangePasswordPostfixAdminDriver |
||
| 124 | */ |
||
| 125 | public function SetUserColumn($sUsercol) |
||
| 130 | |||
| 131 | /** |
||
| 132 | * @param string $sPasscol |
||
| 133 | * |
||
| 134 | * @return \ChangePasswordPostfixAdminDriver |
||
| 135 | */ |
||
| 136 | public function SetPasswordColumn($sPasscol) |
||
| 141 | |||
| 142 | /** |
||
| 143 | * @param string $sUser |
||
| 144 | * |
||
| 145 | * @return \ChangePasswordPostfixAdminDriver |
||
| 146 | */ |
||
| 147 | public function SetUser($sUser) |
||
| 152 | |||
| 153 | /** |
||
| 154 | * @param string $sPassword |
||
| 155 | * |
||
| 156 | * @return \ChangePasswordPostfixAdminDriver |
||
| 157 | */ |
||
| 158 | public function SetPassword($sPassword) |
||
| 163 | |||
| 164 | /** |
||
| 165 | * @param string $sEncrypt |
||
| 166 | * |
||
| 167 | * @return \ChangePasswordPostfixAdminDriver |
||
| 168 | */ |
||
| 169 | public function SetEncrypt($sEncrypt) |
||
| 174 | |||
| 175 | /** |
||
| 176 | * @param string $sAllowedEmails |
||
| 177 | * |
||
| 178 | * @return \ChangePasswordPostfixAdminDriver |
||
| 179 | */ |
||
| 180 | public function SetAllowedEmails($sAllowedEmails) |
||
| 185 | |||
| 186 | /** |
||
| 187 | * @param \MailSo\Log\Logger $oLogger |
||
| 188 | * |
||
| 189 | * @return \ChangePasswordPostfixAdminDriver |
||
| 190 | */ |
||
| 191 | public function SetLogger($oLogger) |
||
| 200 | |||
| 201 | /** |
||
| 202 | * @param \RainLoop\Model\Account $oAccount |
||
| 203 | * |
||
| 204 | * @return bool |
||
| 205 | */ |
||
| 206 | public function PasswordChangePossibility($oAccount) |
||
| 211 | |||
| 212 | /** |
||
| 213 | * @param \RainLoop\Model\Account $oAccount |
||
| 214 | * @param string $sPrevPassword |
||
| 215 | * @param string $sNewPassword |
||
| 216 | * |
||
| 217 | * @return bool |
||
| 218 | */ |
||
| 219 | public function ChangePassword(\RainLoop\Account $oAccount, $sPrevPassword, $sNewPassword) |
||
| 279 | |||
| 280 | /** |
||
| 281 | * @param string $sPassword |
||
| 282 | * @param \PDO $oPdo |
||
| 283 | * |
||
| 284 | * @return string |
||
| 285 | */ |
||
| 286 | private function cryptPassword($sPassword, $oPdo) |
||
| 342 | } |
||
| 343 |
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.