| Conditions | 13 |
| Paths | 22 |
| Total Lines | 63 |
| Lines | 23 |
| Ratio | 36.51 % |
| 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 |
||
| 83 | public function ChangePassword(\RainLoop\Account $oAccount, $sPrevPassword, $sNewPassword) |
||
| 84 | { |
||
| 85 | if ($this->oLogger) |
||
| 86 | { |
||
| 87 | $this->oLogger->Write('Vesta: Try to change password for '.$oAccount->Email()); |
||
| 88 | } |
||
| 89 | |||
| 90 | $bResult = false; |
||
| 91 | if (!empty($this->sHost) && 0 < $this->iPort && $oAccount) |
||
| 92 | { |
||
| 93 | $sEmail = \trim(\strtolower($oAccount->Email())); |
||
| 94 | |||
| 95 | $sHost = \trim($this->sHost); |
||
| 96 | $sHost = \str_replace('{user:host-imap}', $oAccount->Domain()->IncHost(), $sHost); |
||
| 97 | $sHost = \str_replace('{user:host-smtp}', $oAccount->Domain()->OutHost(), $sHost); |
||
| 98 | $sHost = \str_replace('{user:domain}', \MailSo\Base\Utils::GetDomainFromEmail($sEmail), $sHost); |
||
| 99 | $sHost = \rtrim($this->sHost, '/\\'); |
||
| 100 | $sHost = 'https://'.$sHost; |
||
| 101 | |||
| 102 | $sUrl = $sHost.':'.$this->iPort.'/reset/mail/'; |
||
| 103 | |||
| 104 | $iCode = 0; |
||
| 105 | $oHttp = \MailSo\Base\Http::SingletonInstance(); |
||
| 106 | |||
| 107 | if ($this->oLogger) |
||
| 108 | { |
||
| 109 | $this->oLogger->Write('Vesta[Api Request]:'.$sUrl); |
||
| 110 | } |
||
| 111 | |||
| 112 | $mResult = $oHttp->SendPostRequest($sUrl, |
||
| 113 | array( |
||
| 114 | 'email' => $sEmail, |
||
| 115 | 'password' => $sPrevPassword, |
||
| 116 | 'new' => $sNewPassword, |
||
| 117 | ), 'MailSo Http User Agent (v1)', $iCode, $this->oLogger); |
||
| 118 | |||
| 119 | View Code Duplication | if (false !== $mResult && 200 === $iCode) |
|
| 120 | { |
||
| 121 | $aRes = null; |
||
| 122 | @\parse_str($mResult, $aRes); |
||
| 123 | if (is_array($aRes) && (!isset($aRes['error']) || (int) $aRes['error'] !== 1)) |
||
| 124 | { |
||
| 125 | $bResult = true; |
||
| 126 | } |
||
| 127 | else |
||
| 128 | { |
||
| 129 | if ($this->oLogger) |
||
| 130 | { |
||
| 131 | $this->oLogger->Write('Vesta[Error]: Response: '.$mResult); |
||
| 132 | } |
||
| 133 | } |
||
| 134 | } |
||
| 135 | else |
||
| 136 | { |
||
| 137 | if ($this->oLogger) |
||
| 138 | { |
||
| 139 | $this->oLogger->Write('Vesta[Error]: Empty Response: Code:'.$iCode); |
||
| 140 | } |
||
| 141 | } |
||
| 142 | } |
||
| 143 | |||
| 144 | return $bResult; |
||
| 145 | } |
||
| 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.