| Conditions | 18 |
| Paths | 208 |
| Total Lines | 84 |
| Code Lines | 47 |
| 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 |
||
| 104 | public function ChangePassword(\RainLoop\Account $oAccount, $sPrevPassword, $sNewPassword) |
||
| 105 | { |
||
| 106 | if ($this->oLogger) |
||
| 107 | { |
||
| 108 | $this->oLogger->Write('Try to change password for '.$oAccount->Email()); |
||
| 109 | } |
||
| 110 | |||
| 111 | if (!\class_exists('xmlapi')) |
||
| 112 | { |
||
| 113 | include_once __DIR__.'/xmlapi.php'; |
||
| 114 | } |
||
| 115 | |||
| 116 | $bResult = false; |
||
| 117 | if (!empty($this->sHost) && 0 < $this->iPost && |
||
| 118 | 0 < \strlen($this->sUser) && 0 < \strlen($this->sPassword) && |
||
| 119 | $oAccount && \class_exists('xmlapi')) |
||
| 120 | { |
||
| 121 | $sEmail = $oAccount->Email(); |
||
| 122 | $sEmailUser = \MailSo\Base\Utils::GetAccountNameFromEmail($sEmail); |
||
| 123 | $sEmailDomain = \MailSo\Base\Utils::GetDomainFromEmail($sEmail); |
||
| 124 | |||
| 125 | $sHost = $this->sHost; |
||
| 126 | $sHost = \str_replace('{user:domain}', $sEmailDomain, $sHost); |
||
| 127 | |||
| 128 | $sUser = $this->sUser; |
||
| 129 | $sUser = \str_replace('{user:email}', $sEmail, $sUser); |
||
| 130 | $sUser = \str_replace('{user:login}', $sEmailUser, $sUser); |
||
| 131 | |||
| 132 | $sPassword = $this->sPassword; |
||
| 133 | $sPassword = \str_replace('{user:password}', $oAccount->Password(), $sPassword); |
||
| 134 | |||
| 135 | try |
||
| 136 | { |
||
| 137 | $oXmlApi = new \xmlapi($sHost); |
||
| 138 | $oXmlApi->set_port($this->iPost); |
||
| 139 | $oXmlApi->set_protocol($this->bSsl ? 'https' : 'http'); |
||
| 140 | $oXmlApi->set_debug(false); |
||
| 141 | $oXmlApi->set_output('json'); |
||
| 142 | // $oXmlApi->set_http_client('fopen'); |
||
| 143 | $oXmlApi->set_http_client('curl'); |
||
| 144 | $oXmlApi->password_auth($sUser, $sPassword); |
||
| 145 | |||
| 146 | $aArgs = array( |
||
| 147 | 'email' => $sEmailUser, |
||
| 148 | 'domain' => $sEmailDomain, |
||
| 149 | 'password' => $sNewPassword |
||
| 150 | ); |
||
| 151 | |||
| 152 | $sResult = $oXmlApi->api2_query($sUser, 'Email', 'passwdpop', $aArgs); |
||
| 153 | if ($sResult) |
||
| 154 | { |
||
| 155 | if ($this->oLogger) |
||
| 156 | { |
||
| 157 | $this->oLogger->Write('CPANEL: '.$sResult, \MailSo\Log\Enumerations\Type::INFO); |
||
| 158 | } |
||
| 159 | |||
| 160 | $aResult = @\json_decode($sResult, true); |
||
| 161 | $bResult = isset($aResult['cpanelresult']['data'][0]['result']) && |
||
| 162 | !!$aResult['cpanelresult']['data'][0]['result']; |
||
| 163 | } |
||
| 164 | |||
| 165 | if (!$bResult && $this->oLogger) |
||
| 166 | { |
||
| 167 | $this->oLogger->Write('CPANEL: '.$sResult, \MailSo\Log\Enumerations\Type::ERROR); |
||
| 168 | } |
||
| 169 | } |
||
| 170 | catch (\Exception $oException) |
||
| 171 | { |
||
| 172 | if ($this->oLogger) |
||
| 173 | { |
||
| 174 | $this->oLogger->WriteException($oException); |
||
| 175 | } |
||
| 176 | } |
||
| 177 | } |
||
| 178 | else |
||
| 179 | { |
||
| 180 | if ($this->oLogger) |
||
| 181 | { |
||
| 182 | $this->oLogger->Write('CPANEL: Incorrent configuration data', \MailSo\Log\Enumerations\Type::ERROR); |
||
| 183 | } |
||
| 184 | } |
||
| 185 | |||
| 186 | return $bResult; |
||
| 187 | } |
||
| 188 | } |
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.