| Conditions | 15 |
| Paths | 2599 |
| Total Lines | 64 |
| Code Lines | 39 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | Features | 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 |
||
| 156 | private function sendMail($msg) |
||
| 157 | { |
||
| 158 | $mail = new PHPMailer(true); |
||
| 159 | |||
| 160 | try { |
||
| 161 | //Server settings |
||
| 162 | $mail->SMTPDebug = $this->config['debug']; // Enable verbose debug output |
||
| 163 | $mail->isSMTP(); // Set mailer to use SMTP |
||
| 164 | $mail->Host = $this->config['host']; // Specify main and backup SMTP servers |
||
| 165 | $mail->SMTPAuth = true; // Enable SMTP authentication |
||
| 166 | $mail->Username = $this->config['username']; // SMTP username |
||
| 167 | $mail->Password = $this->config['password']; // SMTP password |
||
| 168 | $mail->SMTPSecure = $this->config['SMTPSecure']; // Enable TLS encryption, `ssl` also accepted |
||
| 169 | $mail->Port = $this->config['port']; // TCP port to connect to |
||
| 170 | $mail->CharSet = 'UTF-8'; |
||
| 171 | $mail->SMTPOptions = $this->config['SMTPOptions']; |
||
| 172 | //Recipients |
||
| 173 | $mail->setFrom($this->config['fromEmail'], $this->config['fromName']); |
||
| 174 | if (isset($this->config['replyMail'])){ |
||
| 175 | $mail->setReplyTo($this->config['replyMail']); |
||
|
|
|||
| 176 | } |
||
| 177 | if (isset($this->config['SMTPOptions'])){ |
||
| 178 | $mail->SMTPOptions = $this->config['SMTPOptions']; |
||
| 179 | } |
||
| 180 | // touser |
||
| 181 | if (isset($msg['to'])) { |
||
| 182 | foreach ($msg['to'] as $t) { |
||
| 183 | $mail->addAddress($t['email'], $t['name']); |
||
| 184 | } |
||
| 185 | |||
| 186 | } |
||
| 187 | // cc |
||
| 188 | if (isset($msg['cc']) && is_string($msg['cc'])) { |
||
| 189 | foreach ($msg['cc'] as $c) { |
||
| 190 | $mail->addCC($c['email'], $c['name']); |
||
| 191 | } |
||
| 192 | } |
||
| 193 | |||
| 194 | // bcc |
||
| 195 | if (isset($msg['bcc'])){ |
||
| 196 | foreach ($msg['bcc'] as $bc) { |
||
| 197 | $mail->addBCC($bc['email'], $bc['name']); |
||
| 198 | } |
||
| 199 | } |
||
| 200 | |||
| 201 | // Attachments |
||
| 202 | if (isset($msg['attachments']) && !empty($msg['attachments'])) { |
||
| 203 | foreach ($msg['attachments'] as $attachment) { |
||
| 204 | $mail->addAttachment($attachment['filepath'], $attachment['filename']); |
||
| 205 | } |
||
| 206 | } |
||
| 207 | // Content |
||
| 208 | $mail->isHTML(true); // Set email format to HTML |
||
| 209 | $mail->Subject = $msg['subject']; |
||
| 210 | $mail->Body = $msg['body']; |
||
| 211 | |||
| 212 | $mail->AltBody = '请使用支持html的邮箱客户端,以取得更好的浏览体验'; |
||
| 213 | $r = $mail->send(); |
||
| 214 | if (!$r) { |
||
| 215 | throw new \Exception('邮件发送失败:'.$mail->ErrorInfo); |
||
| 216 | } |
||
| 217 | return true; |
||
| 218 | } catch (\Exception $e) { |
||
| 219 | throw new \Exception('邮件发送失败:'.$e->getMessage().$e->getLine()); |
||
| 220 | } |
||
| 223 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.