Conditions | 10 |
Paths | 12 |
Total Lines | 49 |
Code Lines | 23 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | 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 |
||
91 | public function send(array $_messages, $_subject = false, $_links = false, $_attachments = false, $_data = false) |
||
92 | { |
||
93 | $body_plain = $_messages['plain'].$this->render_links($_links, false, $this->preferences->external_mailclient); |
||
94 | $body_html = "<html><body>\n".$_messages['html'].$this->render_links($_links, true, $this->preferences->external_mailclient)."</body>\n</html>\n"; |
||
95 | |||
96 | $this->mail->ClearAddresses(); |
||
97 | $this->mail->ClearAttachments(); |
||
98 | $this->mail->addAddress($this->recipient->account_email, $this->recipient->account_fullname); |
||
99 | $this->mail->addHeader('X-EGroupware-Type', 'notification-mail'); |
||
100 | $this->mail->addHeader('X-EGroupware-Install', $GLOBALS['egw_info']['server']['install_id'].'@'.$GLOBALS['egw_info']['server']['default_domain']); |
||
101 | //$this->mail->AddHeader('X-EGroupware-URL', 'notification-mail'); |
||
102 | //$this->mail->AddHeader('X-EGroupware-Tracker', 'notification-mail'); |
||
103 | //error_log(__METHOD__.__LINE__."preparing notification message via email.".array2string($this->mail)); |
||
104 | |||
105 | if ( $_data && !empty( $_data['reply_to'] ) ) |
||
106 | { |
||
107 | $this->mail->addReplyTo($_data['reply_to']); |
||
108 | } |
||
109 | // do NOT set sender as From, as this might not be allowed, set it instead as ReplyTo, if that one it not explicitly set already |
||
110 | elseif ($this->mail->getHeader('From') != Api\Mailer::add_personal($this->sender->account_email, $this->sender->account_fullname)) |
||
111 | { |
||
112 | $this->mail->addReplyTo($this->sender->account_email, $this->sender->account_fullname); |
||
113 | } |
||
114 | |||
115 | $this->mail->addHeader('Subject', trim($_subject)); // trim the subject to avoid strange wrong encoding problem |
||
116 | if ($_messages['html']) |
||
117 | { |
||
118 | // embed images as inline |
||
119 | \EGroupware\Api\Mail::processURL2InlineImages($this->mail, $body_html, null); |
||
120 | } |
||
121 | $this->mail->setHtmlBody($body_html, null, false); // no automatic alternativ |
||
122 | $this->mail->setBody($body_plain); |
||
123 | |||
124 | if(is_array($_attachments) && count($_attachments) > 0) |
||
125 | { |
||
126 | foreach($_attachments as $attachment) |
||
127 | { |
||
128 | if ($attachment->string) |
||
129 | { |
||
130 | $this->mail->AddStringAttachment($attachment->string, $attachment->filename, $attachment->encoding, $attachment->type); |
||
131 | } |
||
132 | elseif($attachment->path) |
||
133 | { |
||
134 | $this->mail->AddAttachment($attachment->path, $attachment->filename, $attachment->encoding, $attachment->type); |
||
135 | } |
||
136 | } |
||
137 | } |
||
138 | //error_log(__METHOD__.__LINE__."about sending notification message via email.".array2string($this->mail)); |
||
139 | $this->mail->send(); |
||
140 | } |
||
175 |