Completed
Push — work-fleets ( c94fa6...bf14b2 )
by SuperNova.WS
06:23
created

DBStaticPlanet   C

Complexity

Total Complexity 57

Size/Duplication

Total Lines 294
Duplicated Lines 37.41 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 10
Bugs 0 Features 1
Metric Value
c 10
b 0
f 1
dl 110
loc 294
rs 6.433
ccs 0
cts 183
cp 0
wmc 57
lcom 1
cbo 4

22 Methods

Rating   Name   Duplication   Size   Complexity  
A db_planets_purge() 0 3 1
A db_planet_by_id() 0 5 2
A db_planet_by_vector_object() 0 6 3
A db_planet_by_id_and_owner() 9 9 3
A db_planet_list_moon_other() 9 9 3
A db_planet_list_by_user_or_planet() 8 8 4
A getResources() 0 10 2
A db_planet_by_gspt_safe() 0 4 1
A db_planet_by_gspt() 0 8 1
B db_planet_by_vector() 0 10 7
A db_planet_by_parent() 0 8 2
A db_planet_list_in_system() 0 7 1
B db_planet_list_sorted() 0 21 5
A db_planet_update_resources() 16 16 3
A db_planet_update_set_by_id_DEPRECATED() 0 7 2
A db_planet_update_by_gspt() 0 20 4
A db_planet_set_by_parent() 14 14 3
A db_planet_set_by_owner() 14 14 3
A db_planet_delete_by_id() 14 14 2
A db_planet_list_delete_by_owner() 14 14 2
A db_planet_count_by_type() 12 12 2
A db_planet_list_resources_by_owner() 0 3 1

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like DBStaticPlanet often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use DBStaticPlanet, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
use Vector\Vector;
4
5
class DBStaticPlanet {
6
7
  /**
8
   * @param array $rowUser
9
   * @param array $rowPlanet
10
   *
11
   * @return array
12
   */
13
  public static function getResources($rowUser, $rowPlanet) {
14
    $planetResources = array();
15
16
    $sn_group_resources = sn_get_groups('resources_loot');
17
    foreach ($sn_group_resources as $resource_id) {
18
      $planetResources[$resource_id] = floor(mrc_get_level($rowUser, $rowPlanet, $resource_id));
19
    }
20
21
    return $planetResources;
22
  }
23
24
25
  public static function db_planets_purge() {
26
    classSupernova::$db->doDeleteComplex("DELETE FROM `{{planets}}` WHERE `id_owner` NOT IN (SELECT `id` FROM `{{users}}`);");
27
  }
28
29
30
  /**
31
   * @param int    $planet_id
32
   * @param bool   $for_update
33
   * @param string $fields
34
   *
35
   * @return array|null
36
   */
37
  public static function db_planet_by_id($planet_id, $for_update = false, $fields = '*') {
38
    $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...
39
40
    return empty($result) ? null : $result;
41
  }
42
43
  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...
44
    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...
45
      "`{{planets}}`.`galaxy` = {$galaxy} AND `{{planets}}`.`system` = {$system} AND `{{planets}}`.`planet` = {$planet} AND `{{planets}}`.`planet_type` = {$planet_type}", true);
46
  }
47
48
  public static function db_planet_by_gspt($galaxy, $system, $planet, $planet_type, $for_update = false, $fields = '*') {
49
    $galaxy = intval($galaxy);
50
    $system = intval($system);
51
    $planet = intval($planet);
52
    $planet_type = intval($planet_type);
53
54
    return DBStaticPlanet::db_planet_by_gspt_safe($galaxy, $system, $planet, $planet_type, $for_update, $fields);
55
  }
