Conditions | 10 |
Paths | 64 |
Total Lines | 49 |
Code Lines | 23 |
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 |
||
39 | protected function sending(Message $message) |
||
40 | { |
||
41 | $phpMailer = new PHPMailer(); |
||
42 | $phpMailer->isSendmail(); |
||
43 | |||
44 | // Set from |
||
45 | if (false !== ($from = $message->getFrom())) { |
||
|
|||
46 | $phpMailer->setFrom($from->getEmail(), $from->getName()); |
||
47 | } |
||
48 | |||
49 | // Set recipient |
||
50 | if (false !== ($to = $message->getTo())) { |
||
51 | foreach ($to as $address) { |
||
52 | if ($address instanceof Address) { |
||
53 | $phpMailer->addAddress($address->getEmail(), $address->getName()); |
||
54 | } |
||
55 | } |
||
56 | } |
||
57 | |||
58 | // Set reply-to |
||
59 | if (false !== ($replyTo = $message->getReplyTo())) { |
||
60 | $phpMailer->addReplyTo($replyTo->getEmail(), $replyTo->getName()); |
||
61 | } |
||
62 | |||
63 | // Set content-type |
||
64 | if ($message->getContentType() === 'html') { |
||
65 | $phpMailer->isHTML(true); |
||
66 | } |
||
67 | |||
68 | // Set subject, body & alt-body |
||
69 | $phpMailer->Subject = $message->getSubject(); |
||
70 | $phpMailer->Body = $message->getBody(); |
||
71 | $phpMailer->AltBody = $message->getAltBody(); |
||
72 | |||
73 | if (false !== ($attachments = $message->getAttachments())) { |
||
74 | foreach ($attachments as $filename => $attachment) { |
||
75 | $phpMailer->addAttachment($attachment, $filename); |
||
76 | } |
||
77 | } |
||
78 | |||
79 | if ( ! $phpMailer->send()) { |
||
80 | $this->addErrors([ |
||
81 | $phpMailer->ErrorInfo, |
||
82 | ]); |
||
83 | |||
84 | return false; |
||
85 | } |
||
86 | |||
87 | return true; |
||
88 | } |
||
89 | } |