Test Failed
Push — trunk ( 132e87...b3f953 )
by SuperNova.WS
11:54
created

db_user_list_admin_multiaccounts()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
/** @noinspection PhpDeprecationInspection */
3
/** @noinspection SqlResolve */
4
/** @noinspection PhpUnnecessaryCurlyVarSyntaxInspection */
5
6
use Player\PlayerStatic;
7
8
/**
9
 * Возвращает информацию о пользователе по его ID
10
 *
11
 * @param int   $user_id_unsafe  ID пользователя
12
 * @param bool  $for_update      @deprecated
13
 * @param ?bool $player          Признак выбора записи пользователь типа "игрок"
14
 *                               <p>null - Можно выбрать запись любого типа</p>
15
 *                               <p>true - Выбирается только запись типа "игрок"</p>
16
 *                               <p>false - Выбирается только запись типа "альянс"</p>
17
 *
18
 * @return array|false
19
 *    <p>false - Нет записи с указанным ID и $player</p>
20
 *    <p>array - запись типа $user</p>
21
 * @deprecated
22
 * @noinspection PhpUnusedParameterInspection
23
 */
24
function db_user_by_id($user_id_unsafe, $for_update = false, $player = null) {
25
  $user  = PlayerStatic::dbSelectOne("SELECT * FROM {{users}} WHERE `id` = " . idval($user_id_unsafe));
0 ignored issues
show
Deprecated Code introduced by
The function Player\PlayerStatic::dbSelectOne() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

25
  $user  = /** @scrutinizer ignore-deprecated */ PlayerStatic::dbSelectOne("SELECT * FROM {{users}} WHERE `id` = " . idval($user_id_unsafe));
Loading history...
26
27
  return (is_array($user) &&
28
    (
29
      $player === null
30
      ||
31
      ($player === true && !$user['user_as_ally'])
32
      ||
33
      ($player === false && $user['user_as_ally'])
34
    )) ? $user : false;
35
}
36
37
/**
38
 * @deprecated
39
 */
40
function db_user_by_username($username_unsafe, $like = false) {
41
  if (!($username_unsafe = trim($username_unsafe))) {
42
    return null;
43
  }
44
45
  // тут на самом деле strtolower() лишняя, но пусть будет
46
  $username_safe = SN::$db->db_escape($like ? strtolower($username_unsafe) : $username_unsafe);
47
48
  // Вытаскиваем запись
49
  $operand = $like ? 'LIKE' : '=';
50
51
   $user  = PlayerStatic::dbSelectOne("SELECT * FROM {{users}} WHERE `username` {$operand} '{$username_safe}'");
0 ignored issues
show
Deprecated Code introduced by
The function Player\PlayerStatic::dbSelectOne() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

51
   $user  = /** @scrutinizer ignore-deprecated */ PlayerStatic::dbSelectOne("SELECT * FROM {{users}} WHERE `username` {$operand} '{$username_safe}'");
Loading history...
52
53
  return $user;
54
}
55
56
/**
57
 * @param        $playerIdOrName
58
 * @param null   $player
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $player is correct as it would always require null to be passed?
Loading history...
59
 * @param bool   $like
60
 *
61
 * @return array|false
62
 * @deprecated
63
 */
64
function dbPlayerByIdOrName($playerIdOrName, $player = null, $like = false) {
65
  $row = db_user_by_id($playerIdOrName, false, $player);
0 ignored issues
show
Deprecated Code introduced by
The function db_user_by_id() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

65
  $row = /** @scrutinizer ignore-deprecated */ db_user_by_id($playerIdOrName, false, $player);
Loading history...
66
  if (empty($row['id'])) {
67
    $row = db_user_by_username($playerIdOrName, $like);
0 ignored issues
show
Deprecated Code introduced by
The function db_user_by_username() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

67
    $row = /** @scrutinizer ignore-deprecated */ db_user_by_username($playerIdOrName, $like);
Loading history...
68
  }
69
70
  return !is_array($row) || empty($row['id']) ? false : $row;
71
}
72
73
/**
74
 * @deprecated
75
 * @noinspection PhpUnusedParameterInspection
76
 */
77
function db_user_list($filter = '', $for_update = false, $fields = '*') {
78
  return SN::db_get_record_list(LOC_USER, $filter);
79
}
80
81
82
/**
83
 * @deprecated
84
 */
85
function db_user_set_by_id($user_id, $set) {
86
  return SN::db_upd_record_by_id(LOC_USER, $user_id, $set);
87
}
88
89
90
/**
91
 * @deprecated
92
 */
93
function db_user_list_set_mass_mail($owners_list, $set) {
94
  return SN::db_upd_record_list(LOC_USER, !empty($owners_list) ? '`id` IN (' . implode(',', $owners_list) . ');' : '', $set);
95
}
96
97
/**
98
 * @deprecated
99
 */
100
function db_user_list_set_by_ally_and_rank($ally_id, $ally_rank_id, $set) {
101
  return SN::db_upd_record_list(LOC_USER, "`ally_id`={$ally_id} AND `ally_rank_id` >= {$ally_rank_id}", $set);
102
}
103
104
/**
105
 * @deprecated
106
 */
107
function db_user_list_set_ally_deprecated_convert_ranks($ally_id, $i, $rank_id) {
108
  return SN::db_upd_record_list(LOC_USER, "`ally_id` = {$ally_id} AND `ally_rank_id`={$rank_id}", "`ally_rank_id` = {$i}");
109
}
110
111
112
function db_user_change_active_planet_to_capital($user_id, $captured_planet) {
113
  return doquery("UPDATE {{users}} SET `current_planet` = `id_planet` WHERE `id` = {$user_id} AND `current_planet` = {$captured_planet};");
0 ignored issues
show
Deprecated Code introduced by
The function doquery() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

113
  return /** @scrutinizer ignore-deprecated */ doquery("UPDATE {{users}} SET `current_planet` = `id_planet` WHERE `id` = {$user_id} AND `current_planet` = {$captured_planet};");
Loading history...
114
}
115
116
117
// TODO Внести это всё в supernova для HyperNova
118
/**
119
 * @return string
120
 * @deprecated
121
 * TODO - это вообще-то надо хранить в конфигурации
122
 */
123
function db_user_last_registered_username() {
124
  $user = PlayerStatic::dbSelectOne('SELECT * FROM `{{users}}` WHERE `user_as_ally` IS NULL ORDER BY `id` DESC');
0 ignored issues
show
Deprecated Code introduced by
The function Player\PlayerStatic::dbSelectOne() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

124
  $user = /** @scrutinizer ignore-deprecated */ PlayerStatic::dbSelectOne('SELECT * FROM `{{users}}` WHERE `user_as_ally` IS NULL ORDER BY `id` DESC');
Loading history...
125
126
  return isset($user['username']) ? $user['username'] : '';
127
}
128
129
function db_user_count($online = false) {
130
  $result = doquery('SELECT COUNT(`id`) AS user_count FROM `{{users}}` WHERE `user_as_ally` IS NULL AND `user_bot` = ' . USER_BOT_PLAYER . ($online ? ' AND onlinetime > ' . (SN_TIME_NOW - SN::$config->game_users_online_timeout) : ''), true);
0 ignored issues
show
Bug introduced by
true of type true is incompatible with the type string expected by parameter $table of doquery(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

130
  $result = doquery('SELECT COUNT(`id`) AS user_count FROM `{{users}}` WHERE `user_as_ally` IS NULL AND `user_bot` = ' . USER_BOT_PLAYER . ($online ? ' AND onlinetime > ' . (SN_TIME_NOW - SN::$config->game_users_online_timeout) : ''), /** @scrutinizer ignore-type */ true);
Loading history...
Deprecated Code introduced by
The function doquery() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

130
  $result = /** @scrutinizer ignore-deprecated */ doquery('SELECT COUNT(`id`) AS user_count FROM `{{users}}` WHERE `user_as_ally` IS NULL AND `user_bot` = ' . USER_BOT_PLAYER . ($online ? ' AND onlinetime > ' . (SN_TIME_NOW - SN::$config->game_users_online_timeout) : ''), true);
Loading history...
131
132
  return isset($result['user_count']) ? $result['user_count'] : 0;
133
}
134
135
function db_user_list_to_celebrate($config_user_birthday_range) {
136
  // TODO
137
  /** @noinspection SqlAggregates */
138
  return doquery(
0 ignored issues
show
Deprecated Code introduced by
The function doquery() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

138
  return /** @scrutinizer ignore-deprecated */ doquery(
Loading history...
139
    "SELECT
140
      `id`, `username`, `user_birthday`, `user_birthday_celebrated`
141
      , CONCAT(YEAR(CURRENT_DATE), DATE_FORMAT(`user_birthday`, '-%m-%d')) AS `current_birthday`
142
      , DATEDIFF(CURRENT_DATE, CONCAT(YEAR(CURRENT_DATE), DATE_FORMAT(`user_birthday`, '-%m-%d'))) AS `days_after_birthday`
143
    FROM
144
      `{{users}}`
145
    WHERE
146
      `user_birthday` IS NOT NULL
147
      AND (`user_birthday_celebrated` IS NULL OR DATE_ADD(`user_birthday_celebrated`, INTERVAL 1 YEAR) < CURRENT_DATE)
148
      AND `user_as_ally` IS NULL
149
    HAVING
150
      `days_after_birthday` >= 0 AND `days_after_birthday` < {$config_user_birthday_range} FOR UPDATE;");
151
}
152
153
//function db_user_list_online_sorted($TypeSort) {
154
//  global $config;
155
//
156
//  return doquery(
157
//    "SELECT `id` AS `ID`, `username` AS `NAME`, `ally_name` AS `ALLY`, `total_points` AS `STAT_POINTS`,
158
//      `onlinetime` AS `ACTIVITY`
159
//    FROM `{{users}}`
160
//    WHERE `onlinetime` >= " . (SN_TIME_NOW - $config->game_users_online_timeout) . " ORDER BY user_as_ally, `" . $TypeSort . "`;");
161
//}
162
163
164
function db_user_list_admin_multi_accounts() {
165
  return doquery("SELECT COUNT(*) as ip_count, `user_lastip` FROM `{{users}}` WHERE user_as_ally IS NULL GROUP BY user_lastip HAVING COUNT(*) > 1;");
0 ignored issues
show
Deprecated Code introduced by
The function doquery() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

165
  return /** @scrutinizer ignore-deprecated */ doquery("SELECT COUNT(*) as ip_count, `user_lastip` FROM `{{users}}` WHERE user_as_ally IS NULL GROUP BY user_lastip HAVING COUNT(*) > 1;");
Loading history...
166
}
167
168
169
function db_user_list_admin_sorted($sort, $online = false) {
170
  global $config;
171
172
  return doquery("SELECT u.*, COUNT(r.id) AS referral_count, SUM(r.dark_matter) AS referral_dm FROM {{users}} as u
0 ignored issues
show
Deprecated Code introduced by
The function doquery() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

172
  return /** @scrutinizer ignore-deprecated */ doquery("SELECT u.*, COUNT(r.id) AS referral_count, SUM(r.dark_matter) AS referral_dm FROM {{users}} as u
Loading history...
173
    LEFT JOIN {{referrals}} as r on r.id_partner = u.id
174
    WHERE" .
175
    ($online ? " `onlinetime` >= " . (SN_TIME_NOW - $config->game_users_online_timeout) : ' user_as_ally IS NULL') .
176
    " GROUP BY u.id
177
    ORDER BY user_as_ally, {$sort}");
178
}
179
180
/**
181
 * Выбирает записи игроков по списку их ID
182
 *
183
 * @param $user_id_list
184
 *
185
 * @return array
186
 */
187
function db_user_list_by_id($user_id_list) {
188
  if (!is_array($user_id_list)) {
189
    $user_id_list = array($user_id_list);
190
  }
191
192
  $user_list = array();
193
  foreach ($user_id_list as $user_id_unsafe) {
194
    if (!empty($user = db_user_by_id($user_id_unsafe))) {
0 ignored issues
show
Deprecated Code introduced by
The function db_user_by_id() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

194
    if (!empty($user = /** @scrutinizer ignore-deprecated */ db_user_by_id($user_id_unsafe))) {
Loading history...
195
      $user_list[$user_id_unsafe] = $user;
196
    }
197
  }
198
199
  return $user_list;
200
}
201