Conditions | 12 |
Paths | 64 |
Total Lines | 53 |
Code Lines | 33 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
35 | public function send(EmailInterface $email) |
||
36 | { |
||
37 | $m = new SimpleEmailServiceMessage(); |
||
38 | $m->addTo($this->mapEmails($email->getTo())); |
||
39 | $m->setFrom($this->mapEmail($email->getFrom())); |
||
40 | |||
41 | if ($email->getReplyTo()) { |
||
42 | $m->addReplyTo($this->mapEmails($email->getReplyTo())); |
||
43 | } |
||
44 | |||
45 | if ($email->getCc()) { |
||
46 | $m->addCC($this->mapEmails($email->getCc())); |
||
47 | } |
||
48 | |||
49 | if ($email->getBcc()) { |
||
50 | $m->addBCC($this->mapEmails($email->getBcc())); |
||
51 | } |
||
52 | |||
53 | $m->setSubject($email->getSubject()); |
||
54 | $m->setMessageFromString($email->getTextBody(), $email->getHtmlBody()); |
||
55 | |||
56 | if ($email->getAttachements()) { |
||
57 | foreach ($email->getAttachements() as $attachement) { |
||
58 | if (!$attachement->getPath() && $attachement->getContent()) { |
||
59 | $m->addAttachmentFromData( |
||
60 | $attachement->getName(), |
||
61 | $attachement->getContent(), |
||
62 | $attachement->getMimeType() |
||
63 | ); |
||
64 | } elseif ($attachement->getPath()) { |
||
65 | $m->addAttachmentFromFile( |
||
66 | $attachement->getName(), |
||
67 | $attachement->getPath(), |
||
68 | $attachement->getMimeType() |
||
69 | ); |
||
70 | } |
||
71 | } |
||
72 | } |
||
73 | |||
74 | $ses = new SimpleEmailService($this->accessKey, $this->secretKey, $this->host, false); |
||
75 | $response = $ses->sendEmail($m, false, false); |
||
76 | |||
77 | if (empty($response['MessageId'])) { |
||
78 | if ($this->logger) { |
||
79 | $this->logger->error("Email error: Unknown error", $email); |
||
|
|||
80 | } |
||
81 | throw new Exception('Unknown error', 603); |
||
82 | } else { |
||
83 | if ($this->logger) { |
||
84 | $this->logger->info("Email sent: '{$email->getSubject()}'", $email); |
||
85 | } |
||
86 | } |
||
87 | } |
||
88 | |||
111 |
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: