Completed
Push — work-fleets ( b1376e...d6880d )
by SuperNova.WS
11:23
created

V2UnitList::unitAdd()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 8
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 10
ccs 0
cts 10
cp 0
crap 6
rs 9.4285
1
<?php
2
3
namespace V2Unit;
4
5
use Common\IndexedObjectStorage;
6
use Common\V2Location;
7
use DBStatic\DBStaticUnit;
8
9
/**
10
 * Class V2UnitList
11
 *
12
 * @method V2UnitContainer current()
13
 *
14
 * @package V2Unit
15
 */
16
class V2UnitList extends IndexedObjectStorage {
17
18
  public function load(V2Location $location) {
19
    if (!($unitRows = DBStaticUnit::getUnitListByV2Location($location))) {
20
      return;
21
    }
22
23
    $model = \classSupernova::$gc->unitModel;
24
    foreach ($unitRows as $dbId => $unitRow) {
25
      $unit = $model->fromArray($unitRow);
0 ignored issues
show
Bug introduced by
The method fromArray does only exist in V2Unit\V2UnitModel, 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...
26
      $this->attach($unit, intval($unit->snId));
27
    }
28
  }
29
30
  public function loadFromContainer() {
31
32
  }
33
34
  public function unitAdd($snId, $level) {
35
    if($this->indexIsSet($snId)) {
36
      $this->indexGetObject($snId)->$level += $level;
37
    } else {
38
      $unit = \classSupernova::$gc->unitModel->buildContainer();
0 ignored issues
show
Bug introduced by
The method buildContainer does only exist in V2Unit\V2UnitModel, 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
      $unit->snId = $snId;
40
      $unit->level = $level;
41
      $this->attach($unit, $snId);
42
    }
43
  }
44
45
}
46