| Conditions | 11 |
| Paths | 37 |
| Total Lines | 46 |
| Code Lines | 26 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 37 | public function sendEmailMessage( |
||
| 38 | string $sender, |
||
| 39 | string $recipient, |
||
| 40 | string $subject, |
||
| 41 | string $body, |
||
| 42 | ?string $name = null, |
||
| 43 | array $attachments = [], |
||
| 44 | ?string $replyTo = null |
||
| 45 | ): bool { |
||
| 46 | if ($subject === '' || !GeneralUtility::validEmail($sender) || !GeneralUtility::validEmail($recipient)) { |
||
| 47 | return false; |
||
| 48 | } |
||
| 49 | |||
| 50 | $useFluidEmail = (bool)(GeneralUtility::makeInstance(ExtensionConfiguration::class) |
||
| 51 | ->get('sf_event_mgt', 'useFluidEmail')); |
||
| 52 | |||
| 53 | $email = $this->getEmailObject($useFluidEmail); |
||
| 54 | $email->from(new Address($sender, $name)); |
||
|
|
|||
| 55 | $email->to($recipient); |
||
| 56 | $email->subject($subject); |
||
| 57 | $email->html($body); |
||
| 58 | if ($replyTo !== null && $replyTo !== '' && GeneralUtility::validEmail($replyTo)) { |
||
| 59 | $email->replyTo(new Address($replyTo)); |
||
| 60 | } |
||
| 61 | foreach ($attachments as $attachment) { |
||
| 62 | if (file_exists($attachment)) { |
||
| 63 | $email->attachFromPath($attachment); |
||
| 64 | } |
||
| 65 | } |
||
| 66 | |||
| 67 | if ($email instanceof FluidEmail) { |
||
| 68 | $email->format('html'); |
||
| 69 | $email->setTemplate('EventManagement'); |
||
| 70 | $email->assignMultiple([ |
||
| 71 | 'title' => $subject, |
||
| 72 | 'body' => $body, |
||
| 73 | ]); |
||
| 74 | } |
||
| 75 | |||
| 76 | $mailer = GeneralUtility::makeInstance(MailerInterface::class); |
||
| 77 | |||
| 78 | try { |
||
| 79 | $mailer->send($email); |
||
| 80 | return $mailer->getSentMessage() !== null; |
||
| 81 | } catch (TransportExceptionInterface $e) { |
||
| 82 | return false; |
||
| 83 | } |
||
| 98 |