| Conditions | 13 |
| Paths | 513 |
| Total Lines | 61 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 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 |
||
| 107 | public function renderMail(array $data = []) :\Swift_Message |
||
| 108 | { |
||
| 109 | $mail = new \Swift_Message(); |
||
| 110 | |||
| 111 | $twigEnvironment = clone $this->twigEnvironment; |
||
| 112 | $function = new \Twig_SimpleFunction('embedImage', function ($imgPath) use ($mail) { |
||
| 113 | return $mail->embed(\Swift_Image::fromPath($imgPath)); |
||
| 114 | }); |
||
| 115 | $twigEnvironment->addFunction($function); |
||
| 116 | |||
| 117 | $template = $twigEnvironment->loadTemplate($this->twigPath); |
||
| 118 | |||
| 119 | if (!$template->hasBlock('subject') || !$template->hasBlock('body_html') || !$template->hasBlock('body_text')) { |
||
| 120 | //TODO extract body_text from body HTML |
||
| 121 | throw MissingBlockException::missingBlock($template->getBlockNames()); |
||
| 122 | } |
||
| 123 | |||
| 124 | $subject = $template->renderBlock('subject', $data); |
||
|
|
|||
| 125 | $bodyHtml = $template->renderBlock('body_html', $data); |
||
| 126 | $bodyText = $template->renderBlock('body_text', $data); |
||
| 127 | |||
| 128 | $mail->setSubject($subject); |
||
| 129 | $mail->setBody($bodyHtml); |
||
| 130 | $mail->addPart($bodyText); |
||
| 131 | |||
| 132 | if ($this->fromAdresses) { |
||
| 133 | $mail->setFrom($this->fromAdresses, $this->fromName); |
||
| 134 | $mail->setSender($this->fromAdresses, $this->fromName); |
||
| 135 | } |
||
| 136 | |||
| 137 | if ($this->toAdresses) { |
||
| 138 | $mail->setTo($this->toAdresses, $this->toName); |
||
| 139 | } |
||
| 140 | |||
| 141 | if ($this->bccAdresses) { |
||
| 142 | $mail->setBcc($this->bccAdresses, $this->bccName); |
||
| 143 | } |
||
| 144 | if ($this->ccAdresses) { |
||
| 145 | $mail->setCc($this->ccAdresses, $this->ccName); |
||
| 146 | } |
||
| 147 | if ($this->replyToAdresses) { |
||
| 148 | $mail->setReplyTo($this->replyToAdresses, $this->replyToName); |
||
| 149 | } |
||
| 150 | |||
| 151 | if ($this->maxLineLength) { |
||
| 152 | $mail->setMaxLineLength($this->maxLineLength); |
||
| 153 | } |
||
| 154 | if ($this->priority) { |
||
| 155 | $mail->setPriority($this->priority); |
||
| 156 | } |
||
| 157 | |||
| 158 | if ($this->readReceiptTo) { |
||
| 159 | $mail->setReadReceiptTo($this->readReceiptTo); |
||
| 160 | } |
||
| 161 | |||
| 162 | if ($this->returnPath) { |
||
| 163 | $mail->setReturnPath($this->returnPath); |
||
| 164 | } |
||
| 165 | |||
| 166 | return $mail; |
||
| 167 | } |
||
| 168 | |||
| 281 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.