Conditions | 24 |
Paths | 472 |
Total Lines | 68 |
Code Lines | 54 |
Lines | 0 |
Ratio | 0 % |
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 |
||
28 | public function send(EmailInterface $email) |
||
29 | { |
||
30 | try { |
||
31 | $client = new PostmarkClient($this->serverApiToken); |
||
32 | $sendResult = $client->sendEmail( |
||
33 | $this->mapEmail($email->getFrom()), |
||
34 | $this->mapEmails($email->getTo()), |
||
35 | $email->getSubject(), |
||
36 | $email->getHtmlBody(), |
||
37 | $email->getTextBody(), |
||
38 | null, |
||
39 | true, |
||
40 | $this->mapEmails($email->getReplyTo()), |
||
41 | $this->mapEmails($email->getCc()), |
||
42 | $this->mapEmails($email->getBcc()), |
||
43 | null, |
||
44 | $this->mapAttachments($email->getAttachements()) |
||
45 | ); |
||
46 | |||
47 | if (!isset($sendResult) || (!isset($sendResult[0]) && !isset($sendResult['ErrorCode']))) { |
||
48 | throw new InvalidRequestException; |
||
49 | } elseif (!isset($sendResult['ErrorCode']) && isset($sendResult[0])) { |
||
50 | $sendResult = $sendResult[0]; |
||
51 | } |
||
52 | |||
53 | if ((int) $sendResult['ErrorCode'] !== 0) { |
||
54 | $e = new PostmarkException(); |
||
55 | $e->httpStatusCode = $sendResult['ErrorCode']; |
||
56 | $e->message = $sendResult['Message']; |
||
57 | $e->postmarkApiErrorCode = $sendResult['ErrorCode']; |
||
58 | throw $e; |
||
59 | } |
||
60 | |||
61 | if ($this->logger) { |
||
62 | $this->logger->info("Email sent: '{$email->getSubject()}'", $email); |
||
|
|||
63 | } |
||
64 | } catch (Exception $e) { |
||
65 | if ($this->logger) { |
||
66 | $this->logger->info("Email error: '{$e->getMessage()}'", $email); |
||
67 | } |
||
68 | throw $e; |
||
69 | } catch (PostmarkException $e) { |
||
70 | if ($this->logger) { |
||
71 | $this->logger->info("Email error: '{$e->getMessage()}'", $email); |
||
72 | } |
||
73 | switch ($e->postmarkApiErrorCode) { |
||
74 | case 10: |
||
75 | case 400: |
||
76 | case 401: |
||
77 | case 405: |
||
78 | case 500: |
||
79 | case 501: |
||
80 | case 502: |
||
81 | case 503: |
||
82 | throw new UnauthorizedException($e->message, 602, $e); |
||
83 | case 100: |
||
84 | case 411: |
||
85 | throw new EmailDeliveryException($e->message, 600, $e); |
||
86 | default: |
||
87 | throw new InvalidRequestException($e->message, 601, $e); |
||
88 | } |
||
89 | } catch (\Exception $e) { |
||
90 | if ($this->logger) { |
||
91 | $this->logger->info("Email error: '{$e->getMessage()}'", $email); |
||
92 | } |
||
93 | throw new Exception($e->getMessage(), $e->getCode(), $e); |
||
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: