Completed
Push — work-fleets ( 04acf9...8f8df9 )
by SuperNova.WS
07:02
created

db_queries.php ➔ db_ban_insert_unset()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 3
dl 14
loc 14
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
require_once('db_helpers.php');
4
5
function db_planet_list_admin_list($table_parent_columns, $planet_active, $active_time, $planet_type) {
6
  return classSupernova::$db->doSelect(
7
    "SELECT p.*, u.username" . ($table_parent_columns ? ', p1.name AS parent_name' : '') .
8
    " FROM {{planets}} AS p
9
      LEFT JOIN {{users}} AS u ON u.id = p.id_owner" .
10
    ($table_parent_columns ? ' LEFT JOIN {{planets}} AS p1 ON p1.id = p.parent_planet' : '') .
11
    " WHERE " . ($planet_active ? "p.last_update >= {$active_time}" : "p.planet_type = {$planet_type}"));
12
}
13
14
function db_planet_list_search($searchtext) {
15
  return classSupernova::$db->doSelect(
16
    "SELECT
17
      p.galaxy, p.system, p.planet, p.planet_type, p.name as planet_name,
18
      u.id as uid, u.username, u.ally_id, u.id_planet,
19
      u.total_points, u.total_rank,
20
      u.ally_tag, u.ally_name
21
    FROM
22
      {{planets}} AS p
23
      LEFT JOIN {{users}} AS u ON u.id = p.id_owner
24
    WHERE
25
      name LIKE '%{$searchtext}%' AND u.user_as_ally IS NULL
26
    ORDER BY
27
      ally_tag, username, planet_name
28
    LIMIT 30;"
29
  );
30
}
31
32
33
function db_user_list_search($searchtext) {
34
  return classSupernova::$db->doSelect(
35
    "SELECT
36
      pn.player_name, u.id as uid, u.username, u.ally_id, u.id_planet, u.total_points, u.total_rank,
37
      p.galaxy, p.system, p.planet, p.planet_type, p.name as planet_name,
38
      u.ally_tag, u.ally_name
39
    FROM
40
      {{player_name_history}} AS pn
41
      JOIN {{users}} AS u ON u.id = pn.player_id
42
      LEFT JOIN {{planets}} AS p ON p.id_owner = u.id AND p.id=u.id_planet
43
    WHERE
44
      player_name LIKE '%{$searchtext}%' AND u.user_as_ally IS NULL
45
    ORDER BY
46
      ally_tag, username, planet_name
47
    LIMIT 30;"
48
  );
49
}
50
51
52
function db_unit_records_sum($unit_id, $user_skip_list_unit) {
53
  return classSupernova::$db->doSelectFetch(
54
    "SELECT unit_player_id, username, sum(unit_level) as unit_level
55
          FROM {{unit}} JOIN {{users}} AS u ON u.id = unit_player_id
56
          WHERE unit_player_id != 0 AND unit_snid = {$unit_id} {$user_skip_list_unit}
57
          GROUP BY unit_player_id
58
          ORDER BY sum(unit_level) DESC, unit_player_id
59
          LIMIT 1;");
60
}
61
62
function db_unit_records_plain($unit_id, $user_skip_list_unit) {
63
  return classSupernova::$db->doSelectFetch(
64
    "SELECT unit_player_id, username, unit_level
65
          FROM {{unit}} JOIN {{users}} AS u ON u.id = unit_player_id
66
          WHERE unit_player_id != 0 AND unit_snid = {$unit_id} {$user_skip_list_unit}
67
          ORDER BY unit_level DESC, unit_id
68
          LIMIT 1;");
69
}
70
71
function db_stat_list_statistic($who, $is_common_stat, $Rank, $start, $source = false) {
72
// pdump($source);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
73
  if (!$source) {
74
    $source = array(
75
      'statpoints' => 'statpoints',
76
      'users'      => 'users',
77
      'id'         => 'id',
78
      'username'   => 'username',
79
80
      'alliance' => 'alliance',
81
82
    );
83
  } else {
84
    $source = array(
85
      'statpoints' => 'blitz_statpoints',
86
      'users'      => 'blitz_registrations',
87
      'id'         => 'blitz_player_id',
88
      'username'   => 'blitz_name',
89
90
      'alliance' => 'blitz_alliance', // TODO
91
    );
92
  }
93
// pdump($source);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
94
  if ($who == 1) {
95
    if ($is_common_stat) { // , UNIX_TIMESTAMP(CONCAT(YEAR(CURRENT_DATE), DATE_FORMAT(`user_birthday`, '-%m-%d'))) AS `nearest_birthday`
0 ignored issues
show
Unused Code Comprehensibility introduced by
57% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
96
      $query_str =
97
        "SELECT
98
      @rownum:=@rownum+1 rownum, subject.{$source['id']} as `id`, sp.{$Rank}_rank as rank, sp.{$Rank}_old_rank as rank_old, sp.{$Rank}_points as points, subject.{$source['username']} as `name`, subject.*
99
    FROM
100
      (SELECT @rownum:={$start}) r,
101
      {{{$source['statpoints']}}} as sp
102
      LEFT JOIN {{{$source['users']}}} AS subject ON subject.{$source['id']} = sp.id_owner
103
      LEFT JOIN {{{$source['statpoints']}}} AS sp_old ON sp_old.id_owner = subject.{$source['id']} AND sp_old.`stat_type` = 1 AND sp_old.`stat_code` = 2
104
    WHERE
105
      sp.`stat_type` = 1 AND sp.`stat_code` = 1
106
    ORDER BY
107
      sp.`{$Rank}_rank`, subject.{$source['id']}
108
    LIMIT
109
      " . $start . ",100;";
110 View Code Duplication
    } else { // , UNIX_TIMESTAMP(CONCAT(YEAR(CURRENT_DATE), DATE_FORMAT(`user_birthday`, '-%m-%d'))) AS `nearest_birthday`
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Unused Code Comprehensibility introduced by
57% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
111
      $query_str =
112
        "SELECT
113
      @rownum:=@rownum+1 AS rank, subject.{$source['id']} as `id`, @rownum as rank_old, subject.{$Rank} as points, subject.{$source['username']} as name, subject.*
114
    FROM
115
      (SELECT @rownum:={$start}) r,
116
      {{{$source['users']}}} AS subject
117
    WHERE
118
      subject.user_as_ally is null
119
    ORDER BY
120
      subject.{$Rank} DESC, subject.{$source['id']}
121
    LIMIT
122
      " . $start . ",100;";
123
    }
124 View Code Duplication
  } else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
125
    // TODO
126
    $query_str =
127
      "SELECT
128
    @rownum:=@rownum+1 as rownum, subject.id as `id`, sp.{$Rank}_rank as rank, sp.{$Rank}_old_rank as rank_old, sp.{$Rank}_points as points, subject.ally_name as name, subject.ally_tag, subject.ally_members
129
  FROM
130
    (SELECT @rownum:={$start}) r,
131
    {{{$source['statpoints']}}} AS sp
132
    LEFT JOIN {{{$source['alliance']}}} AS subject ON subject.id = sp.id_ally
133
    LEFT JOIN {{{$source['statpoints']}}} AS sp_old ON sp_old.id_ally = subject.id AND sp_old.`stat_type` = 2 AND sp_old.`stat_code` = 2
134
  WHERE
135
    sp.`stat_type` = 2 AND sp.`stat_code` = 1
136
  ORDER BY
137
    sp.`{$Rank}_rank`, subject.id
138
  LIMIT
139
    " . $start . ",100;";
140
  }
141
142
  return classSupernova::$db->doSelect($query_str);
143
}
144
145
146
function db_stat_list_update_user_stats() {
147
  return classSupernova::$db->doUpdate("UPDATE `{{users}}` AS u JOIN `{{statpoints}}` AS sp ON sp.id_owner = u.id AND sp.stat_code = 1 AND sp.stat_type = 1 SET u.total_rank = sp.total_rank, u.total_points = sp.total_points WHERE user_as_ally IS NULL;");
148
}
149
150
function db_stat_list_update_ally_stats() {
151
  return classSupernova::$db->doUpdate("UPDATE `{{alliance}}` AS a JOIN `{{statpoints}}` AS sp ON sp.id_ally = a.id AND sp.stat_code = 1 AND sp.stat_type = 2 SET a.total_rank = sp.total_rank, a.total_points = sp.total_points;");
152
}
153
154
function db_stat_list_delete_ally_player() {
155
  return classSupernova::$db->doDeleteComplex("DELETE s FROM `{{statpoints}}` AS s JOIN `{{users}}` AS u ON u.id = s.id_owner WHERE s.id_ally IS NULL AND u.user_as_ally IS NOT NULL");
156
}
157
158
159
function db_referrals_list_by_id($user_id) {
160
  return classSupernova::$db->doSelect("SELECT r.*, u.username, u.register_time FROM {{referrals}} AS r LEFT JOIN {{users}} AS u ON u.id = r.id WHERE id_partner = {$user_id}");
161
}
162
163
164
/**
165
 * Хелпер для работы с простыми хэш-таблицами в БД
166
 *
167
 * @param string $current_value_unsafe
168
 * @param string $db_id_field_name
169
 * @param string $db_table_name
170
 * @param string $db_value_field_name
171
 *
172
 * @return int
173
 */
174
// OK v4
175
// TODO - вынести в отдельный класс
176
function db_get_set_unique_id_value($current_value_unsafe, $db_id_field_name, $db_table_name, $db_value_field_name) {
177
  $current_value_safe = db_escape($current_value_unsafe);
178
  $value_id = classSupernova::$db->doSelectFetch("SELECT `{$db_id_field_name}` FROM {{{$db_table_name}}} WHERE `{$db_value_field_name}` = '{$current_value_safe}' LIMIT 1 FOR UPDATE");
179
  if (empty($value_id[$db_id_field_name])) {
180
    classSupernova::$db->doInsertSet($db_table_name, array(
181
      $db_value_field_name => $current_value_unsafe,
182
    ));
183
184
    $variable_id = classSupernova::$db->db_insert_id();
185
  } else {
186
    $variable_id = $value_id[$db_id_field_name];
187
  }
188
189
  return $variable_id;
190
}
191
192
/**
193
 * Функция проверяет наличие имени игрока в базе
194
 *
195
 * @param $player_name_unsafe
196
 *
197
 * @return bool
198
 */
199
function db_player_name_exists($player_name_unsafe) {
200
  sn_db_transaction_check(true);
201
202
  $player_name_safe = classSupernova::$db->db_escape($player_name_unsafe);
203
204
  $player_name_exists = classSupernova::$db->doSelectFetch(
205
    "SELECT * 
206
    FROM `{{player_name_history}}` 
207
    WHERE `player_name` = '{$player_name_safe}' 
208
    LIMIT 1 
209
    FOR UPDATE"
210
  );
211
212
  return !empty($player_name_exists);
213
}
214
215
/**
216
 * @param        $userId
217
 * @param string $username_unsafe
218
 */
219
function db_player_name_history_replace($userId, $username_unsafe) {
220
  classSupernova::$gc->db->doReplaceSet('player_name_history', array(
0 ignored issues
show
Bug introduced by
The method doReplaceSet does only exist in db_mysql, but not in Closure.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
221
    'player_id'   => $userId,
222
    'player_name' => $username_unsafe,
223
  ));
224
}
225
226
227
/**
228
 * @param $username_safe
229
 *
230
 * @return array|bool|mysqli_result|null
231
 */
232
function db_player_name_history_get_name_by_name($username_safe) {
233
  $name_check = classSupernova::$db->doSelectFetch("SELECT * FROM {{player_name_history}} WHERE `player_name` LIKE \"{$username_safe}\" LIMIT 1 FOR UPDATE;");
234
235
  return $name_check;
236
}
237
238
239
// BANNED *************************************************************************************************************
240
function db_banned_list_select() {
241
  return classSupernova::$db->doSelect("SELECT * FROM `{{banned}}` ORDER BY `ban_id` DESC;");
242
}
243
244
/**
245
 * @param $user_row
246
 *
247
 * @return array|bool|mysqli_result|null
248
 */
249
function db_ban_list_get_details($user_row) {
250
  $ban_details = classSupernova::$db->doSelectFetch("SELECT * FROM {{banned}} WHERE `ban_user_id` = {$user_row['id']} ORDER BY ban_id DESC LIMIT 1");
251
252
  return $ban_details;
253
}
254
255
256
// BLITZ ***************************************************************************************************************
257
function db_blitz_reg_insert($userId, $current_round) {
258
  classSupernova::$db->doInsertSet(TABLE_BLITZ_REGISTRATIONS, array(
259
    'user_id'      => $userId,
260
    'round_number' => $current_round,
261
  ), DB_INSERT_IGNORE);
262
}
263
264
function db_blitz_reg_get_id_by_player_and_round($user, $current_round) {
265
  return classSupernova::$db->doSelectFetch("SELECT `id` FROM `{{blitz_registrations}}` WHERE `user_id` = {$user['id']} AND `round_number` = {$current_round} FOR UPDATE;");
266
}
267
268
function db_blitz_reg_count($current_round) {
269
  return classSupernova::$db->doSelectFetch("SELECT count(`id`) AS `count` FROM {{blitz_registrations}} WHERE `round_number` = {$current_round};");
270
}
271
272
function db_blitz_reg_get_random_id($current_round) {
273
  return classSupernova::$db->doSelect("SELECT `id` FROM {{blitz_registrations}} WHERE `round_number` = {$current_round} ORDER BY RAND();");
274
}
275
276
function db_blitz_reg_get_player_list($current_round) {
277
  return classSupernova::$db->doSelect("SELECT blitz_name, blitz_password, blitz_online FROM {{blitz_registrations}} WHERE `round_number` = {$current_round} ORDER BY `id`;");
278
}
279
280
function db_blitz_reg_get_player_list_order_by_place($current_round) {
281
  return classSupernova::$db->doSelect("SELECT * FROM {{blitz_registrations}} WHERE `round_number` = {$current_round} ORDER BY `blitz_place` FOR UPDATE;");
282
}
283
284
function db_blitz_reg_get_player_list_and_users($current_round) {
285
  return classSupernova::$db->doSelect(
286
    "SELECT u.*, br.blitz_name, br.blitz_password, br.blitz_place, br.blitz_status, br.blitz_points, br.blitz_reward_dark_matter
287
    FROM {{blitz_registrations}} AS br
288
    JOIN {{users}} AS u ON u.id = br.user_id
289
  WHERE br.`round_number` = {$current_round}
290
  order by `blitz_place`, `timestamp`;");
291
}
292
293
function db_blitz_reg_update_with_name_and_password($blitz_name, $blitz_password, $row, $current_round) {
294
  classSupernova::$db->doUpdate("UPDATE {{blitz_registrations}} SET blitz_name = '{$blitz_name}', blitz_password = '{$blitz_password}' WHERE `id` = {$row['id']} AND `round_number` = {$current_round};");
295
}
296
297
function db_blitz_reg_update_apply_results($reward, $row, $current_round) {
298
  classSupernova::$db->doUpdate("UPDATE {{blitz_registrations}} SET blitz_reward_dark_matter = blitz_reward_dark_matter + ($reward) WHERE id = {$row['id']} AND `round_number` = {$current_round};");
299
}
300
301
function db_blitz_reg_update_results($blitz_result_data, $current_round) {
302
  classSupernova::$db->doUpdate(
303
    "UPDATE `{{blitz_registrations}}` SET
304
            `blitz_player_id` = '{$blitz_result_data[0]}',
305
            `blitz_online` = '{$blitz_result_data[2]}',
306
            `blitz_place` = '{$blitz_result_data[3]}',
307
            `blitz_points` = '{$blitz_result_data[4]}'
308
          WHERE `blitz_name` = '{$blitz_result_data[1]}' AND `round_number` = {$current_round};");
309
}
310
311
function db_blitz_reg_delete($userId, $current_round) {
312
  classSupernova::$gc->db->doDeleteWhere(TABLE_BLITZ_REGISTRATIONS, array('user_id' => $userId, 'round_number' => $current_round));
0 ignored issues
show
Bug introduced by
The method doDeleteWhere does only exist in db_mysql, but not in Closure.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
313
}
314
315
316
// Universe *************************************************************************************************************
317
function db_universe_get_name($uni_galaxy, $uni_system = 0) {
318
  $db_row = classSupernova::$db->doSelectFetch("select `universe_name` from `{{universe}}` where `universe_galaxy` = {$uni_galaxy} and `universe_system` = {$uni_system} limit 1;");
319
320
  return $db_row['universe_name'];
321
}
322
323
/**
324
 * @param $uni_galaxy
325
 * @param $uni_system
326
 *
327
 * @return array|bool|mysqli_result|null
328
 */
329
function db_universe_get($uni_galaxy, $uni_system) {
330
  $uni_row = classSupernova::$db->doSelectFetch("select * from `{{universe}}` where `universe_galaxy` = {$uni_galaxy} and `universe_system` = {$uni_system} limit 1;");
331
332
  return $uni_row;
333
}
334
335
/**
336
 * @param $uni_galaxy
337
 * @param $uni_system
338
 * @param $uni_row
339
 */
340
function db_universe_rename($uni_galaxy, $uni_system, $uni_row) {
341
  classSupernova::$db->doReplaceSet('universe', array(
342
    'universe_galaxy' => $uni_galaxy,
343
    'universe_system' => $uni_system,
344
    'universe_name' => $uni_row['universe_name'],
345
    'universe_price' => $uni_row['universe_price'],
346
  ));
347
348
}
349
350
351
// Payment *************************************************************************************************************
352
353
function db_payment_get($payment_id) {
354
  return classSupernova::$db->doSelectFetch("SELECT * FROM {{payment}} WHERE `payment_id` = {$payment_id} LIMIT 1;");
355
}
356
357
/**
358
 * @param $flt_payer
359
 * @param $flt_status
360
 * @param $flt_test
361
 * @param $flt_module
362
 *
363
 * @return array|bool|mysqli_result|null
364
 */
365
function db_payment_list_get($flt_payer, $flt_status, $flt_test, $flt_module) {
366
  $extra_conditions =
367
    ($flt_payer > 0 ? "AND payment_user_id = {$flt_payer} " : '') .
368
    ($flt_status >= 0 ? "AND payment_status = {$flt_status} " : '') .
369
    ($flt_test >= 0 ? "AND payment_test = {$flt_test} " : '') .
370
    ($flt_module ? "AND payment_module_name = '{$flt_module}' " : '');
371
  $query = classSupernova::$db->doSelect("SELECT * FROM `{{payment}}` WHERE 1 {$extra_conditions} ORDER BY payment_id DESC;");
372
373
  return $query;
374
}
375
376
/**
377
 * @return array|bool|mysqli_result|null
378
 */
379
function db_payment_list_payers() {
380
  $query = classSupernova::$db->doSelect("SELECT payment_user_id, payment_user_name FROM `{{payment}}` GROUP BY payment_user_id ORDER BY payment_user_name");
381
382
  return $query;
383
}
384
385
/**
386
 * @return array|bool|mysqli_result|null
387
 */
388
function db_payment_list_modules() {
389
  $query = classSupernova::$db->doSelect("SELECT DISTINCT payment_module_name FROM `{{payment}}` ORDER BY payment_module_name");
390
391
  return $query;
392
}
393
394
395
// Log Online *************************************************************************************************************
396
function db_log_online_insert() {
397
  classSupernova::$db->doInsertSet(LOG_USERS_ONLINE, array(
398
    'online_count' => (int)classSupernova::$config->var_online_user_count,
0 ignored issues
show
Documentation introduced by
The property var_online_user_count does not exist on object<classConfig>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
399
  ), DB_INSERT_IGNORE);
400
}
401
402
// Log *************************************************************************************************************
403
404
/**
405
 * @return array|bool|mysqli_result|null
406
 */
407
function db_log_list_get_last_100() {
408
  $query = classSupernova::$db->doSelect("SELECT * FROM `{{logs}}` ORDER BY log_id DESC LIMIT 100;");
409
410
  return $query;
411
}
412
413
/**
414
 * @param $delete
415
 */
416
function db_log_delete_by_id($delete) {
417
  classSupernova::$gc->db->doDeleteRowWhere(TABLE_LOGS, array('log_id' => $delete));
0 ignored issues
show
Bug introduced by
The method doDeleteRowWhere does only exist in db_mysql, but not in Closure.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
418
}
419
420
function db_log_delete_update_and_stat_calc() {
421
  classSupernova::$db->doDeleteComplex("DELETE FROM `{{logs}}` WHERE `log_code` IN (103, 180, 191);");
422
}
423
424
/**
425
 * @param $detail
426
 *
427
 * @return array|bool|mysqli_result|null
428
 */
429
function db_log_get_by_id($detail) {
430
  $errorInfo = classSupernova::$db->doSelectFetch("SELECT * FROM `{{logs}}` WHERE `log_id` = {$detail} LIMIT 1;");
431
432
  return $errorInfo;
433
}
434
435
/**
436
 * @param $i
437
 *
438
 * @return array|bool|mysqli_result|null
439
 */
440
function db_log_count($i) {
441
  $query = classSupernova::$db->doSelectFetch("SELECT COUNT(*) AS LOG_MESSAGES_TOTAL, {$i} AS LOG_MESSAGES_VISIBLE FROM `{{logs}}`;");
442
443
  return $query;
444
}
445
446
// SYSTEM QUERIES - MOVE TO DB *****************************************************************************************
447
/**
448
 * @return array|bool|mysqli_result|null
449
 */
450
function db_core_show_status() {
451
  $result = classSupernova::$db->doExecute('SHOW STATUS;');
452
453
  return $result;
454
}
455
456
/**
457
 * @return array|bool|mysqli_result|null
458
 */
459
function db_counter_list_by_week() {
460
  $query = classSupernova::$db->doSelect("SELECT `visit_time`, user_id FROM `{{counter}}` WHERE user_id <> 0 AND visit_time > UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 7 DAY)) ORDER BY user_id, visit_time;");
461
462
  return $query;
463
}
464
465
/**
466
 * @param $user_last_browser_id
467
 *
468
 * @return array|bool|mysqli_result|null
469
 */
470
function db_browser_agent_get_by_id($user_last_browser_id) {
471
  $temp = classSupernova::$db->doSelectFetch("SELECT browser_user_agent FROM {{security_browser}} WHERE `browser_id` = {$user_last_browser_id}");
472
473
  return $temp['browser_user_agent'];
474
}
475
476
477
/**
478
 * @param $user_id
479
 * @param $change_type
480
 * @param $dark_matter
481
 * @param $comment_unsafe
482
 * @param $rowUserNameUnsafe
483
 * @param $page_url_unsafe
484
 */
485
function db_log_dark_matter_insert($user_id, $change_type, $dark_matter, $comment_unsafe, $rowUserNameUnsafe, $page_url_unsafe) {
486
  return classSupernova::$db->doInsertSet(TABLE_LOG_DARK_MATTER, array(
487
    'log_dark_matter_username' => $rowUserNameUnsafe,
488
    'log_dark_matter_reason'   => (int)$change_type,
489
    'log_dark_matter_amount'   => (float)$dark_matter,
490
    'log_dark_matter_comment'  => (string)$comment_unsafe,
491
    'log_dark_matter_page'     => (string)$page_url_unsafe,
492
    'log_dark_matter_sender'   => $user_id,
493
  ));
494
}
495
496
// REFERRALS ***********************************************************************************************************
497
/**
498
 * @param $user_id_safe
499
 *
500
 * @return array|bool|mysqli_result|null
501
 */
502
function db_referral_get_by_id($user_id_safe) {
503
  $old_referral = classSupernova::$db->doSelectFetch("SELECT * FROM {{referrals}} WHERE `id` = {$user_id_safe} LIMIT 1 FOR UPDATE;");
504
505
  return $old_referral;
506
}
507
508
/**
509
 * @param $user_id_safe
510
 * @param $dark_matter
511
 */
512
function db_referral_update_dm($user_id_safe, $dark_matter) {
513
  classSupernova::$db->doUpdate("UPDATE {{referrals}} SET dark_matter = dark_matter + '{$dark_matter}' WHERE `id` = {$user_id_safe} LIMIT 1;");
514
}
515
516
517
/**
518
 * @param $partnerId
519
 * @param $userId
520
 */
521
function db_referral_insert($partnerId, $userId) {
522
  classSupernova::$db->doInsertSet(TABLE_REFERRALS, array(
523
    'id'         => $userId,
524
    'id_partner' => $partnerId,
525
  ));
526
}
527
528
529
// Quests ***********************************************************************************************************
530
/**
531
 * @param $query_add_select
532
 * @param $query_add_from
533
 * @param $query_add_where
534
 *
535
 * @return array|bool|mysqli_result|null
536
 */
537
function db_quest_list_get($query_add_select, $query_add_from, $query_add_where) {
538
  $query = classSupernova::$db->doSelect(
539
    "SELECT q.* {$query_add_select}
540
      FROM {{quest}} AS q {$query_add_from}
541
      WHERE 1 {$query_add_where}
542
    ;"
543
  );
544
545
  return $query;
546
}
547
548
549
/**
550
 * @return array|bool|mysqli_result|null
551
 */
552
function db_quest_count() {
553
  $query = classSupernova::$db->doSelectFetch("SELECT count(*) AS count FROM `{{quest}}`;");
554
555
  return $query;
556
}
557
558
/**
559
 * @param $quest_id
560
 *
561
 * @return array|bool|mysqli_result|null
562
 */
563
function db_quest_get($quest_id) {
564
  $quest = classSupernova::$db->doSelectFetch("SELECT * FROM {{quest}} WHERE `quest_id` = {$quest_id} LIMIT 1;");
565
566
  return $quest;
567
}
568
569
/**
570
 * @param $quest_id
571
 */
572
function db_quest_delete($quest_id) {
573
  classSupernova::$gc->db->doDeleteRowWhere(TABLE_QUEST, array('quest_id' => $quest_id));
0 ignored issues
show
Bug introduced by
The method doDeleteRowWhere does only exist in db_mysql, but not in Closure.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
574
}
575
576
/**
577
 * @param $quest_name
578
 * @param $quest_type
579
 * @param $quest_description
580
 * @param $quest_conditions
581
 * @param $quest_rewards
582
 * @param $quest_id
583
 */
584
function db_quest_update($quest_name, $quest_type, $quest_description, $quest_conditions, $quest_rewards, $quest_id) {
585
  classSupernova::$db->doUpdate(
586
    "UPDATE {{quest}} SET
587
              `quest_name` = '{$quest_name}',
588
              `quest_type` = '{$quest_type}',
589
              `quest_description` = '{$quest_description}',
590
              `quest_conditions` = '$quest_conditions',
591
              `quest_rewards` = '{$quest_rewards}'
592
            WHERE `quest_id` = {$quest_id} LIMIT 1;"
593
  );
594
}
595
596
/**
597
 * @param $user_id
598
 *
599
 * @return array|bool|mysqli_result|null
600
 */
601
function db_stat_get_by_user($user_id) {
602
  $StatRecord = classSupernova::$db->doSelectFetch("SELECT * FROM {{statpoints}} WHERE `stat_type` = 1 AND `stat_code` = 1 AND `id_owner` = {$user_id};");
603
604
  return $StatRecord;
605
}
606
607
/**
608
 * @param $user_id
609
 *
610
 * @return array|bool|mysqli_result|null
611
 */
612
function db_stat_get_by_user2($user_id) {
613
  $query = classSupernova::$db->doSelect("SELECT * FROM {{statpoints}} WHERE `stat_type` = 1 AND `id_owner` = {$user_id} ORDER BY `stat_code` DESC;");
614
615
  return $query;
616
}
617
618
/**
619
 * @param $options
620
 *
621
 * @return array|bool|mysqli_result|null
622
 */
623
function db_payment_get_something($options) {
624
  $payment = classSupernova::$db->doSelectFetch("SELECT * FROM {{payment}} WHERE `payment_module_name` = '{$this->manifest['name']}' AND `payment_external_id` = '{$options['payment_external_id']}' LIMIT 1 FOR UPDATE;");
0 ignored issues
show
Bug introduced by
The variable $this does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
625
626
  return $payment;
627
}
628
629
/**
630
 * @param $payment_external_id
631
 *
632
 * @return array|bool|mysqli_result|null
633
 */
634
function db_payment_get_something2($payment_external_id) {
635
  $payment = classSupernova::$db->doSelectFetch("SELECT * FROM {{payment}} WHERE `payment_module_name` = '{$this->manifest['name']}' AND `payment_external_id` = '{$payment_external_id}' LIMIT 1 FOR UPDATE;");
0 ignored issues
show
Bug introduced by
The variable $this does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
636
637
  return $payment;
638
}
639
640
641
/**
642
 * @return array|bool|mysqli_result|null
643
 */
644
function db_ube_report_get_best_battles() {
645
  $query = classSupernova::$db->doSelect("SELECT *
646
      FROM `{{ube_report}}`
647
      WHERE `ube_report_time_process` <  DATE(DATE_SUB(NOW(), INTERVAL " . MODULE_INFO_BEST_BATTLES_LOCK_DAYS . " DAY))
648
      ORDER BY `ube_report_debris_total_in_metal` DESC, `ube_report_id` ASC
649
      LIMIT " . MODULE_INFO_BEST_BATTLES_REPORT_VIEW . ";");
650
651
  return $query;
652
}
653
654
function db_config_get_stockman_fleet() {
655
  classSupernova::$db->doSelect("SELECT * FROM `{{config}}` WHERE `config_name` = 'eco_stockman_fleet' LIMIT 1 FOR UPDATE;");
656
}
657
658
659
/**
660
 * @param $payment
661
 * @param $safe_comment
662
 */
663
function db_payment_update(&$payment, $safe_comment) {
664
  classSupernova::$db->doUpdate("UPDATE {{payment}} SET payment_status = {$payment['payment_status']}, payment_comment = '{$safe_comment}' WHERE payment_id = {$payment['payment_id']};");
665
}
666