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