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

DBStaticFleetMissile   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 42
ccs 0
cts 27
cp 0
rs 10
wmc 3
lcom 0
cbo 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A db_missile_insert() 0 15 1
A db_missile_delete() 0 8 1
A db_missile_list_by_arrival() 0 5 1
1
<?php
2
3
namespace DBStatic;
4
use classSupernova;
5
use mysqli_result;
6
7
class DBStaticFleetMissile {
8
9
  public static function db_missile_insert($target_coord, $user, $planetrow, $arrival, $fleet_ship_count, $target_structure) {
10
    classSupernova::$db->doInsertSet(TABLE_MISSILES, array(
11
      'fleet_target_owner' => $target_coord['id_owner'],
12
      'fleet_end_galaxy'   => $target_coord['galaxy'],
13
      'fleet_end_system'   => $target_coord['system'],
14
      'fleet_end_planet'   => $target_coord['planet'],
15
      'fleet_owner'        => $user['id'],
16
      'fleet_start_galaxy' => $planetrow['galaxy'],
17
      'fleet_start_system' => $planetrow['system'],
18
      'fleet_start_planet' => $planetrow['planet'],
19
      'fleet_end_time'     => $arrival,
20
      'fleet_amount'       => $fleet_ship_count,
21
      'primaer'            => $target_structure,
22
    ));
23
  }
24
25
26
  /**
27
   * @param $fleetDbId
28
   */
29
  public static function db_missile_delete($fleetDbId) {
30
    classSupernova::$gc->db->doDeleteRow(
0 ignored issues
show
Bug introduced by
The method doDeleteRow 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...
31
      TABLE_MISSILES,
32
      array(
33
        'id' => $fleetDbId,
34
      )
35
    );
36
  }
37
38
  /**
39
   * @return array|bool|mysqli_result|null
40
   */
41
  public static function db_missile_list_by_arrival() {
42
    $iraks = classSupernova::$db->doSelect("SELECT * FROM `{{iraks}}` WHERE `fleet_end_time` <= " . SN_TIME_NOW . " FOR UPDATE;");
43
44
    return $iraks;
45
  }
46
47
48
}