| Conditions | 7 |
| Paths | 12 |
| Total Lines | 92 |
| Code Lines | 58 |
| 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 |
||
| 24 | public function send(Email $email) |
||
| 25 | { |
||
| 26 | if (!empty($this->_config['queue'])) { |
||
| 27 | $this->_config = $this->_config['queue'] + $this->_config; |
||
| 28 | $email->setConfig((array)$this->_config['queue'] + [ |
||
| 29 | 'queue' => [] |
||
| 30 | ]); |
||
| 31 | unset($this->_config['queue']); |
||
| 32 | } |
||
| 33 | |||
| 34 | $settings = [ |
||
| 35 | 'from' => [ |
||
| 36 | $email->getFrom() |
||
| 37 | ], |
||
| 38 | 'to' => [ |
||
| 39 | $email->getTo() |
||
| 40 | ], |
||
| 41 | 'cc' => [ |
||
| 42 | $email->getCc() |
||
| 43 | ], |
||
| 44 | 'bcc' => [ |
||
| 45 | $email->getBcc() |
||
| 46 | ], |
||
| 47 | 'charset' => [ |
||
| 48 | $email->getCharset() |
||
| 49 | ], |
||
| 50 | 'replyTo' => [ |
||
| 51 | $email->getReplyTo() |
||
| 52 | ], |
||
| 53 | 'readReceipt' => [ |
||
| 54 | $email->getReadReceipt() |
||
| 55 | ], |
||
| 56 | 'returnPath' => [ |
||
| 57 | $email->getReturnPath() |
||
| 58 | ], |
||
| 59 | 'messageId' => [ |
||
| 60 | $email->getMessageId() |
||
| 61 | ], |
||
| 62 | 'domain' => [ |
||
| 63 | $email->getDomain() |
||
| 64 | ], |
||
| 65 | 'headers' => [ |
||
| 66 | $email->getHeaders() |
||
| 67 | ], |
||
| 68 | 'headerCharset' => [ |
||
| 69 | $email->getHeaderCharset() |
||
| 70 | ], |
||
| 71 | 'theme' => [ |
||
| 72 | $email->viewBuilder()->getTheme() |
||
| 73 | ], |
||
| 74 | 'profile' => [ |
||
| 75 | $email->getProfile() |
||
| 76 | ], |
||
| 77 | 'emailFormat' => [ |
||
| 78 | $email->getEmailFormat() |
||
| 79 | ], |
||
| 80 | 'subject' => method_exists($email, 'getOriginalSubject') ? [ |
||
| 81 | $email->getOriginalSubject() |
||
| 82 | ] : [ |
||
| 83 | $email->getSubject() |
||
| 84 | ], |
||
| 85 | 'transport' => [ |
||
| 86 | $this->_config['transport'] |
||
| 87 | ], |
||
| 88 | 'attachments' => [ |
||
| 89 | $email->getAttachments() |
||
| 90 | ], |
||
| 91 | 'template' => [ |
||
| 92 | $email->viewBuilder()->getTemplate() |
||
| 93 | ], |
||
| 94 | 'layout' => [ |
||
| 95 | $email->viewBuilder()->getLayout() |
||
| 96 | ], |
||
| 97 | 'viewVars' => [ |
||
| 98 | $email->getViewVars() |
||
| 99 | ] |
||
| 100 | ]; |
||
| 101 | |||
| 102 | foreach ($settings as $setting => $value) { |
||
| 103 | if (array_key_exists(0, $value) && ($value[0] === null || $value[0] === [])) { |
||
| 104 | unset($settings[$setting]); |
||
| 105 | } |
||
| 106 | } |
||
| 107 | |||
| 108 | $QueuedJobs = $this->getQueuedJobsModel(); |
||
| 109 | $result = $QueuedJobs->createJob('Email', [ |
||
| 110 | 'settings' => $settings |
||
| 111 | ]); |
||
| 112 | $result['headers'] = ''; |
||
| 113 | $result['message'] = ''; |
||
| 114 | |||
| 115 | return $result->toArray(); |
||
| 116 | } |
||
| 130 |