| Conditions | 14 |
| Paths | 11 |
| Total Lines | 54 |
| Code Lines | 34 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 | $data = []; |
||
| 50 | |||
| 51 | $sender = $getParams['sender'] ?? ''; |
||
| 52 | $recipients = $getParams['recipients'] ?? ''; |
||
| 53 | |||
| 54 | if ( |
||
| 55 | ( |
||
| 56 | !filter_var($host, FILTER_VALIDATE_IP) && |
||
| 57 | !filter_var($host, FILTER_VALIDATE_DOMAIN) |
||
| 58 | ) || |
||
| 59 | !is_numeric($port) || |
||
| 60 | empty($user) || |
||
| 61 | empty($pass) |
||
| 62 | ) { |
||
| 63 | $data['result']['message'] = 'Invalid fields.'; |
||
| 64 | $output = json_encode($data); |
||
| 65 | return $this->respondJson($output); |
||
|
|
|||
| 66 | } |
||
| 67 | |||
| 68 | if ('ssl' === $type || 'tls' === $type) { |
||
| 69 | $host = $type . '://' . $host; |
||
| 70 | } |
||
| 71 | |||
| 72 | if (!empty($sender) && $recipients) { |
||
| 73 | $recipients = str_replace("\r", '|', $recipients); |
||
| 74 | $recipients = str_replace("\n", '|', $recipients); |
||
| 75 | $recipients = explode('|', $recipients); |
||
| 76 | |||
| 77 | $messenger = new Messenger\Smtp($user, $pass, $host, (int) $port); |
||
| 78 | |||
| 79 | foreach($recipients as $recipient) { |
||
| 80 | if (filter_var($recipient, FILTER_VALIDATE_EMAIL)) { |
||
| 81 | $messenger->addRecipient($recipient); |
||
| 82 | } |
||
| 83 | } |
||
| 84 | |||
| 85 | if (filter_var($sender, FILTER_VALIDATE_EMAIL)) { |
||
| 86 | $messenger->addSender($sender); |
||
| 87 | } |
||
| 88 | |||
| 89 | $messenger->setSubject($message['title']); |
||
| 90 | |||
| 91 | if ($messenger->send($message['body'])) { |
||
| 92 | return true; |
||
| 93 | } |
||
| 94 | } |
||
| 95 | return false; |
||
| 96 | } |
||
| 97 | } |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.