Completed
Push — work-fleets ( 22b024...7f5906 )
by SuperNova.WS
06:37
created

db_queries.php ➔ db_ANNONCE_insert_set()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 7
dl 0
loc 5
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}` AS id_field FROM {{{$db_table_name}}} WHERE `{$db_value_field_name}` = '{$current_value_safe}' LIMIT 1 FOR UPDATE");
179
  if (!isset($value_id['id_field']) || !$value_id['id_field']) {
180
    classSupernova::$db->doInsert("INSERT INTO {{{$db_table_name}}} (`{$db_value_field_name}`) VALUES ('{$current_value_safe}');");
181
    $variable_id = classSupernova::$db->db_insert_id();
182
  } else {
183
    $variable_id = $value_id['id_field'];
184
  }
185
186
  return $variable_id;
187
}
188
189
/**
190
 * Функция проверяет наличие имени игрока в базе
191
 *
192
 * @param $player_name_unsafe
193
 *
194
 * @return bool
195
 */
196
function db_player_name_exists($player_name_unsafe) {
197
  sn_db_transaction_check(true);
198
199
  $player_name_safe = classSupernova::$db->db_escape($player_name_unsafe);
200
201
  $player_name_exists = classSupernova::$db->doSelectFetch(
202
    "SELECT * 
203
    FROM `{{player_name_history}}` 
204
    WHERE `player_name` = '{$player_name_safe}' 
205
    LIMIT 1 
206
    FOR UPDATE"
207
  );
208
209
  return !empty($player_name_exists);
210
}
211
212
/**
213
 * @param        $userId
214
 * @param string $username_unsafe
215
 */
216
function db_player_name_history_replace($userId, $username_unsafe) {
217
  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...
218
    'player_id'   => $userId,
219
    'player_name' => $username_unsafe,
220
  ));
221
}
222
223
224
/**
225
 * @param $username_safe
226
 *
227
 * @return array|bool|mysqli_result|null
228
 */
229
function db_player_name_history_get_name_by_name($username_safe) {
230
  $name_check = classSupernova::$db->doSelectFetch("SELECT * FROM {{player_name_history}} WHERE `player_name` LIKE \"{$username_safe}\" LIMIT 1 FOR UPDATE;");
231
232
  return $name_check;
233
}
234
235
236
// BANNED *************************************************************************************************************
237
function db_banned_list_select() {
238
  return classSupernova::$db->doSelect("SELECT * FROM `{{banned}}` ORDER BY `ban_id` DESC;");
239
}
240
241
/**
242
 * @param $user_row
243
 *
244
 * @return array|bool|mysqli_result|null
245
 */
246
function db_ban_list_get_details($user_row) {
247
  $ban_details = classSupernova::$db->doSelectFetch("SELECT * FROM {{banned}} WHERE `ban_user_id` = {$user_row['id']} ORDER BY ban_id DESC LIMIT 1");
248
249
  return $ban_details;
250
}
251
252
253
// BLITZ ***************************************************************************************************************
254
function db_blitz_reg_insert($user, $current_round) {
255
  classSupernova::$db->doInsert("INSERT IGNORE INTO {{blitz_registrations}} SET `user_id` = {$user['id']}, `round_number` = {$current_round};");
256
}
257
258
function db_blitz_reg_get_id_by_player_and_round($user, $current_round) {
259
  return classSupernova::$db->doSelectFetch("SELECT `id` FROM `{{blitz_registrations}}` WHERE `user_id` = {$user['id']} AND `round_number` = {$current_round} FOR UPDATE;");
260
}
261
262
function db_blitz_reg_count($current_round) {
263
  return classSupernova::$db->doSelectFetch("SELECT count(`id`) AS `count` FROM {{blitz_registrations}} WHERE `round_number` = {$current_round};");
264
}
265
266
function db_blitz_reg_get_random_id($current_round) {
267
  return classSupernova::$db->doSelect("SELECT `id` FROM {{blitz_registrations}} WHERE `round_number` = {$current_round} ORDER BY RAND();");
268
}
269
270
function db_blitz_reg_get_player_list($current_round) {
271
  return classSupernova::$db->doSelect("SELECT blitz_name, blitz_password, blitz_online FROM {{blitz_registrations}} WHERE `round_number` = {$current_round} ORDER BY `id`;");
272
}
273
274
function db_blitz_reg_get_player_list_order_by_place($current_round) {
275
  return classSupernova::$db->doSelect("SELECT * FROM {{blitz_registrations}} WHERE `round_number` = {$current_round} ORDER BY `blitz_place` FOR UPDATE;");
276
}
277
278
function db_blitz_reg_get_player_list_and_users($current_round) {
279
  return classSupernova::$db->doSelect(
280
    "SELECT u.*, br.blitz_name, br.blitz_password, br.blitz_place, br.blitz_status, br.blitz_points, br.blitz_reward_dark_matter
281
    FROM {{blitz_registrations}} AS br
282
    JOIN {{users}} AS u ON u.id = br.user_id
283
  WHERE br.`round_number` = {$current_round}
284
  order by `blitz_place`, `timestamp`;");
285
}
286
287
function db_blitz_reg_update_with_name_and_password($blitz_name, $blitz_password, $row, $current_round) {
288
  classSupernova::$db->doUpdate("UPDATE {{blitz_registrations}} SET blitz_name = '{$blitz_name}', blitz_password = '{$blitz_password}' WHERE `id` = {$row['id']} AND `round_number` = {$current_round};");
289
}
290
291
function db_blitz_reg_update_apply_results($reward, $row, $current_round) {
292
  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};");
293
}
294
295
function db_blitz_reg_update_results($blitz_result_data, $current_round) {
296
  classSupernova::$db->doUpdate(
297
    "UPDATE `{{blitz_registrations}}` SET
298
            `blitz_player_id` = '{$blitz_result_data[0]}',
299
            `blitz_online` = '{$blitz_result_data[2]}',
300
            `blitz_place` = '{$blitz_result_data[3]}',
301
            `blitz_points` = '{$blitz_result_data[4]}'
302
          WHERE `blitz_name` = '{$blitz_result_data[1]}' AND `round_number` = {$current_round};");
303
}
304
305
function db_blitz_reg_delete($userId, $current_round) {
306
  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...
307
}
308
309
310
// Universe *************************************************************************************************************
311
function db_universe_get_name($uni_galaxy, $uni_system = 0) {
312
  $db_row = classSupernova::$db->doSelectFetch("select `universe_name` from `{{universe}}` where `universe_galaxy` = {$uni_galaxy} and `universe_system` = {$uni_system} limit 1;");
313
314
  return $db_row['universe_name'];
315
}
316
317
/**
318
 * @param $uni_galaxy
319
 * @param $uni_system
320
 *
321
 * @return array|bool|mysqli_result|null
322
 */
323
function db_universe_get($uni_galaxy, $uni_system) {
324
  $uni_row = classSupernova::$db->doSelectFetch("select * from `{{universe}}` where `universe_galaxy` = {$uni_galaxy} and `universe_system` = {$uni_system} limit 1;");
325
326
  return $uni_row;
327
}
328
329
/**
330
 * @param $uni_galaxy
331
 * @param $uni_system
332
 * @param $uni_row
333
 */
334
function db_universe_rename($uni_galaxy, $uni_system, $uni_row) {
335
  $this->db->doReplaceSet('universe', array(
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...
336
    'universe_galaxy' => $uni_galaxy,
337
    'universe_system' => $uni_system,
338
    'universe_name' => $uni_row['universe_name'],
339
    'universe_price' => $uni_row['universe_price'],
340
  ));
341
342
}
343
344
345
// Payment *************************************************************************************************************
346
347
function db_payment_get($payment_id) {
348
  return classSupernova::$db->doSelectFetch("SELECT * FROM {{payment}} WHERE `payment_id` = {$payment_id} LIMIT 1;");
349
}
350
351
/**
352
 * @param $flt_payer
353
 * @param $flt_status
354
 * @param $flt_test
355
 * @param $flt_module
356
 *
357
 * @return array|bool|mysqli_result|null
358
 */
359
function db_payment_list_get($flt_payer, $flt_status, $flt_test, $flt_module) {
360
  $extra_conditions =
361
    ($flt_payer > 0 ? "AND payment_user_id = {$flt_payer} " : '') .
362
    ($flt_status >= 0 ? "AND payment_status = {$flt_status} " : '') .
363
    ($flt_test >= 0 ? "AND payment_test = {$flt_test} " : '') .
364
    ($flt_module ? "AND payment_module_name = '{$flt_module}' " : '');
365
  $query = classSupernova::$db->doSelect("SELECT * FROM `{{payment}}` WHERE 1 {$extra_conditions} ORDER BY payment_id DESC;");
366
367
  return $query;
368
}
369
370
/**
371
 * @return array|bool|mysqli_result|null
372
 */
373
function db_payment_list_payers() {
374
  $query = classSupernova::$db->doSelect("SELECT payment_user_id, payment_user_name FROM `{{payment}}` GROUP BY payment_user_id ORDER BY payment_user_name");
375
376
  return $query;
377
}
378
379
/**
380
 * @return array|bool|mysqli_result|null
381
 */
382
function db_payment_list_modules() {
383
  $query = classSupernova::$db->doSelect("SELECT DISTINCT payment_module_name FROM `{{payment}}` ORDER BY payment_module_name");
384
385
  return $query;
386
}
387
388
389
// Log Online *************************************************************************************************************
390
function db_log_online_insert() {
391
  classSupernova::$db->doInsert("INSERT IGNORE INTO `{{log_users_online}}` SET online_count = " . 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...
392
}
393
394
// Log *************************************************************************************************************
395
396
/**
397
 * @return array|bool|mysqli_result|null
398
 */
399
function db_log_list_get_last_100() {
400
  $query = classSupernova::$db->doSelect("SELECT * FROM `{{logs}}` ORDER BY log_id DESC LIMIT 100;");
401
402
  return $query;
403
}
404
405
/**
406
 * @param $delete
407
 */
408
function db_log_delete_by_id($delete) {
409
  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...
410
}
411
412
function db_log_delete_update_and_stat_calc() {
413
  classSupernova::$db->doDeleteComplex("DELETE FROM `{{logs}}` WHERE `log_code` IN (103, 180, 191);");
414
}
415
416
/**
417
 * @param $detail
418
 *
419
 * @return array|bool|mysqli_result|null
420
 */
421
function db_log_get_by_id($detail) {
422
  $errorInfo = classSupernova::$db->doSelectFetch("SELECT * FROM `{{logs}}` WHERE `log_id` = {$detail} LIMIT 1;");
423
424
  return $errorInfo;
425
}
426
427
/**
428
 * @param $i
429
 *
430
 * @return array|bool|mysqli_result|null
431
 */
432
function db_log_count($i) {
433
  $query = classSupernova::$db->doSelectFetch("SELECT COUNT(*) AS LOG_MESSAGES_TOTAL, {$i} AS LOG_MESSAGES_VISIBLE FROM `{{logs}}`;");
434
435
  return $query;
436
}
437
438
// SYSTEM QUERIES - MOVE TO DB *****************************************************************************************
439
/**
440
 * @return array|bool|mysqli_result|null
441
 */
442
function db_core_show_status() {
443
  $result = classSupernova::$db->doExecute('SHOW STATUS;');
444
445
  return $result;
446
}
447
448
/**
449
 * @return array|bool|mysqli_result|null
450
 */
451
function db_counter_list_by_week() {
452
  $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;");
453
454
  return $query;
455
}
456
457
/**
458
 * @param $user_last_browser_id
459
 *
460
 * @return array|bool|mysqli_result|null
461
 */
462
function db_browser_agent_get_by_id($user_last_browser_id) {
463
  $temp = classSupernova::$db->doSelectFetch("SELECT browser_user_agent FROM {{security_browser}} WHERE `browser_id` = {$user_last_browser_id}");
464
465
  return $temp['browser_user_agent'];
466
}
467
468
469
/**
470
 * @param $user_id
471
 * @param $change_type
472
 * @param $dark_matter
473
 * @param $comment
474
 * @param $row
475
 * @param $page_url
476
 */
477
function db_log_dark_matter_insert($user_id, $change_type, $dark_matter, $comment, $row, $page_url) {
478
  classSupernova::$db->doInsert(
479
    "INSERT INTO {{log_dark_matter}} (`log_dark_matter_username`, `log_dark_matter_reason`,
480
        `log_dark_matter_amount`, `log_dark_matter_comment`, `log_dark_matter_page`, `log_dark_matter_sender`)
481
      VALUES (
482
        '{$row['username']}', {$change_type},
483
        {$dark_matter}, '{$comment}', '{$page_url}', {$user_id}
484
      );");
485
}
486
487
// REFERRALS ***********************************************************************************************************
488
/**
489
 * @param $user_id_safe
490
 *
491
 * @return array|bool|mysqli_result|null
492
 */
493
function db_referral_get_by_id($user_id_safe) {
494
  $old_referral = classSupernova::$db->doSelectFetch("SELECT * FROM {{referrals}} WHERE `id` = {$user_id_safe} LIMIT 1 FOR UPDATE;");
495
496
  return $old_referral;
497
}
498
499
/**
500
 * @param $user_id_safe
501
 * @param $dark_matter
502
 */
503
function db_referral_update_dm($user_id_safe, $dark_matter) {
504
  classSupernova::$db->doUpdate("UPDATE {{referrals}} SET dark_matter = dark_matter + '{$dark_matter}' WHERE `id` = {$user_id_safe} LIMIT 1;");
505
}
506
507
508
/**
509
 * @param $options
510
 * @param $user_new
511
 */
512
function db_referral_insert($options, $user_new) {
513
  classSupernova::$db->doInsert("INSERT INTO {{referrals}} SET `id` = {$user_new['id']}, `id_partner` = {$options['partner_id']}");
514
}
515
516
517
// Quests ***********************************************************************************************************
518
/**
519
 * @param $query_add_select
520
 * @param $query_add_from
521
 * @param $query_add_where
522
 *
523
 * @return array|bool|mysqli_result|null
524
 */
525
function db_quest_list_get($query_add_select, $query_add_from, $query_add_where) {
526
  $query = classSupernova::$db->doSelect(
527
    "SELECT q.* {$query_add_select}
528
      FROM {{quest}} AS q {$query_add_from}
529
      WHERE 1 {$query_add_where}
530
    ;"
531
  );
532
533
  return $query;
534
}
535
536
537
/**
538
 * @return array|bool|mysqli_result|null
539
 */
540
function db_quest_count() {
541
  $query = classSupernova::$db->doSelectFetch("SELECT count(*) AS count FROM `{{quest}}`;");
542
543
  return $query;
544
}
545
546
/**
547
 * @param $quest_id
548
 *
549
 * @return array|bool|mysqli_result|null
550
 */
551
function db_quest_get($quest_id) {
552
  $quest = classSupernova::$db->doSelectFetch("SELECT * FROM {{quest}} WHERE `quest_id` = {$quest_id} LIMIT 1;");
553
554
  return $quest;
555
}
556
557
/**
558
 * @param $quest_id
559
 */
560
function db_quest_delete($quest_id) {
561
  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...
562
}
563
564
/**
565
 * @param $quest_name
566
 * @param $quest_type
567
 * @param $quest_description
568
 * @param $quest_conditions
569
 * @param $quest_rewards
570
 * @param $quest_id
571
 */
572
function db_quest_update($quest_name, $quest_type, $quest_description, $quest_conditions, $quest_rewards, $quest_id) {
573
  classSupernova::$db->doUpdate(
574
    "UPDATE {{quest}} SET
575
              `quest_name` = '{$quest_name}',
576
              `quest_type` = '{$quest_type}',
577
              `quest_description` = '{$quest_description}',
578
              `quest_conditions` = '$quest_conditions',
579
              `quest_rewards` = '{$quest_rewards}'
580
            WHERE `quest_id` = {$quest_id} LIMIT 1;"
581
  );
582
}
583
584
585
/**
586
 * @param $banner
587
 * @param $banned
588
 * @param $reason
589
 * @param $ban_until
590
 */
591 View Code Duplication
function db_ban_insert($banner, $banned, $reason, $ban_until) {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in 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...
592
  classSupernova::$db->doInsert(
593
    "INSERT INTO
594
      {{banned}}
595
    SET
596
      `ban_user_id` = '{$banned['id']}',
597
      `ban_user_name` = '{$banned['username']}',
598
      `ban_reason` = '{$reason}',
599
      `ban_time` = " . SN_TIME_NOW . ",
600
      `ban_until` = {$ban_until},
601
      `ban_issuer_id` = '{$banner['id']}',
602
      `ban_issuer_name` = '{$banner['username']}',
603
      `ban_issuer_email` = '{$banner['email']}'
604
  ");
605
}
606
607
608
/**
609
 * @param $banner
610
 * @param $banned
611
 * @param $reason
612
 */
613 View Code Duplication
function db_ban_insert_unset($banner, $banned, $reason) {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in 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...
614
  classSupernova::$db->doInsert(
615
    "INSERT INTO {{banned}}
616
    SET
617
      `ban_user_id` = '{$banned['id']}',
618
      `ban_user_name` = '{$banned['username']}',
619
      `ban_reason` = '{$reason}',
620
      `ban_time` = 0,
621
      `ban_until` = " . SN_TIME_NOW . ",
622
      `ban_issuer_id` = '{$banner['id']}',
623
      `ban_issuer_name` = '{$banner['username']}',
624
      `ban_issuer_email` = '{$banner['email']}'
625
  ");
626
}
627
628
629
/**
630
 * @param $user_id
631
 *
632
 * @return array|bool|mysqli_result|null
633
 */
634
function db_stat_get_by_user($user_id) {
635
  $StatRecord = classSupernova::$db->doSelectFetch("SELECT * FROM {{statpoints}} WHERE `stat_type` = 1 AND `stat_code` = 1 AND `id_owner` = {$user_id};");
636
637
  return $StatRecord;
638
}
639
640
/**
641
 * @param $user_id
642
 *
643
 * @return array|bool|mysqli_result|null
644
 */
645
function db_stat_get_by_user2($user_id) {
646
  $query = classSupernova::$db->doSelect("SELECT * FROM {{statpoints}} WHERE `stat_type` = 1 AND `id_owner` = {$user_id} ORDER BY `stat_code` DESC;");
647
648
  return $query;
649
}
650
651
/**
652
 * @param $options
653
 *
654
 * @return array|bool|mysqli_result|null
655
 */
656
function db_payment_get_something($options) {
657
  $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...
658
659
  return $payment;
660
}
661
662
/**
663
 * @param $payment_external_id
664
 *
665
 * @return array|bool|mysqli_result|null
666
 */
667
function db_payment_get_something2($payment_external_id) {
668
  $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...
669
670
  return $payment;
671
}
672
673
674
/**
675
 * @return array|bool|mysqli_result|null
676
 */
677
function db_ube_report_get_best_battles() {
678
  $query = classSupernova::$db->doSelect("SELECT *
679
      FROM `{{ube_report}}`
680
      WHERE `ube_report_time_process` <  DATE(DATE_SUB(NOW(), INTERVAL " . MODULE_INFO_BEST_BATTLES_LOCK_DAYS . " DAY))
681
      ORDER BY `ube_report_debris_total_in_metal` DESC, `ube_report_id` ASC
682
      LIMIT " . MODULE_INFO_BEST_BATTLES_REPORT_VIEW . ";");
683
684
  return $query;
685
}
686
687
function db_config_get_stockman_fleet() {
688
  classSupernova::$db->doSelect("SELECT * FROM `{{config}}` WHERE `config_name` = 'eco_stockman_fleet' LIMIT 1 FOR UPDATE;");
689
}
690
691
692
/**
693
 * @param $payment
694
 * @param $safe_comment
695
 */
696
function db_payment_update(&$payment, $safe_comment) {
697
  classSupernova::$db->doUpdate("UPDATE {{payment}} SET payment_status = {$payment['payment_status']}, payment_comment = '{$safe_comment}' WHERE payment_id = {$payment['payment_id']};");
698
}
699