Conditions | 16 |
Paths | 96 |
Total Lines | 80 |
Code Lines | 46 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php /** @noinspection PhpUnnecessaryCurlyVarSyntaxInspection, PhpCastIsUnnecessaryInspection, PhpDeprecationInspection */ |
||
59 | public function __construct($fleetRow, $eventType) { |
||
60 | if (empty(self::$sn_groups_mission)) { |
||
61 | self::$sn_groups_mission = sn_get_groups('missions'); |
||
62 | } |
||
63 | |||
64 | $this->fleet = $fleetRow; |
||
65 | $this->event = $eventType; |
||
66 | |||
67 | $this->srcPlanetOwnerId = $fleetRow[self::F_FLEET_OWNER_ID]; |
||
68 | |||
69 | $this->missionId = (int)$this->fleet[FleetDispatcher::F_FLEET_MISSION]; |
||
70 | $this->missionInfoNew = self::$MISSIONS[$this->missionId]; |
||
71 | |||
72 | $this->eventTimeStamp = (int)$this->fleet[$this->event === EVENT_FLT_ARRIVE ? 'fleet_start_time' : |
||
73 | ($this->event === EVENT_FLT_ACCOMPLISH ? 'fleet_end_stay' : /* EVENT_FLT_RETURN */ |
||
74 | 'fleet_end_time')]; |
||
75 | |||
76 | /** @var Fleet $fleetObject */ |
||
77 | $fleetObject = (object)$this->fleet; |
||
78 | |||
79 | // Always locking flying fleet and fleet owner |
||
80 | $this->userIdsToLock = [(int)$fleetObject->fleet_owner ?: 0 => true,]; |
||
|
|||
81 | $this->fleetIdsToLock = [(int)$fleetObject->fleet_id => true,]; |
||
82 | $this->planetIdsToLock = []; |
||
83 | |||
84 | // Some locks make sense only on specific event types |
||
85 | if ($this->event === EVENT_FLT_RETURN) { |
||
86 | // There is no means or ways how returning fleet can influence other planet(s) then starting one |
||
87 | $isLockSource = true; |
||
88 | } else { |
||
89 | // Locking destination planet always |
||
90 | // There are no means or sense to make a mission which does not affect destination planet |
||
91 | $this->getDstPlanetRowFromFleet(); |
||
92 | // Locking dest planet |
||
93 | $this->planetIdsToLock[$this->dstPlanetId] = true; |
||
94 | // Locking destination planet always implies locking destination user |
||
95 | // Locking planet owner ID |
||
96 | $this->userIdsToLock[$this->dstPlanetOwnerId] = true; |
||
97 | |||
98 | // If the fleet is a part of existing fleet group - locking also fleets in group and their respected owners |
||
99 | // Only doing it for EVENT_FLT_ARRIVE - currently no other event types does trigger fleet group actions |
||
100 | if (!empty($fleetObject->fleet_group) && $this->event === EVENT_FLT_ARRIVE) { |
||
101 | $fleetGroupId = (int)$fleetObject->fleet_group; |
||
102 | foreach (DbFleetStatic::db_fleet_list("`fleet_group` = {$fleetGroupId}") as $fleetInGroup) { |
||
103 | $this->userIdsToLock[(int)$fleetInGroup[self::F_FLEET_OWNER_ID] ?: 0] = true; |
||
104 | $this->fleetIdsToLock[(int)$fleetInGroup[self::F_FLEET_ID] ?: 0] = true; |
||
105 | } |
||
106 | } |
||
107 | |||
108 | // We may need to lock source planet/user for some extra info such as planet name/username, coordinates etc |
||
109 | $isLockSource = !empty($this->missionInfoNew[self::IS_LOCK_SOURCE]); |
||
110 | } |
||
111 | |||
112 | if ($isLockSource) { |
||
113 | $this->getSrcPlanetRowFromFleet(); |
||
114 | $this->planetIdsToLock[$this->srcPlanetId] = true; |
||
115 | $this->userIdsToLock[$this->srcPlanetOwnerId] = true; |
||
116 | } |
||
117 | |||
118 | if (!empty($this->missionInfoNew[self::IS_ATTACK])) { |
||
119 | $fleetsOnHold = DbFleetStatic::fleet_list_on_hold( |
||
120 | $fleetObject->fleet_end_galaxy, |
||
121 | $fleetObject->fleet_end_system, |
||
122 | $fleetObject->fleet_end_planet, |
||
123 | $fleetObject->fleet_end_type, |
||
124 | $this->eventTimeStamp |
||
125 | ); |
||
126 | foreach ($fleetsOnHold as $aFleet) { |
||
127 | $this->userIdsToLock[(int)$aFleet[self::F_FLEET_OWNER_ID] ?: 0] = true; |
||
128 | $this->fleetIdsToLock[(int)$aFleet[self::F_FLEET_ID] ?: 0] = true; |
||
129 | } |
||
130 | } |
||
131 | |||
132 | unset($this->userIdsToLock[0]); |
||
133 | unset($this->planetIdsToLock[0]); |
||
134 | unset($this->fleetIdsToLock[0]); |
||
135 | |||
136 | $this->userIdsToLock = array_keys($this->userIdsToLock); |
||
137 | $this->planetIdsToLock = array_keys($this->planetIdsToLock); |
||
138 | $this->fleetIdsToLock = array_keys($this->fleetIdsToLock); |
||
139 | } |
||
272 |
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..