Conditions | 11 |
Paths | 8 |
Total Lines | 40 |
Code Lines | 29 |
Lines | 10 |
Ratio | 25 % |
Changes | 2 | ||
Bugs | 0 | Features | 2 |
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 |
||
25 | public function send(EmailInterface $email) |
||
26 | { |
||
27 | $mailin = new Mailin('https://api.sendinblue.com/v2.0', $this->accessKey); |
||
28 | |||
29 | $data = [ |
||
30 | 'to' => $this->mapEmails($email->getTo()), |
||
31 | 'cc' => $this->mapEmails($email->getCc()), |
||
32 | 'bcc' => $this->mapEmails($email->getBcc()), |
||
33 | 'from' => $this->mapEmail($email->getFrom()), |
||
34 | 'replyto' => $this->mapEmails($email->getReplyTo()), |
||
35 | 'subject' => $email->getSubject(), |
||
36 | 'text' => $email->getTextBody(), |
||
37 | 'html' => $email->getHtmlBody(), |
||
38 | 'attachment' => $this->mapAttachments($email->getAttachements()) |
||
39 | ]; |
||
40 | |||
41 | $response = $mailin->send_email($data); |
||
42 | if ($response && $response['code'] && $response['code'] === 'success') { |
||
43 | if ($this->logger) { |
||
44 | $this->logger->info("Email sent: '{$email->getSubject()}'", $email); |
||
|
|||
45 | } |
||
46 | } else { |
||
47 | if (!$response || !$response['code']) { |
||
48 | throw new Exception('Unknown exception'); |
||
49 | } else { |
||
50 | switch ($response['code']) { |
||
51 | View Code Duplication | case 'failure': |
|
52 | if ($this->logger) { |
||
53 | $this->logger->info("Email error: '{$response['message']}'", $email); |
||
54 | } |
||
55 | throw new InvalidRequestException($response['message']); |
||
56 | View Code Duplication | case 'error': |
|
57 | if ($this->logger) { |
||
58 | $this->logger->info("Email error: '{$response['message']}'", $email); |
||
59 | } |
||
60 | throw new InvalidRequestException($response['message']); |
||
61 | } |
||
62 | } |
||
63 | } |
||
64 | } |
||
65 | |||
121 |
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: