We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Total Complexity | 43 |
| Total Lines | 385 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Complex classes like AbstractMenu often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use AbstractMenu, and based on these observations, apply Extract Interface, too.
| 1 | <?php declare(strict_types=1); |
||
| 9 | class AbstractMenu { |
||
| 10 | |||
| 11 | public static function headquarters(int $locationTypeID): void { |
||
| 12 | $gameID = Smr\Session::getInstance()->getGameID(); |
||
| 13 | |||
| 14 | $links = []; |
||
| 15 | $location = SmrLocation::getLocation($gameID, $locationTypeID); |
||
| 16 | if ($location->isHQ()) { |
||
| 17 | $links[] = ['government.php', 'Government']; |
||
| 18 | $links[] = ['military_payment_claim.php', 'Claim Military Payment']; |
||
| 19 | } elseif ($location->isUG()) { |
||
| 20 | $links[] = ['underground.php', 'Underground']; |
||
| 21 | } else { |
||
| 22 | throw new Exception('Location is not HQ or UG: ' . $location->getName()); |
||
| 23 | } |
||
| 24 | |||
| 25 | // No bounties in Semi Wars games |
||
| 26 | if (!SmrGame::getGame($gameID)->isGameType(SmrGame::GAME_TYPE_SEMI_WARS)) { |
||
| 27 | $links[] = ['bounty_claim.php', 'Claim Bounty']; |
||
| 28 | $links[] = ['bounty_place.php', 'Place Bounty']; |
||
| 29 | } |
||
| 30 | |||
| 31 | $menuItems = []; |
||
| 32 | foreach ($links as $link) { |
||
| 33 | $container = Page::create($link[0], ['LocationID' => $locationTypeID]); |
||
| 34 | $menuItems[] = [ |
||
| 35 | 'Link' => $container->href(), |
||
| 36 | 'Text' => $link[1], |
||
| 37 | ]; |
||
| 38 | } |
||
| 39 | $template = Smr\Template::getInstance(); |
||
| 40 | $template->assign('MenuItems', $menuItems); |
||
| 41 | } |
||
| 42 | |||
| 43 | public static function planetList(int $alliance_id, int $selected_index): void { |
||
| 44 | $menuItems = []; |
||
| 45 | $menuItems[] = ['Link' => Globals::getPlanetListHREF($alliance_id), 'Text' => 'Defense']; |
||
| 46 | $menuItems[] = ['Link' => Globals::getPlanetListFinancialHREF($alliance_id), 'Text' => 'Financial']; |
||
| 47 | // make the selected index bold |
||
| 48 | $boldItem =& $menuItems[$selected_index]['Text']; |
||
| 49 | $boldItem = '<span class="bold">' . $boldItem . '</span>'; |
||
| 50 | |||
| 51 | $template = Smr\Template::getInstance(); |
||
| 52 | $template->assign('MenuItems', $menuItems); |
||
| 53 | } |
||
| 54 | |||
| 55 | public static function alliance(int $alliance_id): void { |
||
| 56 | $db = Database::getInstance(); |
||
| 57 | $player = Smr\Session::getInstance()->getPlayer(); |
||
| 58 | |||
| 59 | $in_alliance = ($alliance_id == $player->getAllianceID() || in_array($player->getAccountID(), Globals::getHiddenPlayers())); |
||
| 60 | |||
| 61 | // Some pages are visible to all alliance members |
||
| 62 | $canReadMb = $in_alliance; |
||
| 63 | $canReadMotd = $in_alliance; |
||
| 64 | $canSeePlanetList = $in_alliance; |
||
| 65 | |||
| 66 | // Check if player has permissions through an alliance treaty |
||
| 67 | if (!$in_alliance) { |
||
| 68 | $dbResult = $db->read('SELECT mb_read, mod_read, planet_land FROM alliance_treaties |
||
| 69 | WHERE (alliance_id_1 = ' . $db->escapeNumber($alliance_id) . ' OR alliance_id_1 = ' . $db->escapeNumber($player->getAllianceID()) . ') |
||
| 70 | AND (alliance_id_2 = ' . $db->escapeNumber($alliance_id) . ' OR alliance_id_2 = ' . $db->escapeNumber($player->getAllianceID()) . ') |
||
| 71 | AND game_id = ' . $db->escapeNumber($player->getGameID()) . ' |
||
| 72 | AND (mb_read = 1 OR mod_read = 1 OR planet_land = 1) AND official = \'TRUE\''); |
||
| 73 | if ($dbResult->hasRecord()) { |
||
| 74 | $dbRecord = $dbResult->record(); |
||
| 75 | $canReadMb = $dbRecord->getBoolean('mb_read'); |
||
| 76 | $canReadMotd = $dbRecord->getBoolean('mod_read'); |
||
| 77 | $canSeePlanetList = $dbRecord->getBoolean('planet_land'); |
||
| 78 | } |
||
| 79 | } |
||
| 80 | |||
| 81 | $role_id = $player->getAllianceRole($alliance_id); |
||
| 82 | $dbResult = $db->read('SELECT send_alliance_msg FROM alliance_has_roles WHERE alliance_id = ' . $db->escapeNumber($alliance_id) . ' AND game_id = ' . $db->escapeNumber($player->getGameID()) . ' AND role_id = ' . $db->escapeNumber($role_id)); |
||
| 83 | if ($dbResult->hasRecord()) { |
||
| 84 | $send_alliance_msg = $dbResult->record()->getBoolean('send_alliance_msg'); |
||
| 85 | } else { |
||
| 86 | $send_alliance_msg = false; |
||
| 87 | } |
||
| 88 | |||
| 89 | $menuItems = []; |
||
| 90 | if ($canReadMotd) { |
||
| 91 | $menuItems[] = ['Link' => Globals::getAllianceMotdHREF($alliance_id), 'Text' => 'Message of the Day']; |
||
| 92 | } |
||
| 93 | $menuItems[] = ['Link' => Globals::getAllianceRosterHREF($alliance_id), 'Text' => 'Roster']; |
||
| 94 | if ($send_alliance_msg) { |
||
| 95 | $menuItems[] = ['Link' => Globals::getAllianceMessageHREF($alliance_id), 'Text' => 'Send Message']; |
||
| 96 | } |
||
| 97 | if ($canReadMb) { |
||
| 98 | $menuItems[] = ['Link' => Globals::getAllianceMessageBoardHREF($alliance_id), 'Text' => 'Message Board']; |
||
| 99 | } |
||
| 100 | if ($canSeePlanetList) { |
||
| 101 | $menuItems[] = ['Link' => Globals::getPlanetListHREF($alliance_id), 'Text' => 'Planets']; |
||
| 102 | } |
||
| 103 | if ($in_alliance) { |
||
| 104 | $menuItems[] = ['Link' => Globals::getAllianceForcesHREF($alliance_id), 'Text' => 'Forces']; |
||
| 105 | $menuItems[] = ['Link' => Globals::getAllianceOptionsHREF($alliance_id), 'Text' => 'Options']; |
||
| 106 | } |
||
| 107 | $menuItems[] = ['Link' => Globals::getAllianceListHREF(), 'Text' => 'List Alliances']; |
||
| 108 | $menuItems[] = ['Link' => Globals::getAllianceNewsHREF($alliance_id), 'Text' => 'View News']; |
||
| 109 | |||
| 110 | $template = Smr\Template::getInstance(); |
||
| 111 | $template->assign('MenuItems', $menuItems); |
||
| 112 | } |
||
| 113 | |||
| 114 | public static function galacticPost(): void { |
||
| 127 | } |
||
| 128 | |||
| 129 | public static function historyGames(int $selected_index): void { |
||
| 130 | $menuItems = []; |
||
| 131 | $container = Page::create('history_games.php'); |
||
| 132 | $container->addVar('HistoryDatabase'); |
||
| 133 | $container->addVar('view_game_id'); |
||
| 134 | $container->addVar('game_name'); |
||
| 135 | $menuItems[] = [ |
||
| 136 | 'Link' => $container->href(), |
||
| 137 | 'Text' => 'Game Details', |
||
| 138 | ]; |
||
| 139 | $container = Page::create('history_games_detail.php', $container); |
||
| 140 | $menuItems[] = [ |
||
| 141 | 'Link' => $container->href(), |
||
| 142 | 'Text' => 'Extended Stats', |
||
| 143 | ]; |
||
| 144 | $container = Page::create('history_games_hof.php', $container); |
||
| 145 | $menuItems[] = [ |
||
| 146 | 'Link' => $container->href(), |
||
| 147 | 'Text' => 'Hall of Fame', |
||
| 148 | ]; |
||
| 149 | $container = Page::create('history_games_news.php', $container); |
||
| 150 | $menuItems[] = [ |
||
| 151 | 'Link' => $container->href(), |
||
| 152 | 'Text' => 'Game News', |
||
| 153 | ]; |
||
| 154 | // make the selected index bold |
||
| 155 | $boldItem =& $menuItems[$selected_index]['Text']; |
||
| 156 | $boldItem = '<b>' . $boldItem . '</b>'; |
||
| 157 | |||
| 158 | $template = Smr\Template::getInstance(); |
||
| 159 | $template->assign('MenuItems', $menuItems); |
||
| 160 | } |
||
| 161 | |||
| 162 | public static function messages(): void { |
||
| 163 | $player = Smr\Session::getInstance()->getPlayer(); |
||
| 164 | |||
| 165 | $menuItems = []; |
||
| 166 | $menuItems[] = ['Link' => Globals::getViewMessageBoxesHREF(), 'Text' => 'View Messages']; |
||
| 167 | $menuItems[] = ['Link' => Globals::getSendGlobalMessageHREF(), 'Text' => 'Send Global Message']; |
||
| 168 | if ($player->isOnCouncil()) { |
||
| 169 | $menuItems[] = ['Link' => Globals::getSendCouncilMessageHREF($player->getRaceID()), 'Text' => 'Send Council Message']; |
||
| 170 | } |
||
| 171 | $menuItems[] = ['Link' => Globals::getManageBlacklistHREF(), 'Text' => 'Manage Blacklist']; |
||
| 172 | |||
| 173 | $template = Smr\Template::getInstance(); |
||
| 174 | $template->assign('MenuItems', $menuItems); |
||
| 175 | } |
||
| 176 | |||
| 177 | public static function combatLog(): void { |
||
| 178 | $container = Page::create('combat_log_list.php'); |
||
| 179 | $menuItems = []; |
||
| 180 | |||
| 181 | foreach (CombatLogType::cases() as $type) { |
||
| 182 | $container['action'] = $type; |
||
| 183 | $menuItems[] = ['Link' => $container->href(), 'Text' => $type->name]; |
||
|
|
|||
| 184 | } |
||
| 185 | |||
| 186 | $template = Smr\Template::getInstance(); |
||
| 187 | $template->assign('MenuItems', $menuItems); |
||
| 188 | } |
||
| 189 | |||
| 190 | public static function trader(): void { |
||
| 191 | $player = Smr\Session::getInstance()->getPlayer(); |
||
| 192 | |||
| 193 | $template = Smr\Template::getInstance(); |
||
| 194 | $template->assign('MenuItems', [ |
||
| 195 | ['Link' => Globals::getTraderStatusHREF(), 'Text' => 'Trader Status'], |
||
| 196 | ['Link' => Globals::getPlanetListHREF($player->getAllianceID()), 'Text' => 'Planets'], |
||
| 197 | ['Link' => Globals::getAllianceHREF($player->getAllianceID()), 'Text' => 'Alliance'], |
||
| 198 | ['Link' => Globals::getCouncilHREF(), 'Text' => 'Politics'], |
||
| 199 | ['Link' => Globals::getTraderRelationsHREF(), 'Text' => 'Relations'], |
||
| 200 | ['Link' => Globals::getTraderBountiesHREF(), 'Text' => 'Bounties']]); |
||
| 201 | } |
||
| 202 | |||
| 203 | public static function planet(SmrPlanet $planet): void { |
||
| 204 | $menu_array = []; |
||
| 205 | $menu_array[] = ['Link' => Globals::getPlanetMainHREF(), 'Text' => 'Planet Main']; |
||
| 206 | if ($planet->hasMenuOption('CONSTRUCTION')) { |
||
| 207 | $menu_array[] = ['Link' => Globals::getPlanetConstructionHREF(), 'Text' => 'Construction']; |
||
| 208 | } |
||
| 209 | if ($planet->hasMenuOption('DEFENSE')) { |
||
| 210 | $menu_array[] = ['Link' => Globals::getPlanetDefensesHREF(), 'Text' => 'Defense']; |
||
| 211 | } |
||
| 212 | if ($planet->hasMenuOption('OWNERSHIP')) { |
||
| 213 | $menu_array[] = ['Link' => Globals::getPlanetOwnershipHREF(), 'Text' => 'Ownership']; |
||
| 214 | } |
||
| 215 | if ($planet->hasMenuOption('STOCKPILE')) { |
||
| 216 | $menu_array[] = ['Link' => Globals::getPlanetStockpileHREF(), 'Text' => 'Stockpile']; |
||
| 217 | } |
||
| 218 | if ($planet->hasMenuOption('FINANCE')) { |
||
| 219 | $menu_array[] = ['Link' => Globals::getPlanetFinancesHREF(), 'Text' => 'Financial']; |
||
| 220 | } |
||
| 221 | |||
| 222 | $template = Smr\Template::getInstance(); |
||
| 223 | $template->assign('MenuItems', $menu_array); |
||
| 224 | } |
||
| 225 | |||
| 226 | /* |
||
| 227 | * $active_level1 - the id of the active menu on the first level |
||
| 228 | * $active_level1 - the id of the active menu on the second level |
||
| 229 | */ |
||
| 230 | public static function rankings(int $active_level1 = 0, int $active_level2 = 0): void { |
||
| 231 | |||
| 232 | $menu = []; |
||
| 233 | |||
| 234 | // player rankings |
||
| 235 | $menu_item = []; |
||
| 236 | $menu_item['entry'] = create_link(Page::create('rankings_player_experience.php'), 'Player Rankings', 'nav'); |
||
| 237 | |||
| 238 | $menu_subitem = []; |
||
| 239 | $menu_subitem[] = create_link(Page::create('rankings_player_experience.php'), 'Experience', 'nav'); |
||
| 240 | $menu_subitem[] = create_link(Page::create('rankings_player_profit.php'), 'Profit', 'nav'); |
||
| 241 | $menu_subitem[] = create_link(Page::create('rankings_player_kills.php'), 'Kills', 'nav'); |
||
| 242 | $menu_subitem[] = create_link(Page::create('rankings_player_death.php'), 'Deaths', 'nav'); |
||
| 243 | $menu_subitem[] = create_link(Page::create('rankings_player_assists.php'), 'Assists', 'nav'); |
||
| 244 | $menu_subitem[] = create_link(Page::create('rankings_player_npc_kills.php'), 'NPC Kills', 'nav'); |
||
| 245 | |||
| 246 | $menu_item['submenu'] = $menu_subitem; |
||
| 247 | |||
| 248 | $menu[] = $menu_item; |
||
| 249 | |||
| 250 | // alliance rankings |
||
| 251 | $menu_item = []; |
||
| 252 | $menu_item['entry'] = create_link(Page::create('rankings_alliance_experience.php'), 'Alliance Rankings', 'nav'); |
||
| 253 | |||
| 254 | $menu_subitem = []; |
||
| 255 | $menu_subitem[] = create_link(Page::create('rankings_alliance_experience.php'), 'Experience', 'nav'); |
||
| 256 | $menu_subitem[] = create_link(Page::create('rankings_alliance_profit.php'), 'Profit', 'nav'); |
||
| 257 | $menu_subitem[] = create_link(Page::create('rankings_alliance_kills.php'), 'Kills', 'nav'); |
||
| 258 | $menu_subitem[] = create_link(Page::create('rankings_alliance_death.php'), 'Deaths', 'nav'); |
||
| 259 | $menu_subitem[] = create_link(Page::create('rankings_alliance_vs_alliance.php'), 'Versus', 'nav'); |
||
| 260 | |||
| 261 | $menu_item['submenu'] = $menu_subitem; |
||
| 262 | |||
| 263 | $menu[] = $menu_item; |
||
| 264 | |||
| 265 | // racial rankings |
||
| 266 | $menu_item = []; |
||
| 267 | $menu_item['entry'] = create_link(Page::create('rankings_race.php'), 'Racial Standings', 'nav'); |
||
| 268 | |||
| 269 | $menu_subitem = []; |
||
| 270 | $menu_subitem[] = create_link(Page::create('rankings_race.php'), 'Experience', 'nav'); |
||
| 271 | $menu_subitem[] = create_link(Page::create('rankings_race_kills.php'), 'Kills', 'nav'); |
||
| 272 | $menu_subitem[] = create_link(Page::create('rankings_race_death.php'), 'Deaths', 'nav'); |
||
| 273 | |||
| 274 | $menu_item['submenu'] = $menu_subitem; |
||
| 275 | |||
| 276 | $menu[] = $menu_item; |
||
| 277 | |||
| 278 | // sector rankings |
||
| 279 | $menu_item = []; |
||
| 280 | $menu_item['entry'] = create_link(Page::create('rankings_sector_kill.php'), 'Sector Kills', 'nav'); |
||
| 281 | $menu[] = $menu_item; |
||
| 282 | |||
| 283 | create_sub_menu($menu, $active_level1, $active_level2); |
||
| 284 | } |
||
| 285 | |||
| 286 | public static function bank(): void { |
||
| 287 | $player = Smr\Session::getInstance()->getPlayer(); |
||
| 288 | |||
| 289 | $links = []; |
||
| 290 | $links[] = ['bank_personal.php', 'Personal Account']; |
||
| 291 | if ($player->hasAlliance()) { |
||
| 292 | $links[] = ['bank_alliance.php', 'Alliance Account']; |
||
| 293 | } |
||
| 294 | $links[] = ['bank_anon.php', 'Anonymous Account']; |
||
| 295 | |||
| 296 | $menuItems = []; |
||
| 297 | foreach ($links as $link) { |
||
| 298 | $container = Page::create($link[0]); |
||
| 299 | $menuItems[] = [ |
||
| 300 | 'Link' => $container->href(), |
||
| 301 | 'Text' => $link[1], |
||
| 302 | ]; |
||
| 303 | } |
||
| 304 | |||
| 305 | $template = Smr\Template::getInstance(); |
||
| 306 | $template->assign('MenuItems', $menuItems); |
||
| 307 | } |
||
| 308 | |||
| 309 | public static function council(int $race_id): void { |
||
| 310 | $player = Smr\Session::getInstance()->getPlayer(); |
||
| 311 | $data = ['race_id' => $race_id]; |
||
| 312 | |||
| 313 | $container = Page::create('council_list.php', $data); |
||
| 314 | $menu_items = []; |
||
| 315 | $menu_items[] = [ |
||
| 316 | 'Link' => $container->href(), |
||
| 317 | 'Text' => 'View Council', |
||
| 318 | ]; |
||
| 319 | |||
| 320 | $container = Page::create('council_politics.php', $data); |
||
| 321 | $menu_items[] = [ |
||
| 322 | 'Link' => $container->href(), |
||
| 323 | 'Text' => 'Political Status', |
||
| 324 | ]; |
||
| 325 | |||
| 326 | $container = Page::create('council_send_message.php', $data); |
||
| 327 | $menu_items[] = [ |
||
| 328 | 'Link' => $container->href(), |
||
| 329 | 'Text' => 'Send Message', |
||
| 330 | ]; |
||
| 331 | |||
| 332 | if ($player->getRaceID() == $race_id) { |
||
| 333 | if ($player->isOnCouncil()) { |
||
| 334 | $container = Page::create('council_vote.php'); |
||
| 335 | $menu_items[] = [ |
||
| 336 | 'Link' => $container->href(), |
||
| 337 | 'Text' => 'Voting Center', |
||
| 338 | ]; |
||
| 339 | } |
||
| 340 | if ($player->isPresident()) { |
||
| 341 | $container = Page::create('council_embassy.php'); |
||
| 342 | $menu_items[] = [ |
||
| 343 | 'Link' => $container->href(), |
||
| 344 | 'Text' => 'Embassy', |
||
| 345 | ]; |
||
| 346 | } |
||
| 347 | } |
||
| 348 | |||
| 349 | $template = Smr\Template::getInstance(); |
||
| 350 | $template->assign('MenuItems', $menu_items); |
||
| 351 | } |
||
| 352 | |||
| 353 | public static function bar(): void { |
||
| 354 | $template = Smr\Template::getInstance(); |
||
| 355 | $template->assign('MenuItems', [ |
||
| 356 | ['Link' => Globals::getBarMainHREF(), 'Text' => 'Bar Main'], |
||
| 357 | ['Link' => Globals::getBarLottoPlayHREF(), 'Text' => 'Lotto'], |
||
| 358 | ['Link' => Globals::getBarBlackjackHREF(), 'Text' => 'BlackJack']]); |
||
| 359 | } |
||
| 360 | |||
| 361 | public static function news(int $gameID): void { |
||
| 382 | } |
||
| 383 | |||
| 384 | public static function navigation(AbstractSmrPlayer $player): void { |
||
| 394 | } |
||
| 395 | |||
| 396 | } |
||
| 397 | |||
| 398 | /** |
||
| 399 | * @param array<array<string, mixed>> $menu |
||
| 400 | */ |
||
| 401 | function create_sub_menu(array $menu, int $active_level1, int $active_level2): void { |
||
| 402 | $return = ('<table class="fullwidth center">'); |
||
| 403 | $return .= ('<tr>'); |
||
| 404 | foreach ($menu as $number => $entry) { |
||
| 405 | // insert spacer |
||
| 458 |