56
57
  public static function db_planet_by_vector($vector, $prefix = '', $for_update = false, $fields = '*') {
58
    $galaxy = isset($vector[$prefix . 'galaxy']) ? intval($vector[$prefix . 'galaxy']) : 0;
59
    $system = isset($vector[$prefix . 'system']) ? intval($vector[$prefix . 'system']) : 0;
60
    $planet = isset($vector[$prefix . 'planet']) ? intval($vector[$prefix . 'planet']) : 0;
61
    $planet_type = isset($vector[$prefix . 'planet_type']) ? intval($vector[$prefix . 'planet_type']) :
62
      (isset($vector[$prefix . 'type']) ? intval($vector[$prefix . 'type']) : 0);
63
    $planet_type = $planet_type == PT_DEBRIS ? PT_PLANET : $planet_type;
64
65
    return DBStaticPlanet::db_planet_by_gspt_safe($galaxy, $system, $planet, $planet_type, $for_update, $fields);
66
  }
67
68
  /**
69
   * @param Vector $vector
70
   * @param bool   $for_update
71
   * @param string $fields
72
   *
73
   * @return array
74
   */
75
  public static function db_planet_by_vector_object($vector, $for_update = false, $fields = '*') {
76
    $planet_type = $vector->type == PT_DEBRIS ? PT_PLANET : $vector->type;
77
    $result = DBStaticPlanet::db_planet_by_gspt_safe($vector->galaxy, $vector->system, $vector->planet, $planet_type, $for_update, $fields);
78
79
    return !empty($result) ? $result : array();
80
  }
81
82
  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...
83
    if (!($parent_id = idval($parent_id))) {
84
      return false;
85
    }
86
87
    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...
88
      "`parent_planet` = {$parent_id} AND `planet_type` = " . PT_MOON, true);
89
  }
90
91 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...
92
    //if(!($planet_id = intval($planet_id)) || !($owner_id = intval($owner_id))) return false;
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% 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...
93
    if (!($planet_id = idval($planet_id)) || !($owner_id = idval($owner_id))) {
94
      return false;
95
    }
96
97
    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...
98
      "`id` = {$planet_id} AND `id_owner` = {$owner_id}", true);
99
  }
100
101
102 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...
103
    // if(!($user_id = intval($user_id)) || !($this_moon_id = intval($this_moon_id))) return false;
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% 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
    if (!($user_id = idval($user_id)) || !($this_moon_id = idval($this_moon_id))) {
105
      return false;
106
    }
107
108
    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...
109
      "`planet_type` = " . PT_MOON . " AND `id_owner` = {$user_id} AND `id` != {$this_moon_id}");
110
  }
111
112
  public static function db_planet_list_in_system($galaxy, $system) {
113
    $galaxy = intval($galaxy);
114
    $system = intval($system);
115
116
    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...
117
      "`galaxy` = {$galaxy} AND `system` = {$system}");
118
  }
119
120
  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...
121
    if (!is_array($user_row)) {
122
      return false;
123
    }
124
    // $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...
125
    $conditions .= $skip_planet_id ? " AND `id` <> {$skip_planet_id} " : '';
126
127
    $sort_orders = array(
128
      SORT_ID       => '{{planets}}.`id`',
129
      SORT_LOCATION => '{{planets}}.`galaxy`, {{planets}}.`system`, {{planets}}.`planet`, {{planets}}.`planet_type`',
130
      SORT_NAME     => '`name`',
131
      SORT_SIZE     => '({{planets}}.`field_max`)',
132
    );
133
    $order_by = classSupernova::$user_options[PLAYER_OPTION_PLANET_SORT];
134
    empty($sort_orders[$order_by]) ? $order_by = SORT_ID : false;
135
    $order_by = $sort_orders[$order_by] . ' ' . (classSupernova::$user_options[PLAYER_OPTION_PLANET_SORT_INVERSE] == SORT_ASCENDING ? 'ASC' : 'DESC');
136
137
    // Compilating query
138
    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...
139
      "`id_owner` = '{$user_row['id']}' {$conditions} ORDER BY {$order_by}");
140
  }
141
142 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...
143
    if (!($user_id = idval($user_id)) && !($planet_id = idval($planet_id))) {
144
      return false;
145
    }
146
147
    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...
148
      $planet_id = idval($planet_id) ? "{{planets}}.`id` = {$planet_id}" : "`id_owner` = {$user_id}", $planet_id);
149
  }
