| Conditions | 4 |
| Paths | 4 |
| Total Lines | 53 |
| Code Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | 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 |
||
| 7 | public function search() |
||
| 8 | { |
||
| 9 | $gets = $this->request->gets(); |
||
| 10 | |||
| 11 | if (empty($gets)) { |
||
| 12 | $users = $this->load->model('User')->users(); |
||
| 13 | $usersformatted = $this->formatUsers($users); |
||
|
|
|||
| 14 | return json_encode($usersformatted); |
||
| 15 | } |
||
| 16 | |||
| 17 | $gender = $gets['gender'] ?? null; |
||
| 18 | $zip = $gets['zip'] ?? null; |
||
| 19 | $country = $gets['country'] ?? null; |
||
| 20 | $registration_from = $gets['registration_from'] ?? null; |
||
| 21 | $registration_to = $gets['registration_to'] ?? null; |
||
| 22 | $active = $gets['active'] ?? null; |
||
| 23 | $pending = $gets['pending'] ?? null; |
||
| 24 | $inactive = $gets['inactive'] ?? null; |
||
| 25 | $online = $gets['online'] ?? null; |
||
| 26 | $offline = $gets['offline'] ?? null; |
||
| 27 | |||
| 28 | $sql = ''; |
||
| 29 | $wheres = []; |
||
| 30 | |||
| 31 | list($sql, $wheres) = $this->active($active, $sql, $wheres); |
||
| 32 | list($sql, $wheres) = $this->pending($pending, $sql, $wheres); |
||
| 33 | list($sql, $wheres) = $this->inactive($inactive, $sql, $wheres); |
||
| 34 | $sql = $this->formatStatus($sql); |
||
| 35 | list($sql, $wheres) = $this->online($online, $sql, $wheres); |
||
| 36 | list($sql, $wheres) = $this->offline($offline, $sql, $wheres); |
||
| 37 | $sql = $this->formatLogin($sql); |
||
| 38 | list($sql, $wheres) = $this->gender($gender, $sql, $wheres); |
||
| 39 | list($sql, $wheres) = $this->zip($zip, $sql, $wheres); |
||
| 40 | list($sql, $wheres) = $this->country($country, $sql, $wheres); |
||
| 41 | list($sql, $wheres) = $this->registration($registration_from, $registration_to, $sql, $wheres); |
||
| 42 | |||
| 43 | $sql = $this->formatSql($sql); |
||
| 44 | |||
| 45 | if ($sql == '') { |
||
| 46 | $users = $this->load->model('User')->users(); |
||
| 47 | $usersformatted = $this->formatUsers($users); |
||
| 48 | return json_encode($usersformatted); |
||
| 49 | } |
||
| 50 | |||
| 51 | $users = $this->load->model('User')->filter($sql, $wheres); |
||
| 52 | |||
| 53 | $msg = null; |
||
| 54 | if (!$users) { |
||
| 55 | $msg = 'no users'; |
||
| 56 | return json_encode($msg); |
||
| 57 | } |
||
| 58 | $msg = $this->formatUsers($users); |
||
| 59 | return json_encode($msg); |
||
| 60 | } |
||
| 180 |