| Conditions | 10 |
| Paths | 15 |
| Total Lines | 55 |
| Code Lines | 34 |
| 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 |
||
| 34 | public function schedule(Message $iTipMessage) { |
||
| 35 | $this->logger->trace("method: %s - recipient: %s - significantChange: %d - scheduleStatus: %s - message: %s", $iTipMessage->method, $iTipMessage->recipient, $iTipMessage->significantChange, $iTipMessage->scheduleStatus, $iTipMessage->message->serialize()); |
||
| 36 | |||
| 37 | if (!$iTipMessage->significantChange) { |
||
| 38 | if (!$iTipMessage->scheduleStatus) { |
||
| 39 | $iTipMessage->scheduleStatus = "1.0;We got the message, but it's not significant enough to warrant an email"; |
||
| 40 | } |
||
| 41 | |||
| 42 | return; |
||
| 43 | } |
||
| 44 | |||
| 45 | $recipient = preg_replace('!^mailto:!i', '', $iTipMessage->recipient); |
||
| 46 | $session = $this->gDavBackend->GetSession(); |
||
| 47 | $addrbook = $this->gDavBackend->GetAddressBook(); |
||
| 48 | $store = $this->gDavBackend->GetStore($this->gDavBackend->GetUser()); |
||
| 49 | $storeprops = mapi_getprops($store, [PR_IPM_OUTBOX_ENTRYID, PR_IPM_SENTMAIL_ENTRYID]); |
||
| 50 | if (!isset($storeprops[PR_IPM_OUTBOX_ENTRYID]) || !isset($storeprops[PR_IPM_SENTMAIL_ENTRYID])) { |
||
| 51 | /* handle error */ |
||
| 52 | $this->logger->error("no outbox found aborting user: %s", $this->gDavBackend->GetUser()); |
||
| 53 | |||
| 54 | return; |
||
| 55 | } |
||
| 56 | |||
| 57 | /* create message and convert */ |
||
| 58 | $outbox = mapi_msgstore_openentry($store, $storeprops[PR_IPM_OUTBOX_ENTRYID]); |
||
| 59 | $newmessage = mapi_folder_createmessage($outbox); |
||
| 60 | mapi_icaltomapi($session, $store, $addrbook, $newmessage, $iTipMessage->message->serialize(), false); |
||
| 61 | mapi_setprops($newmessage, [PR_SENTMAIL_ENTRYID => $storeprops[PR_IPM_SENTMAIL_ENTRYID], PR_DELETE_AFTER_SUBMIT => false]); |
||
| 62 | |||
| 63 | /* clean the recipients (needed since mapi_icaltomapi does not take IC2M_NO_ORGANIZER) */ |
||
| 64 | $recipientTable = mapi_message_getrecipienttable($newmessage); |
||
| 65 | $recipientRows = mapi_table_queryallrows($recipientTable, [PR_SMTP_ADDRESS, PR_ROWID]); |
||
| 66 | $removeRecipients = []; |
||
| 67 | foreach ($recipientRows as $key => $recip) { |
||
| 68 | if (!isset($recip[PR_SMTP_ADDRESS])) { |
||
| 69 | continue; |
||
| 70 | } |
||
| 71 | if (strcasecmp($recip[PR_SMTP_ADDRESS], $recipient) != 0) { |
||
| 72 | $removeRecipients[] = $recip; |
||
| 73 | } |
||
| 74 | } |
||
| 75 | if (count($removeRecipients) == count($recipientRows)) { |
||
| 76 | $this->logger->error("message will have no recipients. List to remove: %s - recipientRows: %s", $removeRecipients, $recipientRows); |
||
| 77 | |||
| 78 | return; |
||
| 79 | } |
||
| 80 | if (count($removeRecipients) > 0) { |
||
| 81 | mapi_message_modifyrecipients($newmessage, MODRECIP_REMOVE, $removeRecipients); |
||
| 82 | } |
||
| 83 | |||
| 84 | /* save message and send */ |
||
| 85 | mapi_savechanges($newmessage); |
||
| 86 | mapi_message_submitmessage($newmessage); |
||
| 87 | $this->logger->info("email sent, recipient: %s", $recipient); |
||
| 88 | $iTipMessage->scheduleStatus = '1.1;Scheduling message sent via iMip'; |
||
| 89 | } |
||
| 91 |