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

DBStaticPlanet::db_planet_by_vector()   B

Complexity

Conditions 7
Paths 64

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 7
eloc 8
c 1
b 0
f 0
nc 64
nop 4
dl 0
loc 10
ccs 0
cts 9
cp 0
crap 56
rs 8.2222
1
<?php
2
3
namespace DBStatic;
4
5
use classSupernova;
6
use mysqli_result;
7
use Vector\Vector;
8
9
class DBStaticPlanet {
10
11
  /**
12
   * @param array $rowUser
13
   * @param array $rowPlanet
14
   *
15
   * @return array
16
   */
17
  public static function getResources($rowUser, $rowPlanet) {
18
    $planetResources = array();
19
20
    $sn_group_resources = sn_get_groups('resources_loot');
21
    foreach ($sn_group_resources as $resource_id) {
22
      $planetResources[$resource_id] = floor(mrc_get_level($rowUser, $rowPlanet, $resource_id));
23
    }
24
25
    return $planetResources;
26
  }
27
28
29
  public static function db_planets_purge() {
30
    classSupernova::$db->doDeleteSql(
31
      'DELETE FROM `{{planets}}` 
32
      WHERE 
33
        `id_owner` NOT IN (
34
          SELECT `id` FROM `{{users}}`
35
        );'
36
    );
37
  }
38
39
40
  /**
41
   * @param int    $planet_id
42
   * @param bool   $for_update
43
   * @param string $fields
44
   *
45
   * @return array|null
46
   */
47
  public static function db_planet_by_id($planet_id, $for_update = false, $fields = '*') {
48
    $result = classSupernova::$gc->cacheOperator->db_get_record_by_id(LOC_PLANET, $planet_id, $for_update, $fields);
0 ignored issues
show
Bug introduced by
The method db_get_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...
49
50
    return empty($result) ? null : $result;
51
  }
52
53
  public static function db_planet_by_gspt_safe($galaxy, $system, $planet, $planet_type, $for_update = false, $fields = '*') {
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...
Unused Code introduced by
The parameter $fields 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...
54
    return classSupernova::$gc->cacheOperator->db_get_record_list(LOC_PLANET,
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...
55
      "`{{planets}}`.`galaxy` = {$galaxy} AND `{{planets}}`.`system` = {$system} AND `{{planets}}`.`planet` = {$planet} AND `{{planets}}`.`planet_type` = {$planet_type}", true);
56
  }
57
58
  public static function db_planet_by_gspt($galaxy, $system, $planet, $planet_type, $for_update = false, $fields = '*') {
59
    $galaxy = intval($galaxy);
60
    $system = intval($system);
61
    $planet = intval($planet);
62
    $planet_type = intval($planet_type);
63
64
    return DBStaticPlanet::db_planet_by_gspt_safe($galaxy, $system, $planet, $planet_type, $for_update, $fields);
65
  }
66
67
  public static function db_planet_by_vector($vector, $prefix = '', $for_update = false, $fields = '*') {
68
    $galaxy = isset($vector[$prefix . 'galaxy']) ? intval($vector[$prefix . 'galaxy']) : 0;
69
    $system = isset($vector[$prefix . 'system']) ? intval($vector[$prefix . 'system']) : 0;
70
    $planet = isset($vector[$prefix . 'planet']) ? intval($vector[$prefix . 'planet']) : 0;
71
    $planet_type = isset($vector[$prefix . 'planet_type']) ? intval($vector[$prefix . 'planet_type']) :
72
      (isset($vector[$prefix . 'type']) ? intval($vector[$prefix . 'type']) : 0);
73
    $planet_type = $planet_type == PT_DEBRIS ? PT_PLANET : $planet_type;
74
75
    return DBStaticPlanet::db_planet_by_gspt_safe($galaxy, $system, $planet, $planet_type, $for_update, $fields);
76
  }
77
78
  /**
79
   * @param Vector $vector
80
   * @param bool   $for_update
81
   * @param string $fields
82
   *
83
   * @return array
84
   */
85
  public static function db_planet_by_vector_object($vector, $for_update = false, $fields = '*') {
86
    $planet_type = $vector->type == PT_DEBRIS ? PT_PLANET : $vector->type;
87
    $result = DBStaticPlanet::db_planet_by_gspt_safe($vector->galaxy, $vector->system, $vector->planet, $planet_type, $for_update, $fields);
88
89
    return !empty($result) ? $result : array();
90
  }
91
92 View Code Duplication
  public static function db_planet_by_parent($parent_id, $for_update = false, $fields = '*') {
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...
Unused Code introduced by
The parameter $fields 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...
Duplication introduced by
This method 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...
93
    if (!($parent_id = idval($parent_id))) {
94
      return false;
95
    }
96
97
    return classSupernova::$gc->cacheOperator->db_get_record_list(
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...
98
      LOC_PLANET,
99
      array('parent_planet' => $parent_id, 'planet_type' => PT_MOON),
0 ignored issues
show
Documentation introduced by
array('parent_planet' =>...lanet_type' => PT_MOON) is of type array<string,double|inte...lanet_type":"integer"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
100
      true
101
    );
102
103
//    return classSupernova::$gc->cacheOperator->db_get_record_list(LOC_PLANET,
0 ignored issues
show
Unused Code Comprehensibility introduced by
48% 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...
104
//      "`parent_planet` = {$parent_id} AND `planet_type` = " . PT_MOON, true);
105
  }
106
107 View Code Duplication
  public static function db_planet_by_id_and_owner($planet_id, $owner_id, $for_update = false, $fields = '*') {
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...
Unused Code introduced by
The parameter $fields 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...
Duplication introduced by
This method 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...
108
    if (!($planet_id = idval($planet_id)) || !($owner_id = idval($owner_id))) {
109
      return false;
110
    }
111
112
    return classSupernova::$gc->cacheOperator->db_get_record_list(LOC_PLANET,
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...
113
      "`id` = {$planet_id} AND `id_owner` = {$owner_id}", true);
114
  }
115
116
117 View Code Duplication
  public static function db_planet_list_moon_other($user_id, $this_moon_id) {
0 ignored issues
show
Duplication introduced by
This method 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...
118
    if (!($user_id = idval($user_id)) || !($this_moon_id = idval($this_moon_id))) {
119
      return false;
120
    }
121
122
    return classSupernova::$gc->cacheOperator->db_get_record_list(LOC_PLANET,
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...
123
      "`planet_type` = " . PT_MOON . " AND `id_owner` = {$user_id} AND `id` != {$this_moon_id}");
124
  }
125
126
  public static function db_planet_list_in_system($galaxy, $system) {
127
    $galaxy = intval($galaxy);
128
    $system = intval($system);
129
130
    return classSupernova::$gc->cacheOperator->db_get_record_list(LOC_PLANET,
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...
131
      "`galaxy` = {$galaxy} AND `system` = {$system}");
132
  }
133
134
  public static function db_planet_list_sorted($user_row, $skip_planet_id = false, $field_list = '', $conditions = '') {
0 ignored issues
show
Unused Code introduced by
The parameter $field_list 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...
135
    if (!is_array($user_row)) {
136
      return false;
137
    }
138
    // $field_list = $field_list != '*' ? "{{planets}}.`id`, `name`, `image`, {{planets}}.`galaxy`, {{planets}}.`system`, {{planets}}.`planet`, `planet_type`{$field_list}" : $field_list;
0 ignored issues
show
Unused Code Comprehensibility introduced by
45% 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...
139
    $conditions .= $skip_planet_id ? " AND `id` <> {$skip_planet_id} " : '';
140
141
    $sort_orders = array(
142
      SORT_ID       => '{{planets}}.`id`',
143
      SORT_LOCATION => '{{planets}}.`galaxy`, {{planets}}.`system`, {{planets}}.`planet`, {{planets}}.`planet_type`',
144
      SORT_NAME     => '`name`',
145
      SORT_SIZE     => '({{planets}}.`field_max`)',
146
    );
147
    $order_by = classSupernova::$user_options[PLAYER_OPTION_PLANET_SORT];
148
    empty($sort_orders[$order_by]) ? $order_by = SORT_ID : false;
149
    $order_by = $sort_orders[$order_by] . ' ' . (classSupernova::$user_options[PLAYER_OPTION_PLANET_SORT_INVERSE] == SORT_ASCENDING ? 'ASC' : 'DESC');
150
151
    // Compilating query
152
    return classSupernova::$gc->cacheOperator->db_get_record_list(LOC_PLANET,
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...
153
      "`id_owner` = '{$user_row['id']}' {$conditions} ORDER BY {$order_by}");
154
  }
155
156 View Code Duplication
  public static function db_planet_list_by_user_or_planet($user_id, $planet_id) {
0 ignored issues
show
Duplication introduced by
This method 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...
157
    if (!($user_id = idval($user_id)) && !($planet_id = idval($planet_id))) {
158
      return false;
159
    }
160
161
    return classSupernova::$gc->cacheOperator->db_get_record_list(LOC_PLANET,
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...
162
      $planet_id = idval($planet_id) ? "{{planets}}.`id` = {$planet_id}" : "`id_owner` = {$user_id}", $planet_id);
163
  }
164
165
  /**
166
   * @param array $planetRowFieldChanges - array of $resourceId => $amount
167
   * @param int   $planetId
168
   *
169
   * // TODO - DEDUPLICATE
170
   * @see DBStaticUser::db_user_update_resources
171
   */
172 View Code Duplication
  public static function db_planet_update_resources($planetRowFieldChanges, $planetId) {
0 ignored issues
show
Duplication introduced by
This method 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...
173
    $fields = array();
174
    foreach ($planetRowFieldChanges as $resourceId => $value) {
175
      $fields[pname_resource_name($resourceId)] = $value;
176
    }
177
    if (!empty($fields)) {
178
      classSupernova::$gc->db->doUpdateRowAdjust(
0 ignored issues
show
Bug introduced by
The method doUpdateRowAdjust 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...
179
        TABLE_PLANETS,
180
        array(),
181
        $fields,
182
        array(
183
          'id' => $planetId
184
        )
185
      );
186
    }
187
  }
188
189
  /**
190
   * @param        $planet_id
191
   * @param array  $set
192
   *
193
   * @return array|bool|mysqli_result|null
194
   */
195
  public static function db_planet_update_set_by_id($planet_id, $set) {
196
    return classSupernova::$gc->cacheOperator->db_upd_record_by_id(LOC_PLANET, $planet_id, $set, array());
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...
197
  }
198
199
  /**
200
   * @param        $planet_id
201
   * @param array  $adjust
202
   *
203
   * @return array|bool|mysqli_result|null
204
   */
205
  public static function db_planet_update_adjust_by_id($planet_id, $adjust) {
206
    return classSupernova::$gc->cacheOperator->db_upd_record_by_id(LOC_PLANET, $planet_id, array(), $adjust);
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...
207
  }
208
209
  // TODO - adjust separate
210
211
  public static function db_planet_update_by_gspt($ui_galaxy, $ui_system, $ui_planet, $ui_planet_type = PT_ALL, $set, $adjust) {
212
    if (empty($set) && empty($adjust)) {
213
      return;
214
    }
215
216
    $where = array(
217
      'galaxy' => $ui_galaxy,
218
      'system' => $ui_system,
219
      'planet' => $ui_planet,
220
    );
221
    if (intval($ui_planet_type)) {
222
      $where['planet_type'] = $ui_planet_type;
223
    }
224
    classSupernova::$gc->cacheOperator->db_upd_record_list(
0 ignored issues
show
Bug introduced by
The method db_upd_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...
225
      LOC_PLANET,
226
      $set,
227
      $adjust,
228
      $where
229
    );
230
  }
231
232
  /**
233
   * @param int   $ui_parent_id
234
   * @param array $set
235
   */
236 View Code Duplication
  public static function db_planet_set_by_parent($ui_parent_id, $set) {
0 ignored issues
show
Duplication introduced by
This method 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...
237
    if (!idval($ui_parent_id) || empty($set)) {
238
      return;
239
    }
240
241
    classSupernova::$gc->cacheOperator->db_upd_record_list(
0 ignored issues
show
Bug introduced by
The method db_upd_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...
242
      LOC_PLANET,
243
      $set,
244
      array(),
245
      array(
246
        'parent_planet' => $ui_parent_id,
247
      )
248
    );
249
  }
250
251
  /**
252
   * @param       $ui_owner_id
253
   * @param array $set
254
   */
255 View Code Duplication
  public static function db_planet_set_by_owner($ui_owner_id, $set) {
0 ignored issues
show
Duplication introduced by
This method 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...
256
    if (!idval($ui_owner_id) || empty($set)) {
257
      return;
258
    }
259
260
    classSupernova::$gc->cacheOperator->db_upd_record_list(
0 ignored issues
show
Bug introduced by
The method db_upd_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...
261
      LOC_PLANET,
262
      $set,
263
      array(),
264
      array(
265
        'id_owner' => $ui_owner_id
266
      )
267
    );
268
  }
269
270
271 View Code Duplication
  public static function db_planet_delete_by_id($planet_id) {
0 ignored issues
show
Duplication introduced by
This method 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...
272
    // if(!($planet_id = intval($planet_id))) return false;
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% 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...
273
    if (!($planet_id = idval($planet_id))) {
274
      return false;
275
    }
276
    classSupernova::$gc->cacheOperator->db_del_record_by_id(LOC_PLANET, $planet_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...
277
    classSupernova::$gc->cacheOperator->db_del_record_list(LOC_UNIT, array(
0 ignored issues
show
Bug introduced by
The method db_del_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...
278
      'unit_location_type' => LOC_PLANET,
279
      'unit_location_id'   => $planet_id,
280
    ));
281
282
    // Очереди очистятся автоматически по FOREIGN KEY
283
    return true;
284
  }
285
286 View Code Duplication
  public static function db_planet_list_delete_by_owner($ui_owner_id) {
0 ignored issues
show
Duplication introduced by
This method 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...
287
    // if(!($si_owner_id = intval($ui_owner_id))) return false;
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% 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...
288
    if (!($si_owner_id = idval($ui_owner_id))) {
289
      return false;
290
    }
291
    classSupernova::$gc->cacheOperator->db_del_record_list(LOC_PLANET, array('id_owner' => $si_owner_id));
0 ignored issues
show
Bug introduced by
The method db_del_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...
292
    classSupernova::$gc->cacheOperator->db_del_record_list(LOC_UNIT, array(
293
      'unit_location_type' => LOC_PLANET,
294
      'unit_player_id'     => $si_owner_id,
295
    ));
296
297
    // Очереди очистятся автоматически по FOREIGN KEY
298
    return true;
299
  }
300
301
302 View Code Duplication
  public static function db_planet_count_by_type($ui_user_id, $ui_planet_type = PT_PLANET) {
0 ignored issues
show
Duplication introduced by
This method 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...
303
    // $si_user_id = intval($ui_user_id);
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
304
    $si_user_id = idval($ui_user_id);
305
    $si_planet_type = intval($ui_planet_type);
306
307
    // Лочим запись-родителя - если она есть и еще не залочена
308
    $record_list = classSupernova::$gc->cacheOperator->db_get_record_list(LOC_PLANET, "`id_owner` = {$si_user_id} AND `planet_type` = {$si_planet_type}");
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...
309
310
    return is_array($record_list) ? count($record_list) : 0;
311
    // $planets = doquery("SELECT COUNT(*) AS planet_count FROM {{planets}} WHERE `id_owner` = {$si_user_id} AND `planet_type` = {$si_planet_type}", true);
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% 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...
312
    // return isset($planets['planet_count']) ? $planets['planet_count'] : 0;
0 ignored issues
show
Unused Code Comprehensibility introduced by
73% 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...
313
  }
314
315
  public static function db_planet_list_resources_by_owner() {
316
    return classSupernova::$db->doSelect("SELECT `id_owner`, sum(metal) AS metal, sum(crystal) AS crystal, sum(deuterium) AS deuterium FROM `{{planets}}` WHERE id_owner <> 0 /*AND id_owner is not null*/ GROUP BY id_owner;");
317
  }
318
319
}
320