Completed
Push — work-fleets ( d7065d...1ee481 )
by SuperNova.WS
08:22
created

DBStaticQue::db_que_research_change_origin()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 11
ccs 0
cts 11
cp 0
crap 2
rs 9.4285
1
<?php
2
3
namespace DBStatic;
4
use classSupernova;
5
use mysqli_result;
6
7
class DBStaticQue {
8
9
  /*
10
   * С $for_update === true эта функция должна вызываться только из транзакции! Все соответствующие записи в users и planets должны быть уже блокированы!
11
   *
12
   * $que_type
13
   *   !$que_type - все очереди
14
   *   QUE_XXXXXX - конкретная очередь по планете
15
   * $user_id - ID пользователя
16
   * $planet_id
17
   *   $que_type == QUE_RESEARCH - игнорируется
18
   *   null - обработка очередей планет не производится
19
   *   false/0 - обрабатываются очереди всех планет по $user_id
20
   *   (integer) - обрабатываются локальные очереди для планеты. Нужно, например, в обработчике флотов
21
   *   иначе - $que_type для указанной планеты
22
   * $for_update - true == нужно блокировать записи
23
   *
24
   * TODO Работа при !$user_id
25
   * TODO Переформатировать вывод данных, что бы можно было возвращать данные по всем планетам и юзерам в одном запросе: добавить подмассивы 'que', 'planets', 'players'
26
   *
27
   */
28
  public static function db_que_list_by_type_location($user_id, $planet_id = null, $que_type = false, $for_update = false) {
0 ignored issues
show
Unused Code introduced by
The parameter $for_update is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
29
    if (!$user_id) {
30
      pdump(debug_backtrace());
31
      die('No user_id for que_get_que()');
32
    }
33
34
    $ques = array();
35
36
    $query = array();
37
38
    if ($user_id = idval($user_id)) {
39
      $query[] = "`que_player_id` = {$user_id}";
40
    }
41
42
    if ($que_type == QUE_RESEARCH || $planet_id === null) {
43
      $query[] = "`que_planet_id` IS NULL";
44
    } elseif ($planet_id) {
45
      $query[] = "(`que_planet_id` = {$planet_id}" . ($que_type ? '' : ' OR que_planet_id IS NULL') . ")";
46
    }
47
    if ($que_type) {
48
      $query[] = "`que_type` = {$que_type}";
49
    }
50
51
    $ques['items'] = classSupernova::$gc->cacheOperator->db_get_record_list(LOC_QUE, implode(' AND ', $query));
0 ignored issues
show
Bug introduced by
The method db_get_record_list does only exist in SnDbCachedOperator, 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...
52
53
    return que_recalculate($ques);
54
  }
55
56
57
  public static function db_que_list_stat() {
58
    return classSupernova::$db->doSelect("SELECT que_player_id, sum(que_unit_amount) AS que_unit_amount, que_unit_price FROM `{{que}}` GROUP BY que_player_id, que_unit_price;");
59
  }
60
61
  public static function db_que_set_time_left_by_id($que_id, $que_time_left) {
62
    return classSupernova::$gc->cacheOperator->db_upd_record_by_id(
0 ignored issues
show
Bug introduced by
The method db_upd_record_by_id does only exist in SnDbCachedOperator, 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...
63
      LOC_QUE,
64
      $que_id,
65
      array(
66
        'que_time_left' => $que_time_left,
67
      ),
68
      array()
69
    );
70
  }
71
72
  /**
73
   * @param array $set
74
   *
75
   * @return array|bool|false|mysqli_result|null
76
   */
77
  public static function db_que_set_insert($set) {
78
    return classSupernova::$gc->cacheOperator->db_ins_record(LOC_QUE, $set);
0 ignored issues
show
Bug introduced by
The method db_ins_record does only exist in SnDbCachedOperator, 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...
79
  }
80
81
  public static function db_que_delete_by_id($que_id) {
82
    return classSupernova::$gc->cacheOperator->db_del_record_by_id(LOC_QUE, $que_id);
0 ignored issues
show
Bug introduced by
The method db_del_record_by_id does only exist in SnDbCachedOperator, 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...
83
  }
84
85
  public static function db_que_planet_change_owner($planet_id, $new_owner_id) {
86
    return classSupernova::$db->doUpdateTableSet(
87
      TABLE_QUE,
88
      array(
89
        'que_player_id' => $new_owner_id,
90
      ),
91
      array(
92
        'que_planet_id' => $planet_id,
93
      )
94
    );
95
  }
96
97
  public static function db_que_research_change_origin($planet_id, $new_planet_id) {
98
    return classSupernova::$db->doUpdateTableSet(
99
      TABLE_QUE,
100
      array(
101
        'que_planet_id_origin' => $new_planet_id,
102
      ),
103
      array(
104
        'que_planet_id_origin' => $planet_id,
105
      )
106
    );
107
  }
108
109
}