Issues (1369)

classes/Fleet/MissionData.php (5 issues)

1
<?php
2
/**
3
 * Created by Gorlum 11.10.2017 13:17
4
 */
5
6
namespace Fleet;
7
8
9
use Core\GlobalContainer;
10
11
class MissionData {
12
13
  /**
14
   * @var Fleet $fleetEntity
15
   */
16
  protected $fleetEntity;
17
18
  /** @var array|null $fleet Fleet row from DB */
19
  public $fleet;
20
  /** @var array|null */
21
  public $dstUserRow;
22
  /** @var array|null */
23
  public $dstPlanetRow;
24
  /** @var array|null */
25
  public $fleetOwnerRow;
26
  /** @var array|null */
27
  public $srcPlanetRow;
28
  /** @var array|null */
29
  public $fleet_event;
30
31
  /** @var \General $general */
32
  protected $general;
33
  /** @var \classLocale $lang */
34
  protected $lang;
35
36
  /**
37
   * @param FleetDispatchEvent $fleetEvent
38
   *
39
   * @return static
40
   */
41
  public static function buildFromArray($fleetEvent) {
42
    return new static($fleetEvent);
43
  }
44
45
  /**
46
   * MissionData constructor.
47
   *
48
   * @param ?FleetDispatchEvent $fleetEvent
49
   */
50
  public function __construct($fleetEvent) {
51
    $this->general = $this->getDefaultGeneral();
52
    $this->lang    = $this->getDefaultLang();
53
54
    $this->fromMissionArray($fleetEvent);
55
  }
56
57
  /**
58
   * @param GlobalContainer $gc
59
   */
60
  public function changeGc($gc) {
61
    $this->general = $gc->general;
62
  }
63
64
  /**
65
   * @param ?FleetDispatchEvent $fleetEvent
66
   */
67
  protected function fromMissionArray($fleetEvent) {
68
    $this->fleet         = $fleetEvent->fleet;
69
    $this->dstUserRow    = $fleetEvent->dstPlanetOwnerId ? db_user_by_id($fleetEvent->dstPlanetOwnerId) : null;
0 ignored issues
show
Deprecated Code introduced by
The function db_user_by_id() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

69
    $this->dstUserRow    = $fleetEvent->dstPlanetOwnerId ? /** @scrutinizer ignore-deprecated */ db_user_by_id($fleetEvent->dstPlanetOwnerId) : null;
Loading history...
70
    $this->dstPlanetRow  = $fleetEvent->dstPlanetId ? $fleetEvent->dstPlanetRow : null;
0 ignored issues
show
Documentation Bug introduced by
It seems like $fleetEvent->dstPlanetId...nt->dstPlanetRow : null can also be of type boolean. However, the property $dstPlanetRow is declared as type array|null. 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...
71
    $this->fleetOwnerRow = $fleetEvent->fleetOwnerId ? db_user_by_id($fleetEvent->fleet['fleet_owner']) : null;
0 ignored issues
show
Deprecated Code introduced by
The function db_user_by_id() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

71
    $this->fleetOwnerRow = $fleetEvent->fleetOwnerId ? /** @scrutinizer ignore-deprecated */ db_user_by_id($fleetEvent->fleet['fleet_owner']) : null;
Loading history...
72
    $this->srcPlanetRow  = $fleetEvent->srcPlanetId ? $fleetEvent->srcPlanetRow : null;
0 ignored issues
show
Documentation Bug introduced by
It seems like $fleetEvent->srcPlanetId...nt->srcPlanetRow : null can also be of type boolean. However, the property $srcPlanetRow is declared as type array|null. 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...
73
    $this->fleet_event   = $fleetEvent->event;
0 ignored issues
show
Documentation Bug introduced by
It seems like $fleetEvent->event of type string is incompatible with the declared type array|null of property $fleet_event.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
74
75
    $this->fleetEntity = new Fleet();
76
    $this->fleetEntity->dbLoadRecord($this->fleet['fleet_id']);
77
  }
78
79
  protected function dbFleetFindRecordById($fleetId) {
80
    return RecordFleet::findById($fleetId);
81
  }
82
83
  /**
84
   * @return \classLocale
85
   */
86
  protected function getDefaultLang() {
87
    return \SN::$lang;
88
  }
89
90
  /**
91
   * @return \General
92
   */
93
  protected function getDefaultGeneral() {
94
    return \SN::$gc->general;
95
  }
96
97
}
98