| Conditions | 10 |
| Paths | 9 |
| Total Lines | 58 |
| Code Lines | 43 |
| Lines | 4 |
| Ratio | 6.9 % |
| 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 |
||
| 99 | public function ChangePassword(\RainLoop\Account $oAccount, $sPrevPassword, $sNewPassword) |
||
| 100 | { |
||
| 101 | $this->WriteLog('Mail-in-a-box: Try to change password for '.$oAccount->Email()); |
||
| 102 | $bResult = false; |
||
| 103 | if (!empty($this->sHost) && !empty($this->sAdminUser) && !empty($this->sAdminPassword) && $oAccount) |
||
| 104 | { |
||
| 105 | $this->WriteLog('Mail-in-a-box:[Check] Required Fields Present'); |
||
| 106 | $sEmail = \trim(\strtolower($oAccount->Email())); |
||
| 107 | $sHost = \rtrim(\trim($this->sHost), '/'); |
||
| 108 | $sUrl = $sHost.'/admin/mail/users/password'; |
||
| 109 | |||
| 110 | $sAdminUser = $this->sAdminUser; |
||
| 111 | $sAdminPassword = $this->sAdminPassword; |
||
| 112 | $iCode = 0; |
||
| 113 | $aPost = array( |
||
| 114 | 'email' => $sEmail, |
||
| 115 | 'password' => $sNewPassword, |
||
| 116 | ); |
||
| 117 | $aOptions = array( |
||
| 118 | CURLOPT_URL => $sUrl, |
||
| 119 | CURLOPT_HEADER => false, |
||
| 120 | CURLOPT_FAILONERROR => true, |
||
| 121 | CURLOPT_SSL_VERIFYPEER => false, |
||
| 122 | CURLOPT_RETURNTRANSFER => true, |
||
| 123 | CURLOPT_POST => true, |
||
| 124 | CURLOPT_POSTFIELDS => \http_build_query($aPost, '', '&'), |
||
| 125 | CURLOPT_TIMEOUT => 20, |
||
| 126 | CURLOPT_SSL_VERIFYHOST => false, |
||
| 127 | CURLOPT_USERPWD => $sAdminUser.':'.$sAdminPassword, |
||
| 128 | CURLOPT_HTTPAUTH => CURLAUTH_BASIC |
||
| 129 | ); |
||
| 130 | $oCurl = \curl_init(); |
||
| 131 | \curl_setopt_array($oCurl, $aOptions); |
||
| 132 | $this->WriteLog('Mail-in-a-box: Send post request: '.$sUrl); |
||
| 133 | $mResult = \curl_exec($oCurl); |
||
| 134 | $iCode = (int) \curl_getinfo($oCurl, CURLINFO_HTTP_CODE); |
||
| 135 | $sContentType = (string) \curl_getinfo($oCurl, CURLINFO_CONTENT_TYPE); |
||
| 136 | $this->WriteLog('Mail-in-a-box: Post request result: (Status: '.$iCode.', ContentType: '.$sContentType.')'); |
||
| 137 | View Code Duplication | if (false === $mResult || 200 !== $iCode) |
|
| 138 | { |
||
| 139 | $this->WriteLog('Mail-in-a-box: Error: '.\curl_error($oCurl), \MailSo\Log\Enumerations\Type::WARNING); |
||
| 140 | } |
||
| 141 | if (\is_resource($oCurl)) |
||
| 142 | { |
||
| 143 | \curl_close($oCurl); |
||
| 144 | } |
||
| 145 | if (false !== $mResult && 200 === $iCode) |
||
| 146 | { |
||
| 147 | $this->WriteLog('Mail-in-a-box: Password Change Status: Success'); |
||
| 148 | $bResult = true; |
||
| 149 | } |
||
| 150 | else |
||
| 151 | { |
||
| 152 | $this->WriteLog('Mail-in-a-box[Error]: Empty Response: Code: '.$iCode); |
||
| 153 | } |
||
| 154 | } |
||
| 155 | return $bResult; |
||
| 156 | } |
||
| 157 | } |
||
| 158 |
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.