| Conditions | 26 |
| Paths | 585 |
| Total Lines | 160 |
| Code Lines | 84 |
| 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 |
||
| 147 | public function schedule(Message $iTipMessage) { |
||
| 148 | // Not sending any emails if the system considers the update |
||
| 149 | // insignificant. |
||
| 150 | if (!$iTipMessage->significantChange) { |
||
| 151 | if (!$iTipMessage->scheduleStatus) { |
||
| 152 | $iTipMessage->scheduleStatus = '1.0;We got the message, but it\'s not significant enough to warrant an email'; |
||
| 153 | } |
||
| 154 | return; |
||
| 155 | } |
||
| 156 | |||
| 157 | if (parse_url($iTipMessage->sender, PHP_URL_SCHEME) !== 'mailto' |
||
| 158 | || parse_url($iTipMessage->recipient, PHP_URL_SCHEME) !== 'mailto') { |
||
| 159 | return; |
||
| 160 | } |
||
| 161 | |||
| 162 | // don't send out mails for events that already took place |
||
| 163 | $lastOccurrence = $this->imipService->getLastOccurrence($iTipMessage->message); |
||
| 164 | $currentTime = $this->timeFactory->getTime(); |
||
| 165 | if ($lastOccurrence < $currentTime) { |
||
| 166 | return; |
||
| 167 | } |
||
| 168 | |||
| 169 | // Strip off mailto: |
||
| 170 | $recipient = substr($iTipMessage->recipient, 7); |
||
| 171 | if (!$this->mailer->validateMailAddress($recipient)) { |
||
| 172 | // Nothing to send if the recipient doesn't have a valid email address |
||
| 173 | $iTipMessage->scheduleStatus = '5.0; EMail delivery failed'; |
||
| 174 | return; |
||
| 175 | } |
||
| 176 | $recipientName = $iTipMessage->recipientName ?: null; |
||
| 177 | |||
| 178 | $newEvents = $iTipMessage->message; |
||
| 179 | $oldEvents = $this->getVCalendar(); |
||
| 180 | |||
| 181 | $modified = $this->eventComparisonService->findModified($newEvents, $oldEvents); |
||
| 182 | /** @var VEvent $vEvent */ |
||
| 183 | $vEvent = array_pop($modified['new']); |
||
| 184 | /** @var VEvent $oldVevent */ |
||
| 185 | $oldVevent = !empty($modified['old']) && is_array($modified['old']) ? array_pop($modified['old']) : null; |
||
| 186 | |||
| 187 | // No changed events after all - this shouldn't happen if there is significant change yet here we are |
||
| 188 | // The scheduling status is debatable |
||
| 189 | if(empty($vEvent)) { |
||
| 190 | $this->logger->warning('iTip message said the change was significant but comparison did not detect any updated VEvents'); |
||
| 191 | $iTipMessage->scheduleStatus = '1.0;We got the message, but it\'s not significant enough to warrant an email'; |
||
| 192 | return; |
||
| 193 | } |
||
| 194 | |||
| 195 | // we (should) have one event component left |
||
| 196 | // as the ITip\Broker creates one iTip message per change |
||
| 197 | // and triggers the "schedule" event once per message |
||
| 198 | // we also might not have an old event as this could be a new |
||
| 199 | // invitation, or a new recurrence exception |
||
| 200 | $attendee = $this->imipService->getCurrentAttendee($iTipMessage); |
||
| 201 | $this->imipService->setL10n($attendee); |
||
| 202 | |||
| 203 | // Build the sender name. |
||
| 204 | // Due to a bug in sabre, the senderName property for an iTIP message |
||
| 205 | // can actually also be a VObject Property |
||
| 206 | /** @var Parameter|string|null $senderName */ |
||
| 207 | $senderName = $iTipMessage->senderName ?: null; |
||
| 208 | if($senderName instanceof Parameter) { |
||
| 209 | $senderName = $senderName->getValue() ?? null; |
||
| 210 | } |
||
| 211 | |||
| 212 | if ($senderName === null || empty(trim($senderName))) { |
||
| 213 | $senderName = $this->userManager->getDisplayName($this->userId); |
||
| 214 | } |
||
| 215 | $sender = substr($iTipMessage->sender, 7); |
||
| 216 | |||
| 217 | switch (strtolower($iTipMessage->method)) { |
||
| 218 | case self::METHOD_REPLY: |
||
| 219 | $method = self::METHOD_REPLY; |
||
| 220 | $data = $this->imipService->buildBodyData($vEvent, $oldVevent); |
||
| 221 | break; |
||
| 222 | case self::METHOD_CANCEL: |
||
| 223 | $method = self::METHOD_CANCEL; |
||
| 224 | $data = $this->imipService->buildCancelledBodyData($vEvent); |
||
| 225 | break; |
||
| 226 | default: |
||
| 227 | $method = self::METHOD_REQUEST; |
||
| 228 | $data = $this->imipService->buildBodyData($vEvent, $oldVevent); |
||
| 229 | break; |
||
| 230 | } |
||
| 231 | |||
| 232 | |||
| 233 | $data['attendee_name'] = ($recipientName ?: $recipient); |
||
| 234 | $data['invitee_name'] = ($senderName ?: $sender); |
||
| 235 | |||
| 236 | $fromEMail = Util::getDefaultEmailAddress('invitations-noreply'); |
||
| 237 | $fromName = $this->imipService->getFrom($senderName, $this->defaults->getName()); |
||
| 238 | |||
| 239 | $message = $this->mailer->createMessage() |
||
| 240 | ->setFrom([$fromEMail => $fromName]) |
||
| 241 | ->setTo([$recipient => $recipientName]) |
||
| 242 | ->setReplyTo([$sender => $senderName]); |
||
| 243 | |||
| 244 | $template = $this->mailer->createEMailTemplate('dav.calendarInvite.' . $method, $data); |
||
| 245 | $template->addHeader(); |
||
| 246 | |||
| 247 | $this->imipService->addSubjectAndHeading($template, $method, $data['invitee_name'], $data['meeting_title']); |
||
| 248 | $this->imipService->addBulletList($template, $vEvent, $data); |
||
| 249 | |||
| 250 | // Only add response buttons to invitation requests: Fix Issue #11230 |
||
| 251 | if (strcasecmp($method, self::METHOD_REQUEST) === 0 && $this->imipService->getAttendeeRsvpOrReqForParticipant($attendee)) { |
||
| 252 | |||
| 253 | /* |
||
| 254 | ** Only offer invitation accept/reject buttons, which link back to the |
||
| 255 | ** nextcloud server, to recipients who can access the nextcloud server via |
||
| 256 | ** their internet/intranet. Issue #12156 |
||
| 257 | ** |
||
| 258 | ** The app setting is stored in the appconfig database table. |
||
| 259 | ** |
||
| 260 | ** For nextcloud servers accessible to the public internet, the default |
||
| 261 | ** "invitation_link_recipients" value "yes" (all recipients) is appropriate. |
||
| 262 | ** |
||
| 263 | ** When the nextcloud server is restricted behind a firewall, accessible |
||
| 264 | ** only via an internal network or via vpn, you can set "dav.invitation_link_recipients" |
||
| 265 | ** to the email address or email domain, or comma separated list of addresses or domains, |
||
| 266 | ** of recipients who can access the server. |
||
| 267 | ** |
||
| 268 | ** To always deliver URLs, set invitation_link_recipients to "yes". |
||
| 269 | ** To suppress URLs entirely, set invitation_link_recipients to boolean "no". |
||
| 270 | */ |
||
| 271 | |||
| 272 | $recipientDomain = substr(strrchr($recipient, '@'), 1); |
||
| 273 | $invitationLinkRecipients = explode(',', preg_replace('/\s+/', '', strtolower($this->config->getAppValue('dav', 'invitation_link_recipients', 'yes')))); |
||
| 274 | |||
| 275 | if (strcmp('yes', $invitationLinkRecipients[0]) === 0 |
||
| 276 | || in_array(strtolower($recipient), $invitationLinkRecipients) |
||
| 277 | || in_array(strtolower($recipientDomain), $invitationLinkRecipients)) { |
||
| 278 | $token = $this->imipService->createInvitationToken($iTipMessage, $vEvent, $lastOccurrence); |
||
| 279 | $this->imipService->addResponseButtons($template, $token); |
||
| 280 | $this->imipService->addMoreOptionsButton($template, $token); |
||
| 281 | } |
||
| 282 | } |
||
| 283 | |||
| 284 | $template->addFooter(); |
||
| 285 | |||
| 286 | $message->useTemplate($template); |
||
| 287 | |||
| 288 | $vCalendar = $this->imipService->generateVCalendar($iTipMessage, $vEvent); |
||
| 289 | |||
| 290 | $attachment = $this->mailer->createAttachment( |
||
| 291 | $vCalendar->serialize(), |
||
| 292 | 'event.ics', |
||
| 293 | 'text/calendar; method=' . $iTipMessage->method |
||
| 294 | ); |
||
| 295 | $message->attach($attachment); |
||
| 296 | |||
| 297 | try { |
||
| 298 | $failed = $this->mailer->send($message); |
||
| 299 | $iTipMessage->scheduleStatus = '1.1; Scheduling message is sent via iMip'; |
||
| 300 | if (!empty($failed)) { |
||
| 301 | $this->logger->error('Unable to deliver message to {failed}', ['app' => 'dav', 'failed' => implode(', ', $failed)]); |
||
| 302 | $iTipMessage->scheduleStatus = '5.0; EMail delivery failed'; |
||
| 303 | } |
||
| 304 | } catch (\Exception $ex) { |
||
| 305 | $this->logger->error($ex->getMessage(), ['app' => 'dav', 'exception' => $ex]); |
||
| 306 | $iTipMessage->scheduleStatus = '5.0; EMail delivery failed'; |
||
| 307 | } |
||
| 325 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.