We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Total Complexity | 48 |
Total Lines | 334 |
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; |
||
10 | $menu_items = []; |
||
11 | $container = create_container('skeleton.php'); |
||
12 | $container['LocationID'] = $var['LocationID']; |
||
13 | |||
14 | $location = SmrLocation::getLocation($var['LocationID']); |
||
15 | if ($location->isHQ()) { |
||
16 | $container['body'] = 'government.php'; |
||
17 | $menu_items[] = create_link($container, 'Government', 'nav'); |
||
18 | $container['body'] = 'military_payment_claim.php'; |
||
19 | $menu_items[] = create_link($container, 'Claim Military Payment', 'nav'); |
||
20 | } elseif ($location->isUG()) { |
||
21 | $container['body'] = 'underground.php'; |
||
22 | $menu_items[] = create_link($container, 'Underground', 'nav'); |
||
23 | } else { |
||
24 | throw new Exception("Location is not HQ or UG: " . $location->getName()); |
||
25 | } |
||
26 | $container['body'] = 'bounty_claim.php'; |
||
27 | $menu_items[] = create_link($container, 'Claim Bounty', 'nav'); |
||
28 | $container['body'] = 'bounty_place.php'; |
||
29 | $menu_items[] = create_link($container, 'Place a Bounty', 'nav'); |
||
30 | create_menu($menu_items); |
||
31 | } |
||
32 | |||
33 | public static function planet_list($alliance_id, $selected_index) { |
||
34 | global $template; |
||
35 | |||
36 | $menuItems = array(); |
||
37 | $menuItems[] = array('Link'=>Globals::getPlanetListHREF($alliance_id), 'Text'=>'Defense'); |
||
38 | $menuItems[] = array('Link'=>Globals::getPlanetListFinancialHREF($alliance_id), 'Text'=>'Financial'); |
||
39 | // make the selected index bold |
||
40 | $boldItem =& $menuItems[$selected_index]['Text']; |
||
41 | $boldItem = '<span class="bold">' . $boldItem . '</span>'; |
||
42 | $template->assign('MenuItems', $menuItems); |
||
43 | } |
||
44 | |||
45 | public static function alliance($alliance_id = null, $alliance_leader_id = FALSE) { |
||
|
|||
46 | global $player, $template, $db; |
||
47 | |||
48 | if ($alliance_id) { |
||
49 | $in_alliance = ($alliance_id == $player->getAllianceID()); |
||
50 | } else { |
||
51 | $in_alliance = $player->hasAlliance(); |
||
52 | } |
||
53 | if (!$in_alliance) { |
||
54 | $db->query('SELECT mb_read, mod_read, planet_land FROM alliance_treaties |
||
55 | WHERE (alliance_id_1 = ' . $db->escapeNumber($alliance_id) . ' OR alliance_id_1 = ' . $db->escapeNumber($player->getAllianceID()) . ') |
||
56 | AND (alliance_id_2 = ' . $db->escapeNumber($alliance_id) . ' OR alliance_id_2 = ' . $db->escapeNumber($player->getAllianceID()) . ') |
||
57 | AND game_id = ' . $db->escapeNumber($player->getGameID()) . ' |
||
58 | AND (mb_read = 1 OR mod_read = 1 OR planet_land = 1) AND official = \'TRUE\''); |
||
59 | if ($db->nextRecord()) { |
||
60 | $mbRead = $db->getBoolean('mb_read'); |
||
61 | $modRead = $db->getBoolean('mod_read'); |
||
62 | $planetLand = $db->getBoolean('planet_land'); |
||
63 | } else { |
||
64 | $mbRead = FALSE; |
||
65 | $modRead = FALSE; |
||
66 | $planetLand = FALSE; |
||
67 | } |
||
68 | } |
||
69 | |||
70 | $role_id = $player->getAllianceRole($alliance_id); |
||
71 | $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)); |
||
72 | if ($db->nextRecord()) { |
||
73 | $send_alliance_msg = $db->getBoolean('send_alliance_msg'); |
||
74 | } else { |
||
75 | $send_alliance_msg = false; |
||
76 | } |
||
77 | |||
78 | $menuItems = array(); |
||
79 | if ($in_alliance || in_array($player->getAccountID(), Globals::getHiddenPlayers()) || $modRead) { |
||
80 | $menuItems[] = array('Link'=>Globals::getAllianceMotdHREF($alliance_id), 'Text'=>'Message of the Day'); |
||
81 | } |
||
82 | $menuItems[] = array('Link'=>Globals::getAllianceRosterHREF($alliance_id), 'Text'=>'Roster'); |
||
83 | if ($send_alliance_msg || in_array($player->getAccountID(), Globals::getHiddenPlayers())) { |
||
84 | $menuItems[] = array('Link'=>Globals::getAllianceMessageHREF($alliance_id), 'Text'=>'Send Message'); |
||
85 | } |
||
86 | if ($in_alliance || in_array($player->getAccountID(), Globals::getHiddenPlayers()) || $mbRead) { |
||
87 | $menuItems[] = array('Link'=>Globals::getAllianceMessageBoardHREF($alliance_id), 'Text'=>'Message Board'); |
||
88 | } |
||
89 | if ($in_alliance || in_array($player->getAccountID(), Globals::getHiddenPlayers()) || $planetLand) { |
||
90 | $menuItems[] = array('Link'=>Globals::getPlanetListHREF($alliance_id), 'Text'=>'Planets'); |
||
91 | } |
||
92 | if ($in_alliance || in_array($player->getAccountID(), Globals::getHiddenPlayers())) { |
||
93 | $menuItems[] = array('Link'=>Globals::getAllianceForcesHREF($alliance_id), 'Text'=>'Forces'); |
||
94 | $menuItems[] = array('Link'=>Globals::getAllianceOptionsHREF($alliance_id), 'Text'=>'Options'); |
||
95 | } |
||
96 | $menuItems[] = array('Link'=>Globals::getAllianceListHREF(), 'Text'=>'List Alliances'); |
||
97 | $menuItems[] = array('Link'=>Globals::getAllianceNewsHREF($alliance_id ? $alliance_id : $player->getAllianceID()), 'Text'=>'View News'); |
||
98 | |||
99 | $template->assign('MenuItems', $menuItems); |
||
100 | } |
||
101 | |||
102 | public static function galactic_post() { |
||
103 | global $template, $player; |
||
104 | $menuItems = array(); |
||
105 | $menuItems[] = array('Link'=>SmrSession::getNewHREF(create_container('galactic_post_current.php')), 'Text'=>'Current Edition'); |
||
106 | $menuItems[] = array('Link'=>SmrSession::getNewHREF(create_container('skeleton.php', 'galactic_post_past.php')), 'Text'=>'Past Editions'); |
||
107 | $menuItems[] = array('Link'=>SmrSession::getNewHREF(create_container('skeleton.php', 'galactic_post_write_article.php')), 'Text'=>'Write an article'); |
||
108 | if ($player->isGPEditor()) { |
||
109 | $menuItems[] = array('Link'=>SmrSession::getNewHREF(create_container('skeleton.php', 'galactic_post.php')), 'Text'=>'Editor Options'); |
||
110 | } |
||
111 | $template->assign('MenuItems', $menuItems); |
||
112 | } |
||
113 | |||
114 | public static function history_games($selected_index) { |
||
115 | global $template, $var; |
||
116 | $menuItems = []; |
||
117 | $container = create_container('skeleton.php', 'history_games.php'); |
||
118 | $container['HistoryDatabase'] = $var['HistoryDatabase']; |
||
119 | $container['view_game_id'] = $var['view_game_id']; |
||
120 | $container['game_name'] = $var['game_name']; |
||
121 | $menuItems[] = ['Link' => SmrSession::getNewHREF($container), |
||
122 | 'Text' => 'Game Details']; |
||
123 | $container['body'] = 'history_games_detail.php'; |
||
124 | $menuItems[] = ['Link' => SmrSession::getNewHREF($container), |
||
125 | 'Text' => 'Extended Stats']; |
||
126 | $container['body'] = 'history_games_hof.php'; |
||
127 | $menuItems[] = ['Link' => SmrSession::getNewHREF($container), |
||
128 | 'Text' => 'Hall of Fame']; |
||
129 | $container['body'] = 'history_games_news.php'; |
||
130 | $menuItems[] = ['Link' => SmrSession::getNewHREF($container), |
||
131 | 'Text' => 'Game News']; |
||
132 | // make the selected index bold |
||
133 | $boldItem =& $menuItems[$selected_index]['Text']; |
||
134 | $boldItem = '<b>' . $boldItem . '</b>'; |
||
135 | $template->assign('MenuItems', $menuItems); |
||
136 | } |
||
137 | |||
138 | public static function messages() { |
||
139 | global $player, $template; |
||
140 | $menuItems = array(); |
||
141 | $menuItems[] = array('Link'=>Globals::getViewMessagesHREF(), 'Text'=>'View Messages'); |
||
142 | $menuItems[] = array('Link'=>Globals::getSendGlobalMessageHREF(), 'Text'=>'Send Global Message'); |
||
143 | if ($player->isOnCouncil()) { |
||
144 | $menuItems[] = array('Link'=>Globals::getSendCouncilMessageHREF($player->getRaceID()), 'Text'=>'Send Council Message'); |
||
145 | } |
||
146 | $menuItems[] = array('Link'=>Globals::getManageBlacklistHREF(), 'Text'=>'Manage Blacklist'); |
||
147 | |||
148 | $template->assign('MenuItems', $menuItems); |
||
149 | } |
||
150 | |||
151 | public static function combat_log() { |
||
152 | global $template; |
||
153 | |||
154 | $container = create_container('skeleton.php', 'combat_log_list.php'); |
||
155 | $menuItems = array(); |
||
156 | |||
157 | $container['action'] = COMBAT_LOG_PERSONAL; |
||
158 | $menuItems[] = array('Link'=>SmrSession::getNewHREF($container), 'Text'=>'Personal'); |
||
159 | $container['action'] = COMBAT_LOG_ALLIANCE; |
||
160 | $menuItems[] = array('Link'=>SmrSession::getNewHREF($container), 'Text'=>'Alliance'); |
||
161 | $container['action'] = COMBAT_LOG_FORCE; |
||
162 | $menuItems[] = array('Link'=>SmrSession::getNewHREF($container), 'Text'=>'Force'); |
||
163 | $container['action'] = COMBAT_LOG_PORT; |
||
164 | $menuItems[] = array('Link'=>SmrSession::getNewHREF($container), 'Text'=>'Port'); |
||
165 | $container['action'] = COMBAT_LOG_PLANET; |
||
166 | $menuItems[] = array('Link'=>SmrSession::getNewHREF($container), 'Text'=>'Planet'); |
||
167 | $container['action'] = COMBAT_LOG_SAVED; |
||
168 | $menuItems[] = array('Link'=>SmrSession::getNewHREF($container), 'Text'=>'Saved'); |
||
169 | |||
170 | $template->assign('MenuItems', $menuItems); |
||
171 | } |
||
172 | |||
173 | public static function trader() { |
||
174 | global $player, $template; |
||
175 | $template->assign('MenuItems', array( |
||
176 | array('Link'=>Globals::getTraderStatusHREF(), 'Text'=>'Trader Status'), |
||
177 | array('Link'=>Globals::getPlanetListHREF($player->getAllianceID()), 'Text'=>'Planets'), |
||
178 | array('Link'=>Globals::getAllianceHREF($player->getAllianceID()), 'Text'=>'Alliance'), |
||
179 | array('Link'=>Globals::getCouncilHREF(), 'Text'=>'Politics'), |
||
180 | array('Link'=>Globals::getTraderRelationsHREF(), 'Text'=>'Relations'), |
||
181 | array('Link'=>Globals::getTraderBountiesHREF(), 'Text'=>'Bounties'))); |
||
182 | } |
||
183 | |||
184 | public static function planet($planet) { |
||
185 | global $template; |
||
186 | |||
187 | $menu_array = array(); |
||
188 | $menu_array[] = array('Link'=>Globals::getPlanetMainHREF(), 'Text'=>'Planet Main'); |
||
189 | if ($planet->hasMenuOption('CONSTRUCTION')) { |
||
190 | $menu_array[] = array('Link'=>Globals::getPlanetConstructionHREF(), 'Text'=>'Construction'); |
||
191 | } |
||
192 | if ($planet->hasMenuOption('DEFENSE')) { |
||
193 | $menu_array[] = array('Link'=>Globals::getPlanetDefensesHREF(), 'Text'=>'Defense'); |
||
194 | } |
||
195 | if ($planet->hasMenuOption('OWNERSHIP')) { |
||
196 | $menu_array[] = array('Link'=>Globals::getPlanetOwnershipHREF(), 'Text'=>'Ownership'); |
||
197 | } |
||
198 | if ($planet->hasMenuOption('STOCKPILE')) { |
||
199 | $menu_array[] = array('Link'=>Globals::getPlanetStockpileHREF(), 'Text'=>'Stockpile'); |
||
200 | } |
||
201 | if ($planet->hasMenuOption('FINANCE')) { |
||
202 | $menu_array[] = array('Link'=>Globals::getPlanetFinancesHREF(), 'Text'=>'Financial'); |
||
203 | } |
||
204 | |||
205 | $template->assign('MenuItems', $menu_array); |
||
206 | } |
||
207 | |||
208 | /* |
||
209 | * $active_level1 - the id of the active menu on the first level |
||
210 | * $active_level1 - the id of the active menu on the second level |
||
211 | */ |
||
212 | public static function rankings($active_level1 = 0, $active_level2 = 0) { |
||
213 | |||
214 | $menu = array(); |
||
215 | |||
216 | // player rankings |
||
217 | $menu_item = array(); |
||
218 | $menu_item['entry'] = create_link(create_container('skeleton.php', 'rankings_player_experience.php'), 'Player Rankings', 'nav'); |
||
219 | |||
220 | $menu_subitem = array(); |
||
221 | $menu_subitem[] = create_link(create_container('skeleton.php', 'rankings_player_experience.php'), 'Experience', 'nav'); |
||
222 | $menu_subitem[] = create_link(create_container('skeleton.php', 'rankings_player_profit.php'), 'Profit', 'nav'); |
||
223 | $menu_subitem[] = create_link(create_container('skeleton.php', 'rankings_player_kills.php'), 'Kills', 'nav'); |
||
224 | $menu_subitem[] = create_link(create_container('skeleton.php', 'rankings_player_death.php'), 'Deaths', 'nav'); |
||
225 | $menu_subitem[] = create_link(create_container('skeleton.php', 'rankings_player_assists.php'), 'Assists', 'nav'); |
||
226 | |||
227 | $menu_item['submenu'] = $menu_subitem; |
||
228 | |||
229 | $menu[] = $menu_item; |
||
230 | |||
231 | // alliance rankings |
||
232 | $menu_item = array(); |
||
233 | $menu_item['entry'] = create_link(create_container('skeleton.php', 'rankings_alliance_experience.php'), 'Alliance Rankings', 'nav'); |
||
234 | |||
235 | $menu_subitem = array(); |
||
236 | $menu_subitem[] = create_link(create_container('skeleton.php', 'rankings_alliance_experience.php'), 'Experience', 'nav'); |
||
237 | $menu_subitem[] = create_link(create_container('skeleton.php', 'rankings_alliance_profit.php'), 'Profit', 'nav'); |
||
238 | $menu_subitem[] = create_link(create_container('skeleton.php', 'rankings_alliance_kills.php'), 'Kills', 'nav'); |
||
239 | $menu_subitem[] = create_link(create_container('skeleton.php', 'rankings_alliance_death.php'), 'Deaths', 'nav'); |
||
240 | $menu_subitem[] = create_link(create_container('skeleton.php', 'rankings_alliance_vs_alliance.php'), 'Versus', 'nav'); |
||
241 | |||
242 | $menu_item['submenu'] = $menu_subitem; |
||
243 | |||
244 | $menu[] = $menu_item; |
||
245 | |||
246 | // racial rankings |
||
247 | $menu_item = array(); |
||
248 | $menu_item['entry'] = create_link(create_container('skeleton.php', 'rankings_race.php'), 'Racial Standings', 'nav'); |
||
249 | |||
250 | $menu_subitem = array(); |
||
251 | $menu_subitem[] = create_link(create_container('skeleton.php', 'rankings_race.php'), 'Experience', 'nav'); |
||
252 | $menu_subitem[] = create_link(create_container('skeleton.php', 'rankings_race_kills.php'), 'Kills', 'nav'); |
||
253 | $menu_subitem[] = create_link(create_container('skeleton.php', 'rankings_race_death.php'), 'Deaths', 'nav'); |
||
254 | |||
255 | $menu_item['submenu'] = $menu_subitem; |
||
256 | |||
257 | $menu[] = $menu_item; |
||
258 | |||
259 | // sector rankings |
||
260 | $menu_item = array(); |
||
261 | $menu_item['entry'] = create_link(create_container('skeleton.php', 'rankings_sector_kill.php'), 'Sector Kills', 'nav'); |
||
262 | $menu[] = $menu_item; |
||
263 | |||
264 | create_sub_menu($menu, $active_level1, $active_level2); |
||
265 | } |
||
266 | |||
267 | public static function bank() { |
||
268 | global $player; |
||
269 | |||
270 | $menu_items[] = create_link(create_container('skeleton.php', 'bank_personal.php'), |
||
271 | 'Personal Account', 'nav'); |
||
272 | |||
273 | if ($player->hasAlliance()) { |
||
274 | $menu_items[] = create_link(create_container('skeleton.php', 'bank_alliance.php'), |
||
275 | 'Alliance Account', 'nav'); |
||
276 | } |
||
277 | |||
278 | $menu_items[] = create_link(create_container('skeleton.php', 'bank_anon.php'), |
||
279 | 'Anonymous Account', 'nav'); |
||
280 | create_menu($menu_items); |
||
281 | } |
||
282 | |||
283 | public static function council($race_id) { |
||
284 | global $player; |
||
285 | |||
286 | $menu_items[] = create_link(create_container('skeleton.php', 'council_list.php'), |
||
287 | 'View Council', 'nav'); |
||
288 | |||
289 | $container = create_container('skeleton.php'); |
||
290 | $container['body'] = 'council_politics.php'; |
||
291 | $container['race_id'] = $race_id; |
||
292 | $menu_items[] = create_link($container, 'Political Status', 'nav'); |
||
293 | |||
294 | $container['body'] = 'council_send_message.php'; |
||
295 | $container['race_id'] = $race_id; |
||
296 | $menu_items[] = create_link($container, 'Send Message', 'nav'); |
||
297 | |||
298 | if ($player->getRaceID() == $race_id) { |
||
299 | if ($player->isOnCouncil()) { |
||
300 | $menu_items[] = create_link(create_container('skeleton.php', 'council_vote.php'), |
||
301 | 'Voting Center', 'nav'); |
||
302 | } |
||
303 | if ($player->isPresident()) { |
||
304 | $menu_items[] = create_link(create_container('skeleton.php', 'council_embassy.php'), |
||
305 | 'Embassy', 'nav'); |
||
306 | } |
||
307 | } |
||
308 | |||
309 | create_menu($menu_items); |
||
310 | } |
||
311 | |||
312 | public static function bar() { |
||
313 | global $template; |
||
314 | $template->assign('MenuItems', array( |
||
315 | array('Link'=>Globals::getBarMainHREF(), 'Text'=>'Bar Main'), |
||
316 | array('Link'=>Globals::getBarLottoPlayHREF(), 'Text'=>'Lotto'), |
||
317 | array('Link'=>Globals::getBarBlackjackHREF(), 'Text'=>'BlackJack'))); |
||
318 | } |
||
319 | |||
320 | public static function news(Template $template) { |
||
330 | } |
||
331 | |||
332 | public static function navigation(Template $template, AbstractSmrPlayer $player) { |
||
340 | } |
||
341 | |||
342 | } |
||
343 | |||
344 | function create_menu($menu) { |
||
345 | global $template; |
||
346 | $return = '<span class="noWrap">' . implode('</span> | <span class="noWrap">', $menu) . '</span>'; |
||
347 | $template->unassign('MenuItems'); |
||
348 | $template->assign('MenuBar', $return); |
||
349 | } |
||
350 | |||
351 | function create_sub_menu($menu, $active_level1, $active_level2) { |
||
352 | global $template; |
||
422 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.