| Conditions | 13 |
| Paths | 11 |
| Total Lines | 43 |
| Code Lines | 25 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 42 | private function sandbox($getParams, $message) |
||
| 43 | { |
||
| 44 | $type = $getParams['type'] ?? ''; |
||
| 45 | $host = $getParams['host'] ?? ''; |
||
| 46 | $user = $getParams['user'] ?? ''; |
||
| 47 | $pass = $getParams['pass'] ?? ''; |
||
| 48 | $port = $getParams['port'] ?? ''; |
||
| 49 | |||
| 50 | $sender = $getParams['sender'] ?? ''; |
||
| 51 | $recipients = $getParams['recipients'] ?? ''; |
||
| 52 | |||
| 53 | if (!$this->checkHost($host) || !is_numeric($port) || empty($user) || empty($pass)) { |
||
| 54 | return false; |
||
| 55 | } |
||
| 56 | |||
| 57 | if ('ssl' === $type || 'tls' === $type) { |
||
| 58 | $host = $type . '://' . $host; |
||
| 59 | } |
||
| 60 | |||
| 61 | if (!empty($sender) && $recipients) { |
||
| 62 | $recipients = str_replace("\r", '|', $recipients); |
||
| 63 | $recipients = str_replace("\n", '|', $recipients); |
||
| 64 | $recipients = explode('|', $recipients); |
||
| 65 | |||
| 66 | $messenger = new Messenger\Smtp($user, $pass, $host, (int) $port); |
||
| 67 | |||
| 68 | foreach($recipients as $recipient) { |
||
| 69 | if (filter_var($recipient, FILTER_VALIDATE_EMAIL)) { |
||
| 70 | $messenger->addRecipient($recipient); |
||
| 71 | } |
||
| 72 | } |
||
| 73 | |||
| 74 | if (filter_var($sender, FILTER_VALIDATE_EMAIL)) { |
||
| 75 | $messenger->addSender($sender); |
||
| 76 | } |
||
| 77 | |||
| 78 | $messenger->setSubject($message['title']); |
||
| 79 | |||
| 80 | if ($messenger->send($message['body'])) { |
||
| 81 | return true; |
||
| 82 | } |
||
| 83 | } |
||
| 84 | return false; |
||
| 85 | } |
||
| 104 | } |