Conditions | 15 |
Paths | 512 |
Total Lines | 66 |
Code Lines | 39 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
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 send(EmailInterface $email) |
||
31 | { |
||
32 | $from = $email->getFrom(); |
||
33 | |||
34 | $body = [ |
||
35 | 'FromEmail' => $from['email'], |
||
36 | 'Subject' => $email->getSubject(), |
||
37 | 'To' => $this->mapEmails($email->getTo()) |
||
38 | ]; |
||
39 | |||
40 | if (!empty($from['name'])) { |
||
41 | $body['FromName'] = $from['name']; |
||
42 | } |
||
43 | |||
44 | if ($email->getReplyTo()) { |
||
45 | $body['Headers'] = [ |
||
46 | 'Reply-To' => $this->mapEmailsString($email->getReplyTo()) |
||
47 | ]; |
||
48 | } |
||
49 | |||
50 | if ($email->getCc()) { |
||
51 | $body['Cc'] = $this->mapEmails($email->getCc()); |
||
52 | } |
||
53 | |||
54 | if ($email->getBcc()) { |
||
55 | $body['Bcc'] = $this->mapEmails($email->getBcc()); |
||
56 | } |
||
57 | |||
58 | if ($email->getTextBody()) { |
||
59 | $body['Text-part'] = $email->getTextBody(); |
||
60 | } |
||
61 | |||
62 | if ($email->getHtmlBody()) { |
||
63 | $body['Html-part'] = $email->getHtmlBody(); |
||
64 | } |
||
65 | |||
66 | if ($email->getAttachements()) { |
||
67 | $attachements = []; |
||
68 | foreach ($email->getAttachements() as $attachement) { |
||
69 | $item = [ |
||
70 | 'Content-type' => $attachement->getMimeType(), |
||
71 | 'Filename' => $attachement->getName() |
||
72 | ]; |
||
73 | if (!$attachement->getPath() && $attachement->getContent()) { |
||
74 | $item['content'] = base64_encode($attachement->getContent()); |
||
75 | } elseif ($attachement->getPath()) { |
||
76 | $item['content'] = base64_encode(file_get_contents($attachement->getPath())); |
||
77 | } |
||
78 | $attachements[] = $item; |
||
79 | } |
||
80 | $body['Attachments'] = $attachements; |
||
81 | } |
||
82 | |||
83 | $response = $this->mailjet->post(Resources::$Email, ['body' => $body]); |
||
84 | |||
85 | if ($response->success()) { |
||
86 | if ($this->logger) { |
||
87 | $this->logger->info("Email sent: '{$email->getSubject()}'", $email); |
||
|
|||
88 | } |
||
89 | } else { |
||
90 | if ($this->logger) { |
||
91 | $this->logger->error("Email error: '{$response->getReasonPhrase()}'", $email); |
||
92 | } |
||
93 | throw new InvalidRequestException($response->getReasonPhrase()); |
||
94 | } |
||
95 | } |
||
96 | |||
145 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: