We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 26 |
Paths | > 20000 |
Total Lines | 157 |
Code Lines | 81 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 1 | 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 declare(strict_types=1); |
||
34 | public function build(AbstractSmrPlayer $player, Template $template): void { |
||
35 | $sector = $player->getSector(); |
||
36 | |||
37 | // If on a planet, forward to planet_main.php |
||
38 | if ($player->isLandedOnPlanet()) { |
||
39 | (new PlanetMain($this->message, $this->errorMessage))->go(); |
||
40 | } |
||
41 | |||
42 | $template->assign('SpaceView', true); |
||
43 | |||
44 | $template->assign('PageTopic', 'Current Sector: ' . $player->getSectorID() . ' (' . $sector->getGalaxy()->getDisplayName() . ')'); |
||
45 | |||
46 | Menu::navigation($player); |
||
47 | |||
48 | // ******************************************* |
||
49 | // * |
||
50 | // * Sector List |
||
51 | // * |
||
52 | // ******************************************* |
||
53 | |||
54 | // Sector links |
||
55 | $links = []; |
||
56 | $links['Up'] = ['ID' => $sector->getLinkUp()]; |
||
57 | $links['Right'] = ['ID' => $sector->getLinkRight()]; |
||
58 | $links['Down'] = ['ID' => $sector->getLinkDown()]; |
||
59 | $links['Left'] = ['ID' => $sector->getLinkLeft()]; |
||
60 | $links['Warp'] = ['ID' => $sector->getWarp()]; |
||
61 | |||
62 | $unvisited = []; |
||
63 | |||
64 | $db = Database::getInstance(); |
||
65 | $dbResult = $db->read('SELECT sector_id FROM player_visited_sector WHERE sector_id IN (' . $db->escapeArray($links) . ') AND ' . $player->getSQL()); |
||
66 | foreach ($dbResult->records() as $dbRecord) { |
||
67 | $unvisited[$dbRecord->getInt('sector_id')] = true; |
||
68 | } |
||
69 | |||
70 | foreach ($links as $key => $linkArray) { |
||
71 | if ($linkArray['ID'] > 0 && $linkArray['ID'] != $player->getSectorID()) { |
||
72 | if ($player->getLastSectorID() == $linkArray['ID']) { |
||
73 | $class = 'lastVisited'; |
||
74 | } elseif (isset($unvisited[$linkArray['ID']])) { |
||
75 | $class = 'unvisited'; |
||
76 | } else { |
||
77 | $class = 'visited'; |
||
78 | } |
||
79 | $links[$key]['Class'] = $class; |
||
80 | } |
||
81 | } |
||
82 | |||
83 | $template->assign('Sectors', $links); |
||
84 | |||
85 | doTickerAssigns($template, $player, $db); |
||
86 | |||
87 | $this->unreadMissions ??= $player->markMissionsRead(); |
||
88 | $template->assign('UnreadMissions', $this->unreadMissions); |
||
89 | |||
90 | // ******************************************* |
||
91 | // * |
||
92 | // * Force and other Results |
||
93 | // * |
||
94 | // ******************************************* |
||
95 | $game = SmrGame::getGame($player->getGameID()); |
||
96 | if (!$game->hasStarted()) { |
||
97 | $turnsMessage = 'The game will start in ' . format_time($game->getStartTime() - Epoch::time()) . '!'; |
||
98 | } else { |
||
99 | $turnsMessage = $player->getTurnsLevel()->message(); |
||
100 | if ($player->getTurnsLevel() === TurnsLevel::None) { |
||
101 | $turnsMessage .= ' You will gain another turn in ' . format_time($player->getTimeUntilNextTurn()) . '.'; |
||
102 | } |
||
103 | } |
||
104 | if (!empty($turnsMessage)) { |
||
105 | $template->assign('TurnsMessage', $turnsMessage); |
||
106 | } |
||
107 | |||
108 | $protectionMessage = ''; |
||
109 | if ($player->getNewbieTurns()) { |
||
110 | if ($player->getNewbieTurns() < 25) { |
||
111 | $protectionMessage = '<span class="blue">PROTECTION</span>: You are almost out of <span class="green">NEWBIE</span> protection.'; |
||
112 | } else { |
||
113 | $protectionMessage = '<span class="blue">PROTECTION</span>: You are under <span class="green">NEWBIE</span> protection.'; |
||
114 | } |
||
115 | } elseif ($player->hasFederalProtection()) { |
||
116 | $protectionMessage = '<span class="blue">PROTECTION</span>: You are under <span class="blue">FEDERAL</span> protection.'; |
||
117 | } elseif ($sector->offersFederalProtection()) { |
||
118 | $protectionMessage = '<span class="blue">PROTECTION</span>: You are <span class="red">NOT</span> under protection.'; |
||
119 | } |
||
120 | |||
121 | if (!empty($protectionMessage)) { |
||
122 | $template->assign('ProtectionMessage', $protectionMessage); |
||
123 | } |
||
124 | |||
125 | //enableProtectionDependantRefresh($template,$player); |
||
126 | |||
127 | // Do we have an unseen attack message to store in this var? |
||
128 | $dbResult = $db->read('SELECT * FROM sector_message WHERE ' . $player->getSQL()); |
||
129 | if ($dbResult->hasRecord()) { |
||
130 | $this->attackMessage = $dbResult->record()->getString('message'); |
||
131 | $db->write('DELETE FROM sector_message WHERE ' . $player->getSQL()); |
||
132 | } |
||
133 | |||
134 | if ($this->attackMessage !== null) { |
||
135 | checkForAttackMessage($this->attackMessage, $player); |
||
136 | } |
||
137 | if ($this->showForceRefreshMessage) { |
||
138 | $template->assign('ForceRefreshMessage', getForceRefreshMessage($player)); |
||
139 | } |
||
140 | if ($this->missionMessage !== null) { |
||
141 | $template->assign('MissionMessage', $this->missionMessage); |
||
142 | } |
||
143 | if ($this->message !== null) { |
||
144 | $template->assign('VarMessage', bbifyMessage($this->message)); |
||
145 | } |
||
146 | |||
147 | //error msgs take precedence |
||
148 | if ($this->errorMessage !== null) { |
||
149 | $template->assign('ErrorMessage', $this->errorMessage); |
||
150 | } |
||
151 | |||
152 | // ******************************************* |
||
153 | // * |
||
154 | // * Trade Result |
||
155 | // * |
||
156 | // ******************************************* |
||
157 | |||
158 | if ($this->tradeMessage !== null) { |
||
159 | $template->assign('TradeMessage', $this->tradeMessage); |
||
160 | } |
||
161 | |||
162 | // ******************************************* |
||
163 | // * |
||
164 | // * Ports |
||
165 | // * |
||
166 | // ******************************************* |
||
167 | |||
168 | if ($sector->hasPort()) { |
||
169 | $port = $sector->getPort(); |
||
170 | $template->assign('PortIsAtWar', $player->getRelation($port->getRaceID()) < RELATIONS_WAR); |
||
171 | } |
||
172 | |||
173 | // ******************************************* |
||
174 | // * |
||
175 | // * Ships |
||
176 | // * |
||
177 | // ******************************************* |
||
178 | $otherPlayers = $sector->getOtherTraders($player); |
||
179 | $visiblePlayers = []; |
||
180 | $cloakedPlayers = []; |
||
181 | foreach ($otherPlayers as $accountID => $otherPlayer) { |
||
182 | if ($player->canSee($otherPlayer)) { |
||
183 | $visiblePlayers[$accountID] = $otherPlayer; |
||
184 | } else { |
||
185 | $cloakedPlayers[$accountID] = $otherPlayer; |
||
186 | } |
||
187 | } |
||
188 | $template->assign('VisiblePlayers', $visiblePlayers); |
||
189 | $template->assign('CloakedPlayers', $cloakedPlayers); |
||
190 | $template->assign('SectorPlayersLabel', 'Ships'); |
||
191 | } |
||
229 |