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