| Conditions | 10 |
| Paths | 82 |
| Total Lines | 67 |
| Code Lines | 40 |
| 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 |
||
| 32 | public function swiftMessageInitializeAndSend(array $data = array()) |
||
| 33 | { |
||
| 34 | $swiftMessageInstance = \Swift_Message::newInstance(); |
||
| 35 | |||
| 36 | if (!isset($data['subject'])) { |
||
| 37 | throw new \Exception('You need to specify a subject'); |
||
| 38 | } |
||
| 39 | |||
| 40 | if (!isset($data['to'])) { |
||
| 41 | throw new \Exception('You need to specify a recipient'); |
||
| 42 | } |
||
| 43 | |||
| 44 | $from = isset($data['from']) |
||
| 45 | ? $data['from'] |
||
| 46 | : $this->app['email'] |
||
| 47 | ; |
||
| 48 | $to = $data['to']; |
||
| 49 | |||
| 50 | $swiftMessageInstance |
||
| 51 | ->setSubject($data['subject']) |
||
| 52 | ->setTo($to) |
||
| 53 | ->setFrom($from) |
||
| 54 | ; |
||
| 55 | |||
| 56 | if (isset($data['cc'])) { |
||
| 57 | $swiftMessageInstance->setCc($data['cc']); |
||
| 58 | } |
||
| 59 | |||
| 60 | if (isset($data['bcc'])) { |
||
| 61 | $swiftMessageInstance->setBcc($data['bcc']); |
||
| 62 | } |
||
| 63 | |||
| 64 | $templateData = array( |
||
| 65 | 'app' => $this->app, |
||
| 66 | 'user' => $this->app['user'], |
||
| 67 | 'email' => $to, |
||
| 68 | 'swiftMessage' => $swiftMessageInstance, |
||
| 69 | ); |
||
| 70 | |||
| 71 | if (isset($data['templateData'])) { |
||
| 72 | $templateData = array_merge( |
||
| 73 | $templateData, |
||
| 74 | $data['templateData'] |
||
| 75 | ); |
||
| 76 | } |
||
| 77 | |||
| 78 | if (isset($data['body'])) { |
||
| 79 | $bodyType = isset($data['bodyType']) |
||
| 80 | ? $data['bodyType'] |
||
| 81 | : 'text/html' |
||
| 82 | ; |
||
| 83 | $isTwigTemplate = isset($data['contentIsTwigTemplate']) |
||
| 84 | ? $data['contentIsTwigTemplate'] |
||
| 85 | : true |
||
| 86 | ; |
||
| 87 | |||
| 88 | $swiftMessageBody = $this->app['mailer.css_to_inline_styles_converter']( |
||
| 89 | $data['body'], |
||
| 90 | $templateData, |
||
| 91 | $isTwigTemplate |
||
| 92 | ); |
||
| 93 | |||
| 94 | $swiftMessageInstance->setBody($swiftMessageBody, $bodyType); |
||
| 95 | } |
||
| 96 | |||
| 97 | return $this->app['mailer']->send($swiftMessageInstance); |
||
| 98 | } |
||
| 99 | |||
| 145 |