| Conditions | 29 |
| Paths | > 20000 |
| Total Lines | 116 |
| Code Lines | 73 |
| 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 executeInternal() |
||
| 82 | { |
||
| 83 | $languageBackup = null; |
||
| 84 | // Flexform overrides write strings instead of integers so |
||
| 85 | // we need to cast the string '0' to false. |
||
| 86 | if ( |
||
| 87 | isset($this->options['addHtmlPart']) |
||
| 88 | && $this->options['addHtmlPart'] === '0' |
||
| 89 | ) { |
||
| 90 | $this->options['addHtmlPart'] = false; |
||
| 91 | } |
||
| 92 | |||
| 93 | $subject = $this->parseOption('subject'); |
||
| 94 | $recipients = $this->getRecipients('recipients'); |
||
| 95 | $senderAddress = $this->parseOption('senderAddress'); |
||
| 96 | $senderAddress = is_string($senderAddress) ? $senderAddress : ''; |
||
| 97 | $senderName = $this->parseOption('senderName'); |
||
| 98 | $senderName = is_string($senderName) ? $senderName : ''; |
||
| 99 | $replyToRecipients = $this->getRecipients('replyToRecipients'); |
||
| 100 | $carbonCopyRecipients = $this->getRecipients('carbonCopyRecipients'); |
||
| 101 | $blindCarbonCopyRecipients = $this->getRecipients('blindCarbonCopyRecipients'); |
||
| 102 | $addHtmlPart = $this->parseOption('addHtmlPart') ? true : false; |
||
| 103 | $attachUploads = $this->parseOption('attachUploads'); |
||
| 104 | $useFluidEmail = $this->parseOption('useFluidEmail'); |
||
| 105 | $title = $this->parseOption('title'); |
||
| 106 | $title = is_string($title) && $title !== '' ? $title : $subject; |
||
| 107 | |||
| 108 | if (empty($subject)) { |
||
| 109 | throw new FinisherException('The option "subject" must be set for the EmailFinisher.', 1327060320); |
||
| 110 | } |
||
| 111 | if (empty($recipients)) { |
||
| 112 | throw new FinisherException('The option "recipients" must be set for the EmailFinisher.', 1327060200); |
||
| 113 | } |
||
| 114 | if (empty($senderAddress)) { |
||
| 115 | throw new FinisherException('The option "senderAddress" must be set for the EmailFinisher.', 1327060210); |
||
| 116 | } |
||
| 117 | |||
| 118 | $formRuntime = $this->finisherContext->getFormRuntime(); |
||
| 119 | |||
| 120 | $translationService = TranslationService::getInstance(); |
||
| 121 | if (is_string($this->options['translation']['language'] ?? null) && $this->options['translation']['language'] !== '') { |
||
| 122 | $languageBackup = $translationService->getLanguage(); |
||
| 123 | $translationService->setLanguage($this->options['translation']['language']); |
||
| 124 | } |
||
| 125 | |||
| 126 | $mail = $useFluidEmail |
||
| 127 | ? $this |
||
| 128 | ->initializeFluidEmail($formRuntime) |
||
| 129 | ->format($addHtmlPart ? FluidEmail::FORMAT_BOTH : FluidEmail::FORMAT_PLAIN) |
||
| 130 | ->assign('title', $title) |
||
| 131 | : GeneralUtility::makeInstance(MailMessage::class); |
||
| 132 | |||
| 133 | |||
| 134 | ->from(new Address($senderAddress, $senderName)) |
||
| 135 | ->to(...$recipients) |
||
| 136 | ->subject($subject); |
||
|
|
|||
| 137 | |||
| 138 | if (!empty($replyToRecipients)) { |
||
| 139 | $mail->replyTo(...$replyToRecipients); |
||
| 140 | } |
||
| 141 | |||
| 142 | if (!empty($carbonCopyRecipients)) { |
||
| 143 | $mail->cc(...$carbonCopyRecipients); |
||
| 144 | } |
||
| 145 | |||
| 146 | if (!empty($blindCarbonCopyRecipients)) { |
||
| 147 | $mail->bcc(...$blindCarbonCopyRecipients); |
||
| 148 | } |
||
| 149 | |||
| 150 | if (!$useFluidEmail) { |
||
| 151 | $parts = [ |
||
| 152 | [ |
||
| 153 | 'format' => 'Plaintext', |
||
| 154 | 'contentType' => 'text/plain', |
||
| 155 | ], |
||
| 156 | ]; |
||
| 157 | |||
| 158 | if ($addHtmlPart) { |
||
| 159 | $parts[] = [ |
||
| 160 | 'format' => 'Html', |
||
| 161 | 'contentType' => 'text/html', |
||
| 162 | ]; |
||
| 163 | } |
||
| 164 | |||
| 165 | foreach ($parts as $i => $part) { |
||
| 166 | $standaloneView = $this->initializeStandaloneView($formRuntime, $part['format']); |
||
| 167 | $message = $standaloneView->render(); |
||
| 168 | |||
| 169 | if ($part['contentType'] === 'text/plain') { |
||
| 170 | $mail->text($message); |
||
| 171 | } else { |
||
| 172 | $mail->html($message); |
||
| 173 | } |
||
| 174 | } |
||
| 175 | } |
||
| 176 | |||
| 177 | if (!empty($languageBackup)) { |
||
| 178 | $translationService->setLanguage($languageBackup); |
||
| 179 | } |
||
| 180 | |||
| 181 | if ($attachUploads) { |
||
| 182 | foreach ($formRuntime->getFormDefinition()->getRenderablesRecursively() as $element) { |
||
| 183 | if (!$element instanceof FileUpload) { |
||
| 184 | continue; |
||
| 185 | } |
||
| 186 | $file = $formRuntime[$element->getIdentifier()]; |
||
| 187 | if ($file) { |
||
| 188 | if ($file instanceof FileReference) { |
||
| 189 | $file = $file->getOriginalResource(); |
||
| 190 | } |
||
| 191 | $mail->attach($file->getContents(), $file->getName(), $file->getMimeType()); |
||
| 192 | } |
||
| 193 | } |
||
| 194 | } |
||
| 195 | |||
| 196 | $useFluidEmail ? GeneralUtility::makeInstance(Mailer::class)->send($mail) : $mail->send(); |
||
| 197 | } |
||
| 332 |