Conditions | 10 |
Paths | 51 |
Total Lines | 51 |
Code Lines | 29 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 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 |
||
46 | private function sandbox($getParams, $message) |
||
47 | { |
||
48 | $params = [ |
||
49 | 'type', |
||
50 | 'host', |
||
51 | 'user', |
||
52 | 'pass', |
||
53 | 'port', |
||
54 | 'sender', |
||
55 | 'recipients', |
||
56 | ]; |
||
57 | |||
58 | foreach ($params as $param) { |
||
59 | ${$param} = $getParams[$param] ?? ''; |
||
60 | |||
61 | if (empty(${$param})) { |
||
62 | return false; |
||
63 | } |
||
64 | } |
||
65 | |||
66 | if (!$this->checkHost($host)) { |
||
|
|||
67 | return false; |
||
68 | } |
||
69 | |||
70 | if ('ssl' === $type || 'tls' === $type) { |
||
71 | $host = $type . '://' . $host; |
||
72 | } |
||
73 | |||
74 | $recipients = str_replace("\r", '|', $recipients); |
||
75 | $recipients = str_replace("\n", '|', $recipients); |
||
76 | $recipients = explode('|', $recipients); |
||
77 | |||
78 | $messenger = new SmtpTest($user, $pass, $host, (int) $port); |
||
79 | |||
80 | foreach ($recipients as $recipient) { |
||
81 | if (filter_var($recipient, FILTER_VALIDATE_EMAIL)) { |
||
82 | $messenger->addRecipient($recipient); |
||
83 | } |
||
84 | } |
||
85 | |||
86 | if (filter_var($sender, FILTER_VALIDATE_EMAIL)) { |
||
87 | $messenger->addSender($sender); |
||
88 | } |
||
89 | |||
90 | $messenger->setSubject($message['title']); |
||
91 | |||
92 | if ($messenger->send($message['body'])) { |
||
93 | return true; |
||
94 | } |
||
95 | |||
96 | return false; |
||
97 | } |
||
116 | } |