| Conditions | 7 |
| Paths | 32 |
| Total Lines | 68 |
| Code Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 31 | public static function listZombies( |
||
| 32 | $ceiling, |
||
| 33 | $active_only = true, |
||
| 34 | $from = 0, |
||
| 35 | $count = 10, |
||
| 36 | $column = 'user.firstname', |
||
| 37 | $direction = 'desc' |
||
| 38 | ) { |
||
| 39 | if (empty($column)) { |
||
| 40 | $column = 'user.firstname'; |
||
| 41 | } |
||
| 42 | $ceiling = is_numeric($ceiling) ? (int) $ceiling : strtotime($ceiling); |
||
| 43 | $ceiling = date('Y-m-d H:i:s', $ceiling); |
||
| 44 | |||
| 45 | $user_table = Database::get_main_table(TABLE_MAIN_USER); |
||
| 46 | $login_table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN); |
||
| 47 | |||
| 48 | $sql = 'SELECT |
||
| 49 | user.user_id, |
||
| 50 | user.official_code, |
||
| 51 | user.firstname, |
||
| 52 | user.lastname, |
||
| 53 | user.username, |
||
| 54 | user.auth_source, |
||
| 55 | user.email, |
||
| 56 | user.status, |
||
| 57 | user.registration_date, |
||
| 58 | user.active, |
||
| 59 | access.login_date'; |
||
| 60 | |||
| 61 | if (api_is_multiple_url_enabled()) { |
||
| 62 | $access_url_rel_user_table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); |
||
| 63 | $current_url_id = api_get_current_access_url_id(); |
||
| 64 | |||
| 65 | $sql .= " FROM $user_table as user, $login_table as access, $access_url_rel_user_table as url |
||
| 66 | WHERE |
||
| 67 | access.login_date = (SELECT MAX(a.login_date) |
||
| 68 | FROM $login_table as a |
||
| 69 | WHERE a.login_user_id = user.user_id |
||
| 70 | ) AND |
||
| 71 | access.login_date <= '$ceiling' AND |
||
| 72 | user.user_id = access.login_user_id AND |
||
| 73 | url.user_id = user.user_id AND url.access_url_id=$current_url_id"; |
||
| 74 | } else { |
||
| 75 | $sql .= " FROM $user_table as user, $login_table as access |
||
| 76 | WHERE |
||
| 77 | access.login_date = (SELECT MAX(a.login_date) |
||
| 78 | FROM $login_table as a |
||
| 79 | WHERE a.login_user_id = user.user_id |
||
| 80 | ) AND |
||
| 81 | access.login_date <= '$ceiling' AND |
||
| 82 | user.user_id = access.login_user_id"; |
||
| 83 | } |
||
| 84 | |||
| 85 | if ($active_only) { |
||
| 86 | $sql .= ' AND user.active = 1'; |
||
| 87 | } |
||
| 88 | |||
| 89 | $sql .= " ORDER BY $column $direction"; |
||
| 90 | if (!is_null($from) && !is_null($count)) { |
||
| 91 | $count = intval($count); |
||
| 92 | $from = intval($from); |
||
| 93 | $sql .= " LIMIT $from, $count "; |
||
| 94 | } |
||
| 95 | |||
| 96 | $result = Database::query($sql); |
||
| 97 | |||
| 98 | return Database::store_result($result, 'ASSOC'); |
||
|
|
|||
| 99 | } |
||
| 114 |