Completed
Push — work-fleets ( 451000...e7900f )
by SuperNova.WS
06:16
created

Vector::__construct()   B

Complexity

Conditions 8
Paths 3

Size

Total Lines 12
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
rs 7.7777
cc 8
eloc 10
nc 3
nop 4
1
<?php
2
3
class Vector {
4
5
  public $galaxy = 0;
6
  public $system = 0;
7
  public $planet = 0;
8
  public $type = PT_NONE;
9
10
  /**
11
   * UniverseVector constructor.
12
   *
13
   * @param int|string       $galaxy
14
   * @param int|Vector|array $system
15
   * @param int              $planet
16
   * @param int              $type
17
   */
18
  public function __construct($galaxy = 0, $system = 0, $planet = 0, $type = PT_NONE) {
19
    if(is_string($galaxy) && $galaxy == VECTOR_READ_VECTOR && is_object($system) && $system instanceof Vector) {
20
      $this->readFromVector($system);
21
    } elseif(is_string($galaxy) && $galaxy == VECTOR_READ_PARAMS && is_array($system)) {
22
      $this->readFromParamFleets($system);
23
    } else {
24
      $this->galaxy = $galaxy;
0 ignored issues
show
Documentation Bug introduced by
It seems like $galaxy can also be of type string. However, the property $galaxy is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
25
      $this->system = $system;
26
      $this->planet = $planet;
27
      $this->type = $type;
28
    }
29
  }
30
31
32
  public function readFromParamFleets($planetrow = array()) {
33
    $this->galaxy = sys_get_param_int('galaxy', $planetrow['galaxy']);
34
    $this->system = sys_get_param_int('system', $planetrow['system']);
35
    $this->planet = sys_get_param_int('planet', $planetrow['planet']);
36
    $this->type = sys_get_param_int('planet_type', $planetrow['planet_type']);
37
  }
38
39
  /**
40
   * @param Vector $vector
41
   */
42
  public function readFromVector($vector) {
43
    $this->galaxy = $vector->galaxy;
44
    $this->system = $vector->system;
45
    $this->planet = $vector->planet;
46
    $this->type = $vector->type;
47
  }
48
49
  public function compareWithPlanetRow($planetRow) {
0 ignored issues
show
Unused Code introduced by
The parameter $planetRow 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...
50
51
  }
52
53
}
54