| Conditions | 10 |
| Paths | 36 |
| Total Lines | 46 |
| Code Lines | 28 |
| 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 |
||
| 22 | public function createMessage($class, $name, array $parameters) |
||
| 23 | { |
||
| 24 | $subject = $txtBody = $htmlBody = null; |
||
| 25 | $bundle = $this->bundleGuesser->getBundleForClass($class); |
||
| 26 | $txtTpl = sprintf('%s:Mails:%s.txt.twig', $bundle->getName(), $name); |
||
| 27 | $htmlTpl = sprintf('%s:Mails:%s.html.twig', $bundle->getName(), $name); |
||
| 28 | |||
| 29 | if (true === $this->twig->getLoader()->exists($txtTpl)) { |
||
| 30 | $template = $this->twig->loadTemplate($txtTpl); |
||
| 31 | $subject = $template->renderBlock('subject', $parameters); |
||
|
|
|||
| 32 | $txtBody = $template->renderBlock('body', $parameters); |
||
| 33 | } |
||
| 34 | |||
| 35 | if (true === $this->twig->getLoader()->exists($htmlTpl)) { |
||
| 36 | $template = $this->twig->loadTemplate($htmlTpl); |
||
| 37 | $subject = $subject ?: $template->renderBlock('subject', $parameters); |
||
| 38 | $htmlBody = $template->renderBlock('body', $parameters); |
||
| 39 | } |
||
| 40 | |||
| 41 | if (!$subject) { |
||
| 42 | throw new \Twig_Error_Loader(sprintf( |
||
| 43 | 'Can not find mail subject in "%s" or "%s".', $txtTpl, $htmlTpl |
||
| 44 | )); |
||
| 45 | } |
||
| 46 | |||
| 47 | if (!$txtBody && !$htmlBody) { |
||
| 48 | throw new \Twig_Error_Loader(sprintf( |
||
| 49 | 'Can not find mail body in "%s" or "%s".', $txtTpl, $htmlTpl |
||
| 50 | )); |
||
| 51 | } |
||
| 52 | |||
| 53 | $message = $this->mailer->createMessage(); |
||
| 54 | $message->setSubject($subject); |
||
| 55 | |||
| 56 | if ($txtBody) { |
||
| 57 | $message->setBody($txtBody, 'text/plain'); |
||
| 58 | } else { |
||
| 59 | $message->setBody($htmlBody, 'text/html'); |
||
| 60 | } |
||
| 61 | |||
| 62 | if ($txtBody && $htmlBody) { |
||
| 63 | $message->addPart($htmlBody, 'text/html'); |
||
| 64 | } |
||
| 65 | |||
| 66 | return $message; |
||
| 67 | } |
||
| 68 | } |
||
| 69 |
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.