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

V2UnitList   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 7
Bugs 1 Features 3
Metric Value
c 7
b 1
f 3
dl 0
loc 30
ccs 0
cts 22
cp 0
rs 10
wmc 6
lcom 1
cbo 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 11 3
A loadFromContainer() 0 3 1
A unitAdd() 0 10 2
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