Conditions | 10 |
Paths | 256 |
Total Lines | 84 |
Code Lines | 39 |
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 |
||
33 | public static function listZombies( |
||
34 | $ceiling, |
||
35 | $active_only = true, |
||
36 | $from = 0, |
||
37 | $count = 10, |
||
38 | $column = 'user.firstname', |
||
39 | $direction = 'desc' |
||
40 | ) { |
||
41 | $column = str_replace('user.', '', $column); |
||
42 | if (empty($column)) { |
||
43 | $column = 'firstname'; |
||
44 | } |
||
45 | |||
46 | $validColumns = ['id', 'official_code', 'firstname', 'lastname', 'username', 'email', 'status', 'created_at', 'active', 'login_date']; |
||
47 | if (!in_array($column, $validColumns)) { |
||
48 | $column = 'firstname'; |
||
49 | } |
||
50 | $ceiling = is_numeric($ceiling) ? (int) $ceiling : strtotime($ceiling); |
||
51 | $ceiling = date('Y-m-d H:i:s', $ceiling); |
||
52 | |||
53 | $user_table = Database::get_main_table(TABLE_MAIN_USER); |
||
54 | $login_table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN); |
||
55 | |||
56 | $accessUrlHelper = Container::getAccessUrlHelper(); |
||
57 | $accessUrl = $accessUrlHelper->getCurrent(); |
||
58 | |||
59 | $sql = 'SELECT |
||
60 | user.id, |
||
61 | user.official_code, |
||
62 | user.firstname, |
||
63 | user.lastname, |
||
64 | user.username, |
||
65 | user.email, |
||
66 | user.status, |
||
67 | user.created_at, |
||
68 | user.active, |
||
69 | access.login_date'; |
||
70 | |||
71 | if ($accessUrlHelper->isMultiple()) { |
||
72 | $access_url_rel_user_table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); |
||
73 | $current_url_id = $accessUrl->getId(); |
||
74 | |||
75 | $sql .= " FROM $user_table as user, $login_table as access, $access_url_rel_user_table as url |
||
76 | WHERE |
||
77 | access.login_date = (SELECT MAX(a.login_date) |
||
78 | FROM $login_table as a |
||
79 | WHERE a.login_user_id = user.id |
||
80 | ) AND |
||
81 | access.login_date <= '$ceiling' AND |
||
82 | user.id = access.login_user_id AND |
||
83 | url.user_id = user.id AND url.access_url_id=$current_url_id"; |
||
84 | } else { |
||
85 | $sql .= " FROM $user_table as user, $login_table as access |
||
86 | WHERE |
||
87 | access.login_date = (SELECT MAX(a.login_date) |
||
88 | FROM $login_table as a |
||
89 | WHERE a.login_user_id = user.id |
||
90 | ) AND |
||
91 | access.login_date <= '$ceiling' AND |
||
92 | user.id = access.login_user_id"; |
||
93 | } |
||
94 | |||
95 | if ($active_only) { |
||
96 | $sql .= ' AND user.active = 1'; |
||
97 | } |
||
98 | |||
99 | $sql .= !str_contains($sql, 'WHERE') ? ' WHERE user.active <> '.USER_SOFT_DELETED : ' AND user.active <> '.USER_SOFT_DELETED; |
||
100 | $column = str_replace('user.', '', $column); |
||
101 | $sql .= " ORDER BY `$column` $direction"; |
||
102 | if (!is_null($from) && !is_null($count)) { |
||
103 | $count = (int) $count; |
||
104 | $from = (int) $from; |
||
105 | $sql .= " LIMIT $from, $count "; |
||
106 | } |
||
107 | |||
108 | $result = Database::query($sql); |
||
109 | |||
110 | if (Database::num_rows($result) === 0) { |
||
111 | return []; |
||
112 | } |
||
113 | $userInfo = Database::store_result($result, 'ASSOC'); |
||
114 | $userInfo['auth_sources'] = api_get_user_entity($userInfo['id'])->getAuthSourcesAuthentications($accessUrl); |
||
115 | |||
116 | return $userInfo; |
||
117 | } |
||
132 |