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 |
||
157 | private function sendMail($msg) |
||
158 | { |
||
159 | $mail = new PHPMailer(true); |
||
160 | |||
161 | try { |
||
162 | //Server settings |
||
163 | $mail->SMTPDebug = $this->config['debug']; // Enable verbose debug output |
||
164 | $mail->isSMTP(); // Set mailer to use SMTP |
||
165 | $mail->Host = $this->config['host']; // Specify main and backup SMTP servers |
||
166 | $mail->SMTPAuth = true; // Enable SMTP authentication |
||
167 | $mail->Username = $this->config['username']; // SMTP username |
||
168 | $mail->Password = $this->config['password']; // SMTP password |
||
169 | $mail->SMTPSecure = $this->config['SMTPSecure']; // Enable TLS encryption, `ssl` also accepted |
||
170 | $mail->Port = $this->config['port']; // TCP port to connect to |
||
171 | $mail->CharSet = 'UTF-8'; |
||
172 | $mail->SMTPOptions = $this->config['SMTPOptions']; |
||
173 | //Recipients |
||
174 | $mail->setFrom($this->config['fromEmail'], $this->config['fromName']); |
||
175 | if (isset($this->config['replyMail'])) { |
||
176 | $mail->setReplyTo($this->config['replyMail']); |
||
|
|||
177 | } |
||
178 | if (isset($this->config['SMTPOptions'])) { |
||
179 | $mail->SMTPOptions = $this->config['SMTPOptions']; |
||
180 | } |
||
181 | // touser |
||
182 | if (isset($msg['to'])) { |
||
183 | foreach ($msg['to'] as $t) { |
||
184 | $mail->addAddress($t['email'], $t['name']); |
||
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 | |||
218 | return true; |
||
219 | } catch (\Exception $e) { |
||
220 | throw new \Exception('邮件发送失败:'.$e->getMessage().$e->getLine()); |
||
221 | } |
||
224 |
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.