150
151
  /**
152
   * @param array $planetRowFieldChanges - array of $resourceId => $amount
153
   * @param int   $planetId
154
   *
155
   * @see DBStaticUser::db_user_update_resources
156
   * // TODO - DEDUPLICATE
157
   */
158 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...
159
    $fields = array();
160
    foreach ($planetRowFieldChanges as $resourceId => $value) {
161
      $fields[pname_resource_name($resourceId)] = $value;
162
    }
163
    if(!empty($fields)) {
164
      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...
165
        TABLE_PLANETS,
166
        array(),
167
        $fields,
168
        array(
169
          'id' => $planetId
170
        )
171
      );
172
    }
173
  }
174
175
  /**
176
   * @param        $planet_id
177
   * @param string $set
178
   *
179
   * @return array|bool|mysqli_result|null
180
   * @deprecated
181
   */
182
  public static function db_planet_update_set_by_id_DEPRECATED($planet_id, $set) {
183
    if (!($planet_id = idval($planet_id))) {
184
      return false;
185
    }
186
187
    return classSupernova::$gc->cacheOperator->db_upd_record_by_id_DEPRECATED(LOC_PLANET, $planet_id, $set);
0 ignored issues
show
Bug introduced by
The method db_upd_record_by_id_DEPRECATED 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...
188
  }
189
190
  public static function db_planet_update_by_gspt($ui_galaxy, $ui_system, $ui_planet, $ui_planet_type = PT_ALL, $set, $adjust) {
191
    if (empty($set) && empty($adjust)) {
192
      return;
193
    }
194
195
    $where = array(
196
      'galaxy' => $ui_galaxy,
197
      'system' => $ui_system,
198
      'planet' => $ui_planet,
199
    );
200
    if(intval($ui_planet_type)) {
201
      $where['planet_type'] = $ui_planet_type;
202
    }
203
    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...
204
      LOC_PLANET,
205
      $set,
206
      $adjust,
207
      $where
208
    );
209
  }
210
211
  /**
212
   * @param int   $ui_parent_id
213
   * @param array $set
214
   */
215 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...
216
    if (!idval($ui_parent_id) || empty($set)) {
217
      return;
218
    }
219
220
    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...
221
      LOC_PLANET,
222
      $set,
223
      array(),
224
      array(
225
        'parent_planet' => $ui_parent_id,
226
      )
227
    );
228
  }
229
230
  /**
231
   * @param $ui_owner_id
232
   * @param array $set
233
   */
234 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...
235
    if (!idval($ui_owner_id) || empty($set)) {
236
      return;
237
    }
238
239
    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...
240
      LOC_PLANET,
241
      $set,
242
      array(),
243
      array(
244
        'id_owner' => $ui_owner_id
245
      )
246
    );
247
  }
248
249
250 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...
251
    // 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...
252
    if (!($planet_id = idval($planet_id))) {
253
      return false;
254
    }
255
    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...
256
    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...
257
      'unit_location_type' => LOC_PLANET,
258
      'unit_location_id' => $planet_id,
259
    ));
260
261
    // Очереди очистятся автоматически по FOREIGN KEY
262
    return true;
263
  }
264
265 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...
266
    // 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...
267
    if (!($si_owner_id = idval($ui_owner_id))) {
268
      return false;
269
    }
270
    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...
271
    classSupernova::$gc->cacheOperator->db_del_record_list(LOC_UNIT, array(
272
      'unit_location_type' => LOC_PLANET,
273
      'unit_player_id' => $si_owner_id,
274
    ));
275
276
    // Очереди очистятся автоматически по FOREIGN KEY
277
    return true;
278
  }
279
280
281 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...
282
    // $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...
283
    $si_user_id = idval($ui_user_id);
284
    $si_planet_type = intval($ui_planet_type);
285
286
    // Лочим запись-родителя - если она есть и еще не залочена
287
    $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...
288
289
    return is_array($record_list) ? count($record_list) : 0;
290
    // $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...
291
    // 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...
292
  }
293
294
  public static function db_planet_list_resources_by_owner() {
295
    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;");
296
  }
297
298
}
299