| Conditions | 12 |
| Paths | 54 |
| Total Lines | 44 |
| Code Lines | 22 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 90 | public function ChangePassword(\RainLoop\Account $oAccount, $sPrevPassword, $sNewPassword) |
||
| 91 | { |
||
| 92 | if ($this->oLogger) |
||
| 93 | { |
||
| 94 | $this->oLogger->Write('ISP: Try to change password for '.$oAccount->Email()); |
||
| 95 | } |
||
| 96 | |||
| 97 | $bResult = false; |
||
| 98 | if (!empty($this->sDsn) && 0 < \strlen($this->sUser) && 0 < \strlen($this->sPassword) && $oAccount) |
||
| 99 | { |
||
| 100 | try |
||
| 101 | { |
||
| 102 | $oPdo = new \PDO($this->sDsn, $this->sUser, $this->sPassword); |
||
| 103 | $oPdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); |
||
| 104 | |||
| 105 | $oStmt = $oPdo->prepare('SELECT password, mailuser_id FROM mail_user WHERE login = ? LIMIT 1'); |
||
| 106 | if ($oStmt->execute(array($oAccount->IncLogin()))) |
||
| 107 | { |
||
| 108 | $aFetchResult = $oStmt->fetchAll(\PDO::FETCH_ASSOC); |
||
| 109 | if (\is_array($aFetchResult) && isset($aFetchResult[0]['password'], $aFetchResult[0]['mailuser_id'])) |
||
| 110 | { |
||
| 111 | $sDbPassword = \stripslashes($aFetchResult[0]['password']); |
||
| 112 | $sDbSalt = '$1$'.\substr($sDbPassword, 3, 8).'$'; |
||
| 113 | |||
| 114 | if (\crypt(\stripslashes($sPrevPassword), $sDbSalt) === $sDbPassword) |
||
| 115 | { |
||
| 116 | $oStmt = $oPdo->prepare('UPDATE mail_user SET password = ? WHERE mailuser_id = ?'); |
||
| 117 | $bResult = (bool) $oStmt->execute( |
||
| 118 | array($this->cryptPassword($sNewPassword), $aFetchResult[0]['mailuser_id'])); |
||
| 119 | } |
||
| 120 | } |
||
| 121 | } |
||
| 122 | } |
||
| 123 | catch (\Exception $oException) |
||
| 124 | { |
||
| 125 | if ($this->oLogger) |
||
| 126 | { |
||
| 127 | $this->oLogger->WriteException($oException); |
||
| 128 | } |
||
| 129 | } |
||
| 130 | } |
||
| 131 | |||
| 132 | return $bResult; |
||
| 133 | } |
||
| 134 | |||
| 151 | } |
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.