| Conditions | 11 |
| Paths | 768 |
| Total Lines | 41 |
| Code Lines | 29 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 112 | public function sendPerformed(Swift_Events_SendEvent $e) |
||
| 113 | { |
||
| 114 | $message = $e->getMessage(); |
||
| 115 | $recipients = $e->getRecipients(); |
||
| 116 | |||
| 117 | $to = array(); |
||
| 118 | foreach ($recipients->getTo() as $addr) |
||
| 119 | { |
||
| 120 | if ($this->isWindows()) $to[] = substr($addr->build(true), 1, -1); |
||
| 121 | else $to[] = $addr->build(); |
||
| 122 | } |
||
| 123 | $to = implode(", ", $to); |
||
| 124 | |||
| 125 | $bcc_orig = $message->headers->has("Bcc") ? $message->headers->get("Bcc") : null; |
||
| 126 | $subject_orig = $message->headers->has("Subject") ? $message->headers->get("Subject") : null; |
||
| 127 | $to_orig = $message->headers->has("To") ? $message->headers->get("To") : null; |
||
| 128 | |||
| 129 | $bcc = array(); |
||
| 130 | foreach ($recipients->getBcc() as $addr) $bcc[] = $addr->build(); |
||
| 131 | if (!empty($bcc)) $message->headers->set("Bcc", $bcc); |
||
| 132 | $bcc = null; |
||
| 133 | |||
| 134 | $body_data = $message->buildData(); |
||
| 135 | $message_body = $body_data->readFull(); |
||
| 136 | |||
| 137 | $subject_enc = $message->headers->has("Subject") ? $message->headers->getEncoded("Subject") : ""; |
||
| 138 | |||
| 139 | $message->headers->set("To", null); |
||
| 140 | $message->headers->set("Subject", null); |
||
| 141 | |||
| 142 | $sender = $e->getSender(); |
||
| 143 | $this->returnPath = $sender->build(); |
||
| 144 | if ($message->headers->has("Return-Path")) $this->returnPath = $message->headers->get("Return-Path"); |
||
| 145 | if (preg_match("~<([^>]+)>[^>]*\$~", $this->returnPath, $matches)) $this->returnPath = $matches[1]; |
||
| 146 | |||
| 147 | $this->doMail($to, $subject_enc, $message_body, $message->headers, sprintf($this->getAdditionalParams(), $this->returnPath)); |
||
| 148 | $message->setLE($this->oldLE); |
||
| 149 | $message->headers->set("To", $to_orig); |
||
| 150 | $message->headers->set("Subject", $subject_orig); |
||
| 151 | $message->headers->set("Bcc", $bcc_orig); |
||
| 152 | } |
||
| 153 | |||
| 179 |
Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.