| Conditions | 11 |
| Paths | 128 |
| Total Lines | 61 |
| Code Lines | 32 |
| 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 |
||
| 81 | protected function sending(Message $message) |
||
| 82 | {
|
||
| 83 | $phpMailer = new PHPMailer(); |
||
| 84 | $phpMailer->isSMTP(); |
||
| 85 | $phpMailer->SMTPDebug = $this->config[ 'debug' ]; |
||
| 86 | |||
| 87 | $host = $this->config[ 'host' ]; |
||
| 88 | |||
| 89 | if (is_array($this->config[ 'host' ])) {
|
||
| 90 | $host = implode(';', $this->config[ 'host' ]);
|
||
| 91 | } |
||
| 92 | |||
| 93 | $phpMailer->Host = $host; |
||
| 94 | $phpMailer->SMTPAuth = $this->config[ 'auth' ]; |
||
| 95 | $phpMailer->Username = $this->config[ 'username' ]; |
||
| 96 | $phpMailer->Password = $this->config[ 'password' ]; |
||
| 97 | $phpMailer->SMTPSecure = $this->config[ 'encryption' ]; |
||
| 98 | $phpMailer->Port = $this->config[ 'port' ]; |
||
| 99 | |||
| 100 | // Set from |
||
| 101 | if (false !== ($from = $message->getFrom())) {
|
||
|
|
|||
| 102 | $phpMailer->setFrom($from->getEmail(), $from->getName()); |
||
| 103 | } |
||
| 104 | |||
| 105 | // Set recipient |
||
| 106 | if (false !== ($to = $message->getTo())) {
|
||
| 107 | foreach ($to as $address) {
|
||
| 108 | if ($address instanceof Address) {
|
||
| 109 | $phpMailer->addAddress($address->getEmail(), $address->getName()); |
||
| 110 | } |
||
| 111 | } |
||
| 112 | } |
||
| 113 | |||
| 114 | // Set reply-to |
||
| 115 | if (false !== ($replyTo = $message->getReplyTo())) {
|
||
| 116 | $phpMailer->addReplyTo($replyTo->getEmail(), $replyTo->getName()); |
||
| 117 | } |
||
| 118 | |||
| 119 | // Set content-type |
||
| 120 | if ($message->getContentType() === 'html') {
|
||
| 121 | $phpMailer->isHTML(true); |
||
| 122 | } |
||
| 123 | |||
| 124 | // Set subject, body & alt-body |
||
| 125 | $phpMailer->Subject = $message->getSubject(); |
||
| 126 | $phpMailer->Body = $message->getBody(); |
||
| 127 | $phpMailer->AltBody = $message->getAltBody(); |
||
| 128 | |||
| 129 | if (false !== ($attachments = $message->getAttachments())) {
|
||
| 130 | foreach ($attachments as $filename => $attachment) {
|
||
| 131 | $phpMailer->addAttachment($attachment, $filename); |
||
| 132 | } |
||
| 133 | } |
||
| 134 | |||
| 135 | if ( ! $phpMailer->send()) {
|
||
| 136 | $this->addError(100, $phpMailer->ErrorInfo); |
||
| 137 | |||
| 138 | return false; |
||
| 139 | } |
||
| 140 | |||
| 141 | return true; |
||
| 142 | } |
||
| 143 | } |