We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Total Complexity | 50 |
| Total Lines | 360 |
| 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); |
||
| 6 | class AbstractMenu { |
||
| 7 | |||
| 8 | public static function headquarters() { |
||
| 9 | global $var, $template; |
||
| 10 | |||
| 11 | $links = []; |
||
| 12 | $location = SmrLocation::getLocation($var['LocationID']); |
||
| 13 | if ($location->isHQ()) { |
||
| 14 | $links[] = ['government.php', 'Government']; |
||
| 15 | $links[] = ['military_payment_claim.php', 'Claim Military Payment']; |
||
| 16 | } elseif ($location->isUG()) { |
||
| 17 | $links[] = ['underground.php', 'Underground']; |
||
| 18 | } else { |
||
| 19 | throw new Exception("Location is not HQ or UG: " . $location->getName()); |
||
| 20 | } |
||
| 21 | $links[] = ['bounty_claim.php', 'Claim Bounty']; |
||
| 22 | $links[] = ['bounty_place.php', 'Place Bounty']; |
||
| 23 | |||
| 24 | $menuItems = []; |
||
| 25 | $container = create_container('skeleton.php'); |
||
| 26 | $container['LocationID'] = $var['LocationID']; |
||
| 27 | foreach ($links as $link) { |
||
| 28 | $container['body'] = $link[0]; |
||
| 29 | $menuItems[] = [ |
||
| 30 | 'Link' => SmrSession::getNewHREF($container), |
||
| 31 | 'Text' => $link[1], |
||
| 32 | ]; |
||
| 33 | } |
||
| 34 | $template->assign('MenuItems', $menuItems); |
||
| 35 | } |
||
| 36 | |||
| 37 | public static function planet_list($alliance_id, $selected_index) { |
||
| 38 | global $template; |
||
| 39 | |||
| 40 | $menuItems = array(); |
||
| 41 | $menuItems[] = array('Link'=>Globals::getPlanetListHREF($alliance_id), 'Text'=>'Defense'); |
||
| 42 | $menuItems[] = array('Link'=>Globals::getPlanetListFinancialHREF($alliance_id), 'Text'=>'Financial'); |
||
| 43 | // make the selected index bold |
||
| 44 | $boldItem =& $menuItems[$selected_index]['Text']; |
||
| 45 | $boldItem = '<span class="bold">' . $boldItem . '</span>'; |
||
| 46 | $template->assign('MenuItems', $menuItems); |
||
| 47 | } |
||
| 48 | |||
| 49 | public static function alliance($alliance_id = null, $alliance_leader_id = FALSE) { |
||
|
|
|||
| 50 | global $player, $template, $db; |
||
| 51 | |||
| 52 | if ($alliance_id) { |
||
| 53 | $in_alliance = ($alliance_id == $player->getAllianceID()); |
||
| 54 | } else { |
||
| 55 | $in_alliance = $player->hasAlliance(); |
||
| 56 | } |
||
| 57 | if (!$in_alliance) { |
||
| 58 | $db->query('SELECT mb_read, mod_read, planet_land FROM alliance_treaties |
||
| 59 | WHERE (alliance_id_1 = ' . $db->escapeNumber($alliance_id) . ' OR alliance_id_1 = ' . $db->escapeNumber($player->getAllianceID()) . ') |
||
| 60 | AND (alliance_id_2 = ' . $db->escapeNumber($alliance_id) . ' OR alliance_id_2 = ' . $db->escapeNumber($player->getAllianceID()) . ') |
||
| 61 | AND game_id = ' . $db->escapeNumber($player->getGameID()) . ' |
||
| 62 | AND (mb_read = 1 OR mod_read = 1 OR planet_land = 1) AND official = \'TRUE\''); |
||
| 63 | if ($db->nextRecord()) { |
||
| 64 | $mbRead = $db->getBoolean('mb_read'); |
||
| 65 | $modRead = $db->getBoolean('mod_read'); |
||
| 66 | $planetLand = $db->getBoolean('planet_land'); |
||
| 67 | } else { |
||
| 68 | $mbRead = FALSE; |
||
| 69 | $modRead = FALSE; |
||
| 70 | $planetLand = FALSE; |
||
| 71 | } |
||
| 72 | } |
||
| 73 | |||
| 74 | $role_id = $player->getAllianceRole($alliance_id); |
||
| 75 | $db->query('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)); |
||
| 76 | if ($db->nextRecord()) { |
||
| 77 | $send_alliance_msg = $db->getBoolean('send_alliance_msg'); |
||
| 78 | } else { |
||
| 79 | $send_alliance_msg = false; |
||
| 80 | } |
||
| 81 | |||
| 82 | $menuItems = array(); |
||
| 83 | if ($in_alliance || in_array($player->getAccountID(), Globals::getHiddenPlayers()) || $modRead) { |
||
| 84 | $menuItems[] = array('Link'=>Globals::getAllianceMotdHREF($alliance_id), 'Text'=>'Message of the Day'); |
||
| 85 | } |
||
| 86 | $menuItems[] = array('Link'=>Globals::getAllianceRosterHREF($alliance_id), 'Text'=>'Roster'); |
||
| 87 | if ($send_alliance_msg || in_array($player->getAccountID(), Globals::getHiddenPlayers())) { |
||
| 88 | $menuItems[] = array('Link'=>Globals::getAllianceMessageHREF($alliance_id), 'Text'=>'Send Message'); |
||
| 89 | } |
||
| 90 | if ($in_alliance || in_array($player->getAccountID(), Globals::getHiddenPlayers()) || $mbRead) { |
||
| 91 | $menuItems[] = array('Link'=>Globals::getAllianceMessageBoardHREF($alliance_id), 'Text'=>'Message Board'); |
||
| 92 | } |
||
| 93 | if ($in_alliance || in_array($player->getAccountID(), Globals::getHiddenPlayers()) || $planetLand) { |
||
| 94 | $menuItems[] = array('Link'=>Globals::getPlanetListHREF($alliance_id), 'Text'=>'Planets'); |
||
| 95 | } |
||
| 96 | if ($in_alliance || in_array($player->getAccountID(), Globals::getHiddenPlayers())) { |
||
| 97 | $menuItems[] = array('Link'=>Globals::getAllianceForcesHREF($alliance_id), 'Text'=>'Forces'); |
||
| 98 | $menuItems[] = array('Link'=>Globals::getAllianceOptionsHREF($alliance_id), 'Text'=>'Options'); |
||
| 99 | } |
||
| 100 | $menuItems[] = array('Link'=>Globals::getAllianceListHREF(), 'Text'=>'List Alliances'); |
||
| 101 | $menuItems[] = array('Link'=>Globals::getAllianceNewsHREF($alliance_id ? $alliance_id : $player->getAllianceID()), 'Text'=>'View News'); |
||
| 102 | |||
| 103 | $template->assign('MenuItems', $menuItems); |
||
| 104 | } |
||
| 105 | |||
| 106 | public static function galactic_post() { |
||
| 107 | global $template, $player; |
||
| 108 | $menuItems = array(); |
||
| 109 | $menuItems[] = array('Link'=>SmrSession::getNewHREF(create_container('galactic_post_current.php')), 'Text'=>'Current Edition'); |
||
| 110 | $menuItems[] = array('Link'=>SmrSession::getNewHREF(create_container('skeleton.php', 'galactic_post_past.php')), 'Text'=>'Past Editions'); |
||
| 111 | $menuItems[] = array('Link'=>SmrSession::getNewHREF(create_container('skeleton.php', 'galactic_post_write_article.php')), 'Text'=>'Write an article'); |
||
| 112 | if ($player->isGPEditor()) { |
||
| 113 | $menuItems[] = array('Link'=>SmrSession::getNewHREF(create_container('skeleton.php', 'galactic_post.php')), 'Text'=>'Editor Options'); |
||
| 114 | } |
||
| 115 | $template->assign('MenuItems', $menuItems); |
||
| 116 | } |
||
| 117 | |||
| 118 | public static function history_games($selected_index) { |
||
| 140 | } |
||
| 141 | |||
| 142 | public static function messages() { |
||
| 153 | } |
||
| 154 | |||
| 155 | public static function combat_log() { |
||
| 156 | global $template; |
||
| 157 | |||
| 158 | $container = create_container('skeleton.php', 'combat_log_list.php'); |
||
| 159 | $menuItems = array(); |
||
| 160 | |||
| 161 | $container['action'] = COMBAT_LOG_PERSONAL; |
||
| 162 | $menuItems[] = array('Link'=>SmrSession::getNewHREF($container), 'Text'=>'Personal'); |
||
| 163 | $container['action'] = COMBAT_LOG_ALLIANCE; |
||
| 164 | $menuItems[] = array('Link'=>SmrSession::getNewHREF($container), 'Text'=>'Alliance'); |
||
| 165 | $container['action'] = COMBAT_LOG_FORCE; |
||
| 166 | $menuItems[] = array('Link'=>SmrSession::getNewHREF($container), 'Text'=>'Force'); |
||
| 167 | $container['action'] = COMBAT_LOG_PORT; |
||
| 168 | $menuItems[] = array('Link'=>SmrSession::getNewHREF($container), 'Text'=>'Port'); |
||
| 169 | $container['action'] = COMBAT_LOG_PLANET; |
||
| 170 | $menuItems[] = array('Link'=>SmrSession::getNewHREF($container), 'Text'=>'Planet'); |
||
| 171 | $container['action'] = COMBAT_LOG_SAVED; |
||
| 172 | $menuItems[] = array('Link'=>SmrSession::getNewHREF($container), 'Text'=>'Saved'); |
||
| 173 | |||
| 174 | $template->assign('MenuItems', $menuItems); |
||
| 175 | } |
||
| 176 | |||
| 177 | public static function trader() { |
||
| 178 | global $player, $template; |
||
| 179 | $template->assign('MenuItems', array( |
||
| 180 | array('Link'=>Globals::getTraderStatusHREF(), 'Text'=>'Trader Status'), |
||
| 181 | array('Link'=>Globals::getPlanetListHREF($player->getAllianceID()), 'Text'=>'Planets'), |
||
| 182 | array('Link'=>Globals::getAllianceHREF($player->getAllianceID()), 'Text'=>'Alliance'), |
||
| 183 | array('Link'=>Globals::getCouncilHREF(), 'Text'=>'Politics'), |
||
| 184 | array('Link'=>Globals::getTraderRelationsHREF(), 'Text'=>'Relations'), |
||
| 185 | array('Link'=>Globals::getTraderBountiesHREF(), 'Text'=>'Bounties'))); |
||
| 186 | } |
||
| 187 | |||
| 188 | public static function planet($planet) { |
||
| 210 | } |
||
| 211 | |||
| 212 | /* |
||
| 213 | * $active_level1 - the id of the active menu on the first level |
||
| 214 | * $active_level1 - the id of the active menu on the second level |
||
| 215 | */ |
||
| 216 | public static function rankings($active_level1 = 0, $active_level2 = 0) { |
||
| 217 | |||
| 218 | $menu = array(); |
||
| 219 | |||
| 220 | // player rankings |
||
| 221 | $menu_item = array(); |
||
| 222 | $menu_item['entry'] = create_link(create_container('skeleton.php', 'rankings_player_experience.php'), 'Player Rankings', 'nav'); |
||
| 223 | |||
| 224 | $menu_subitem = array(); |
||
| 225 | $menu_subitem[] = create_link(create_container('skeleton.php', 'rankings_player_experience.php'), 'Experience', 'nav'); |
||
| 226 | $menu_subitem[] = create_link(create_container('skeleton.php', 'rankings_player_profit.php'), 'Profit', 'nav'); |
||
| 227 | $menu_subitem[] = create_link(create_container('skeleton.php', 'rankings_player_kills.php'), 'Kills', 'nav'); |
||
| 228 | $menu_subitem[] = create_link(create_container('skeleton.php', 'rankings_player_death.php'), 'Deaths', 'nav'); |
||
| 229 | $menu_subitem[] = create_link(create_container('skeleton.php', 'rankings_player_assists.php'), 'Assists', 'nav'); |
||
| 230 | |||
| 231 | $menu_item['submenu'] = $menu_subitem; |
||
| 232 | |||
| 233 | $menu[] = $menu_item; |
||
| 234 | |||
| 235 | // alliance rankings |
||
| 236 | $menu_item = array(); |
||
| 237 | $menu_item['entry'] = create_link(create_container('skeleton.php', 'rankings_alliance_experience.php'), 'Alliance Rankings', 'nav'); |
||
| 238 | |||
| 239 | $menu_subitem = array(); |
||
| 240 | $menu_subitem[] = create_link(create_container('skeleton.php', 'rankings_alliance_experience.php'), 'Experience', 'nav'); |
||
| 241 | $menu_subitem[] = create_link(create_container('skeleton.php', 'rankings_alliance_profit.php'), 'Profit', 'nav'); |
||
| 242 | $menu_subitem[] = create_link(create_container('skeleton.php', 'rankings_alliance_kills.php'), 'Kills', 'nav'); |
||
| 243 | $menu_subitem[] = create_link(create_container('skeleton.php', 'rankings_alliance_death.php'), 'Deaths', 'nav'); |
||
| 244 | $menu_subitem[] = create_link(create_container('skeleton.php', 'rankings_alliance_vs_alliance.php'), 'Versus', 'nav'); |
||
| 245 | |||
| 246 | $menu_item['submenu'] = $menu_subitem; |
||
| 247 | |||
| 248 | $menu[] = $menu_item; |
||
| 249 | |||
| 250 | // racial rankings |
||
| 251 | $menu_item = array(); |
||
| 252 | $menu_item['entry'] = create_link(create_container('skeleton.php', 'rankings_race.php'), 'Racial Standings', 'nav'); |
||
| 253 | |||
| 254 | $menu_subitem = array(); |
||
| 255 | $menu_subitem[] = create_link(create_container('skeleton.php', 'rankings_race.php'), 'Experience', 'nav'); |
||
| 256 | $menu_subitem[] = create_link(create_container('skeleton.php', 'rankings_race_kills.php'), 'Kills', 'nav'); |
||
| 257 | $menu_subitem[] = create_link(create_container('skeleton.php', 'rankings_race_death.php'), 'Deaths', 'nav'); |
||
| 258 | |||
| 259 | $menu_item['submenu'] = $menu_subitem; |
||
| 260 | |||
| 261 | $menu[] = $menu_item; |
||
| 262 | |||
| 263 | // sector rankings |
||
| 264 | $menu_item = array(); |
||
| 265 | $menu_item['entry'] = create_link(create_container('skeleton.php', 'rankings_sector_kill.php'), 'Sector Kills', 'nav'); |
||
| 266 | $menu[] = $menu_item; |
||
| 267 | |||
| 268 | create_sub_menu($menu, $active_level1, $active_level2); |
||
| 269 | } |
||
| 270 | |||
| 271 | public static function bank() { |
||
| 291 | } |
||
| 292 | |||
| 293 | public static function council($race_id) { |
||
| 294 | global $player, $template; |
||
| 295 | |||
| 296 | $container = create_container('skeleton.php', 'council_list.php'); |
||
| 297 | $menu_items = []; |
||
| 298 | $menu_items[] = [ |
||
| 299 | 'Link' => SmrSession::getNewHREF($container), |
||
| 300 | 'Text' => 'View Council', |
||
| 301 | ]; |
||
| 302 | |||
| 303 | $container = create_container('skeleton.php'); |
||
| 304 | $container['body'] = 'council_politics.php'; |
||
| 305 | $container['race_id'] = $race_id; |
||
| 306 | $menu_items[] = [ |
||
| 307 | 'Link' => SmrSession::getNewHREF($container), |
||
| 308 | 'Text' => 'Political Status', |
||
| 309 | ]; |
||
| 310 | |||
| 311 | $container['body'] = 'council_send_message.php'; |
||
| 312 | $container['race_id'] = $race_id; |
||
| 313 | $menu_items[] = [ |
||
| 314 | 'Link' => SmrSession::getNewHREF($container), |
||
| 315 | 'Text' => 'Send Message', |
||
| 316 | ]; |
||
| 317 | |||
| 318 | if ($player->getRaceID() == $race_id) { |
||
| 319 | if ($player->isOnCouncil()) { |
||
| 320 | $container = create_container('skeleton.php', 'council_vote.php'); |
||
| 321 | $menu_items[] = [ |
||
| 322 | 'Link' => SmrSession::getNewHREF($container), |
||
| 323 | 'Text' => 'Voting Center', |
||
| 324 | ]; |
||
| 325 | } |
||
| 326 | if ($player->isPresident()) { |
||
| 327 | $container = create_container('skeleton.php', 'council_embassy.php'); |
||
| 328 | $menu_items[] = [ |
||
| 329 | 'Link' => SmrSession::getNewHREF($container), |
||
| 330 | 'Text' => 'Embassy', |
||
| 331 | ]; |
||
| 332 | } |
||
| 333 | } |
||
| 334 | |||
| 335 | $template->assign('MenuItems', $menu_items); |
||
| 336 | } |
||
| 337 | |||
| 338 | public static function bar() { |
||
| 339 | global $template; |
||
| 340 | $template->assign('MenuItems', array( |
||
| 341 | array('Link'=>Globals::getBarMainHREF(), 'Text'=>'Bar Main'), |
||
| 342 | array('Link'=>Globals::getBarLottoPlayHREF(), 'Text'=>'Lotto'), |
||
| 343 | array('Link'=>Globals::getBarBlackjackHREF(), 'Text'=>'BlackJack'))); |
||
| 344 | } |
||
| 345 | |||
| 346 | public static function news(Template $template) { |
||
| 356 | } |
||
| 357 | |||
| 358 | public static function navigation(Template $template, AbstractSmrPlayer $player) { |
||
| 366 | } |
||
| 367 | |||
| 368 | } |
||
| 440 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.