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