Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Failed Conditions
Pull Request — master (#1082)
by Dan
05:43
created

Globals::getShipClass()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 8
c 1
b 0
f 1
dl 0
loc 12
rs 10
cc 4
nc 4
nop 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A Globals::getCurrentPlayersHREF() 0 2 1
A Globals::getLocalMapHREF() 0 2 1
A Globals::getTradeHREF() 0 2 1
1
<?php declare(strict_types=1);
2
3
class Globals {
4
	protected static array $HIDDEN_PLAYERS;
5
	protected static array $LEVEL_REQUIREMENTS;
6
	protected static array $RACES;
7
	protected static array $GOODS;
8
	protected static array $HARDWARE_TYPES;
9
	protected static bool $FEATURE_REQUEST_OPEN;
10
	protected static array $RACE_RELATIONS;
11
	protected static array $AVAILABLE_LINKS = [];
12
	protected static Smr\Database $db;
13
14
	protected static function initialiseDatabase() : void {
15
		if (!isset(self::$db)) {
16
			self::$db = Smr\Database::getInstance();
17
		}
18
	}
19
20
	public static function getAvailableLinks() : array {
21
		return self::$AVAILABLE_LINKS;
22
	}
23
24
	public static function canAccessPage(string $pageName, AbstractSmrPlayer $player, array $extraInfo) : void {
25
		switch ($pageName) {
26
			case 'AllianceMOTD':
27
				if ($player->getAllianceID() != $extraInfo['AllianceID']) {
28
					logException(new Exception('Tried to access page without permission.'));
29
					create_error('You cannot access this page.');
30
				}
31
			break;
32
		}
33
	}
34
35
	public static function getHiddenPlayers() : array {
36
		if (!isset(self::$HIDDEN_PLAYERS)) {
37
			self::initialiseDatabase();
38
			self::$db->query('SELECT account_id FROM hidden_players');
39
			self::$HIDDEN_PLAYERS = array(0); //stop errors
40
			while (self::$db->nextRecord()) {
41
				self::$HIDDEN_PLAYERS[] = self::$db->getInt('account_id');
42
			}
43
		}
44
		return self::$HIDDEN_PLAYERS;
45
	}
46
47
	public static function getGalacticPostEditorIDs(int $gameID) : array {
48
		self::initialiseDatabase();
49
		$editorIDs = [];
50
		self::$db->query('SELECT account_id FROM galactic_post_writer WHERE position=\'editor\' AND game_id=' . self::$db->escapeNumber($gameID));
51
		while (self::$db->nextRecord()) {
52
			$editorIDs[] = self::$db->getInt('account_id');
53
		}
54
		return $editorIDs;
55
	}
56
57
	public static function getLevelRequirements() : array {
58
		if (!isset(self::$LEVEL_REQUIREMENTS)) {
59
			self::initialiseDatabase();
60
			self::$LEVEL_REQUIREMENTS = array();
61
62
			// determine user level
63
			self::$db->query('SELECT * FROM level ORDER BY level_id ASC');
64
			while (self::$db->nextRecord()) {
65
				self::$LEVEL_REQUIREMENTS[self::$db->getInt('level_id')] = array(
66
																				'Name' => self::$db->getField('level_name'),
67
																				'Requirement' => self::$db->getInt('requirement')
68
																				);
69
			}
70
		}
71
		return self::$LEVEL_REQUIREMENTS;
72
	}
73
74
	public static function getRaces() : array {
75
		if (!isset(self::$RACES)) {
76
			self::initialiseDatabase();
77
			self::$RACES = array();
78
79
			// determine user level
80
			self::$db->query('SELECT race_id,race_name,race_description FROM race ORDER BY race_id');
81
			while (self::$db->nextRecord()) {
82
				self::$RACES[self::$db->getInt('race_id')] = array(
83
																'Race ID' => self::$db->getInt('race_id'),
84
																'Race Name' => self::$db->getField('race_name'),
85
																'Description' => self::$db->getField('race_description'),
86
																'ImageLink' => 'images/race/race' . self::$db->getInt('race_id') . '.jpg',
87
																'ImageHeadLink' => 'images/race/head/race' . self::$db->getInt('race_id') . '.jpg',
88
																);
89
			}
90
		}
91
		return self::$RACES;
92
	}
93
94
	public static function getRaceName(int $raceID) : string {
95
		return Globals::getRaces()[$raceID]['Race Name'];
96
	}
97
98
	public static function getRaceImage(int $raceID) : string {
99
		return Globals::getRaces()[$raceID]['ImageLink'];
100
	}
101
102
	public static function getRaceHeadImage(int $raceID) : string {
103
		return Globals::getRaces()[$raceID]['ImageHeadLink'];
104
	}
105
106
	public static function getColouredRaceNameForRace(int $raceID, int $gameID, int $fromRaceID, bool $linked = true) : string {
107
		$raceRelations = Globals::getRaceRelations($gameID, $fromRaceID);
108
		return self::getColouredRaceName($raceID, $raceRelations[$raceID], $linked);
109
	}
110
111
	public static function getColouredRaceName(int $raceID, int $relations, bool $linked = true) : string {
112
		$raceName = get_colored_text($relations, Globals::getRaceName($raceID));
113
		if ($linked === true) {
114
			$container = Page::create('skeleton.php', 'council_list.php', array('race_id' => $raceID));
115
			$raceName = create_link($container, $raceName);
116
		}
117
		return $raceName;
118
	}
119
120
	public static function getGoods() : array {
121
		if (!isset(self::$GOODS)) {
122
			self::initialiseDatabase();
123
			self::$GOODS = array();
124
125
			// determine user level
126
			self::$db->query('SELECT * FROM good ORDER BY good_id');
127
			while (self::$db->nextRecord()) {
128
				self::$GOODS[self::$db->getInt('good_id')] = array(
129
																'Type' => 'Good',
130
																'ID' => self::$db->getInt('good_id'),
131
																'Name' => self::$db->getField('good_name'),
132
																'Max' => self::$db->getInt('max_amount'),
133
																'BasePrice' => self::$db->getInt('base_price'),
134
																'Class' => self::$db->getInt('good_class'),
135
																'ImageLink' => 'images/port/' . self::$db->getInt('good_id') . '.png',
136
																'AlignRestriction' => self::$db->getInt('align_restriction')
137
															);
138
			}
139
		}
140
		return self::$GOODS;
141
	}
142
143
	public static function getGood(int $goodID) : array {
144
		return Globals::getGoods()[$goodID];
145
	}
146
147
	public static function getGoodName(int $goodID) : string {
148
		if ($goodID == GOODS_NOTHING) {
149
			return 'Nothing';
150
		}
151
		return Globals::getGoods()[$goodID]['Name'];
152
	}
153
154
	public static function getHardwareTypes(int $hardwareTypeID = null) : array {
155
		if (!isset(self::$HARDWARE_TYPES)) {
156
			self::initialiseDatabase();
157
			self::$HARDWARE_TYPES = array();
158
159
			// determine user level
160
			self::$db->query('SELECT * FROM hardware_type ORDER BY hardware_type_id');
161
			while (self::$db->nextRecord()) {
162
				self::$HARDWARE_TYPES[self::$db->getInt('hardware_type_id')] = array(
163
																			'Type' => 'Hardware',
164
																			'ID' => self::$db->getInt('hardware_type_id'),
165
																			'Name' => self::$db->getField('hardware_name'),
166
																			'Cost' => self::$db->getInt('cost')
167
																			);
168
			}
169
		}
170
		if ($hardwareTypeID === null) {
171
			return self::$HARDWARE_TYPES;
172
		}
173
		return self::$HARDWARE_TYPES[$hardwareTypeID];
174
	}
175
176
	public static function getHardwareName(int $hardwareTypeID) : string {
177
		return Globals::getHardwareTypes()[$hardwareTypeID]['Name'];
178
	}
179
180
	public static function getHardwareCost(int $hardwareTypeID) : int {
181
		return Globals::getHardwareTypes()[$hardwareTypeID]['Cost'];
182
	}
183
184
	public static function isValidGame(int $gameID) : bool {
185
		try {
186
			SmrGame::getGame($gameID);
187
			return true;
188
		} catch (GameNotFoundException $e) {
189
			return false;
190
		}
191
	}
192
193
	public static function getGameType(int $gameID) : string {
194
		return SmrGame::getGame($gameID)->getGameType();
195
	}
196
197
	public static function isFeatureRequestOpen() : bool {
198
		if (!isset(self::$FEATURE_REQUEST_OPEN)) {
199
			self::initialiseDatabase();
200
			self::$db->query('SELECT open FROM open_forms WHERE type=\'FEATURE\'');
201
			self::$db->nextRecord();
202
203
			self::$FEATURE_REQUEST_OPEN = self::$db->getBoolean('open');
204
		}
205
		return self::$FEATURE_REQUEST_OPEN;
206
	}
207
208
	public static function getRaceRelations(int $gameID, int $raceID) : array {
209
		if (!isset(self::$RACE_RELATIONS[$gameID][$raceID])) {
210
			self::initialiseDatabase();
211
			//get relations
212
			$RACES = Globals::getRaces();
213
			self::$RACE_RELATIONS[$gameID][$raceID] = array();
214
			foreach ($RACES as $otherRaceID => $raceArray) {
215
				self::$RACE_RELATIONS[$gameID][$raceID][$otherRaceID] = 0;
216
			}
217
			self::$db->query('SELECT race_id_2,relation FROM race_has_relation WHERE race_id_1=' . self::$db->escapeNumber($raceID) . ' AND game_id=' . self::$db->escapeNumber($gameID) . ' LIMIT ' . count($RACES));
218
			while (self::$db->nextRecord()) {
219
				self::$RACE_RELATIONS[$gameID][$raceID][self::$db->getInt('race_id_2')] = self::$db->getInt('relation');
220
			}
221
		}
222
		return self::$RACE_RELATIONS[$gameID][$raceID];
223
	}
224
225
	public static function getFeatureRequestHREF() : string {
226
		return Page::create('skeleton.php', 'feature_request.php')->href();
227
	}
228
229
	public static function getCurrentSectorHREF() : string {
230
		return self::$AVAILABLE_LINKS['CurrentSector'] = Page::create('skeleton.php', 'current_sector.php')->href();
231
	}
232
233
	public static function getLocalMapHREF() : string {
234
		return self::$AVAILABLE_LINKS['LocalMap'] = Page::create('skeleton.php', 'map_local.php')->href();
235
	}
236
237
	public static function getCurrentPlayersHREF() : string {
238
		return self::$AVAILABLE_LINKS['CurrentPlayers'] = Page::create('skeleton.php', 'current_players.php')->href();
239
	}
240
241
	public static function getTradeHREF() : string {
242
		return self::$AVAILABLE_LINKS['EnterPort'] = Page::create('skeleton.php', 'shop_goods.php')->href();
243
	}
244
245
	public static function getAttackTraderHREF(int $accountID) : string {
246
		$container = Page::create('trader_attack_processing.php');
247
		$container['target'] = $accountID;
248
		return self::$AVAILABLE_LINKS['AttackTrader'] = $container->href();
249
	}
250
251
	public static function getPodScreenHREF() : string {
252
		return Page::create('death_processing.php')->href();
253
	}
254
255
	public static function getBetaFunctionsHREF() : string { //BETA
256
		return Page::create('skeleton.php', 'beta_functions.php')->href();
257
	}
258
259
	public static function getBugReportProcessingHREF() : string {
260
		return Page::create('bug_report_processing.php')->href();
261
	}
262
263
	public static function getWeaponReorderHREF(int $weaponOrderID, string $direction) : string {
264
		$container = Page::create('weapon_reorder_processing.php');
265
		$container[$direction] = $weaponOrderID;
266
		return $container->href();
267
	}
268
269
	public static function getSmrFileCreateHREF(int $adminCreateGameID = null) : string {
270
		$container = Page::create('skeleton.php', 'smr_file_create.php');
271
		$container['AdminCreateGameID'] = $adminCreateGameID;
272
		return $container->href();
273
	}
274
275
	public static function getCurrentSectorMoveHREF(AbstractSmrPlayer $player, int $toSector) : string {
276
		return self::getSectorMoveHREF($player, $toSector, 'current_sector.php');
277
	}
278
279
	public static function getSectorMoveHREF(AbstractSmrPlayer $player, int $toSector, string $targetPage) : string {
280
		$container = Page::create('sector_move_processing.php');
281
		$container['target_page'] = $targetPage;
282
		$container['target_sector'] = $toSector;
283
		return self::$AVAILABLE_LINKS['Move' . $player->getSector()->getSectorDirection($toSector)] = $container->href();
284
	}
285
286
	public static function getSectorScanHREF(AbstractSmrPlayer $player, int $toSector) : string {
287
		$container = Page::create('skeleton.php', 'sector_scan.php');
288
		$container['target_sector'] = $toSector;
289
		return self::$AVAILABLE_LINKS['Scan' . $player->getSector()->getSectorDirection($toSector)] = $container->href();
290
	}
291
292
	public static function getPlotCourseHREF(int $fromSector = null, int $toSector = null) : string {
293
		if ($fromSector === null && $toSector === null) {
294
			return self::$AVAILABLE_LINKS['PlotCourse'] = Page::create('skeleton.php', 'course_plot.php')->href();
295
		} else {
296
			return Page::create('course_plot_processing.php', '', array('from'=>$fromSector, 'to'=>$toSector))->href();
297
		}
298
	}
299
300
	public static function getPlanetMainHREF() : string {
301
		return Page::create('skeleton.php', 'planet_main.php')->href();
302
	}
303
304
	public static function getPlanetConstructionHREF() : string {
305
		return Page::create('skeleton.php', 'planet_construction.php')->href();
306
	}
307
308
	public static function getPlanetDefensesHREF() : string {
309
		return Page::create('skeleton.php', 'planet_defense.php')->href();
310
	}
311
312
	public static function getPlanetOwnershipHREF() : string {
313
		return Page::create('skeleton.php', 'planet_ownership.php')->href();
314
	}
315
316
	public static function getPlanetStockpileHREF() : string {
317
		return Page::create('skeleton.php', 'planet_stockpile.php')->href();
318
	}
319
320
	public static function getPlanetFinancesHREF() : string {
321
		return Page::create('skeleton.php', 'planet_financial.php')->href();
322
	}
323
324
	public static function getAllianceHREF(int $allianceID = null) : string {
325
		if ($allianceID > 0) {
326
			return self::getAllianceMotdHREF($allianceID);
0 ignored issues
show
Bug introduced by
It seems like $allianceID can also be of type null; however, parameter $allianceID of Globals::getAllianceMotdHREF() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

326
			return self::getAllianceMotdHREF(/** @scrutinizer ignore-type */ $allianceID);
Loading history...
327
		} else {
328
			return self::getAllianceListHREF();
329
		}
330
	}
331
332
	public static function getAllianceBankHREF(int $allianceID = null) : string {
333
		$container = Page::create('skeleton.php', 'bank_alliance.php');
334
		$container['alliance_id'] = $allianceID;
335
		return $container->href();
336
	}
337
338
	public static function getAllianceRosterHREF($allianceID = null) : string {
339
		$container = Page::create('skeleton.php', 'alliance_roster.php');
340
		$container['alliance_id'] = $allianceID;
341
		return $container->href();
342
	}
343
344
	public static function getAllianceListHREF() : string {
345
		return Page::create('skeleton.php', 'alliance_list.php')->href();
346
	}
347
348
	public static function getAllianceNewsHREF(int $allianceID) : string {
349
		return Page::create('skeleton.php', 'news_read_advanced.php', array('allianceID'=>$allianceID, 'submit' => 'Search For Alliance'))->href();
350
	}
351
352
	public static function getAllianceMotdHREF(int $allianceID) : string {
353
		return Page::create('skeleton.php', 'alliance_mod.php', array('alliance_id'=>$allianceID))->href();
354
	}
355
356
	public static function getAllianceMessageHREF(int $allianceID) : string {
357
		return Page::create('skeleton.php', 'alliance_broadcast.php', array('alliance_id'=>$allianceID))->href();
358
	}
359
360
	public static function getAllianceMessageBoardHREF(int $allianceID) : string {
361
		return Page::create('skeleton.php', 'alliance_message.php', array('alliance_id'=>$allianceID))->href();
362
	}
363
364
	public static function getAllianceForcesHREF(int $allianceID) : string {
365
		return Page::create('skeleton.php', 'alliance_forces.php', array('alliance_id'=>$allianceID))->href();
366
	}
367
368
	public static function getAllianceOptionsHREF(int $allianceID) : string {
369
		return Page::create('skeleton.php', 'alliance_option.php', array('alliance_id'=>$allianceID))->href();
370
	}
371
372
	public static function getPlanetListHREF(int $allianceID) : string {
373
		return Page::create('skeleton.php', 'planet_list.php', array('alliance_id'=>$allianceID))->href();
374
	}
375
376
	public static function getPlanetListFinancialHREF(int $allianceID) : string {
377
		return Page::create('skeleton.php', 'planet_list_financial.php', array('alliance_id'=>$allianceID))->href();
378
	}
379
380
	public static function getViewMessageBoxesHREF() : string {
381
		return Page::create('skeleton.php', 'message_box.php')->href();
382
	}
383
384
	public static function getSendGlobalMessageHREF() : string {
385
		return Page::create('skeleton.php', 'message_send.php')->href();
386
	}
387
388
	public static function getManageBlacklistHREF() : string {
389
		return Page::create('skeleton.php', 'message_blacklist.php')->href();
390
	}
391
392
	public static function getSendCouncilMessageHREF(int $raceID) : string {
393
		$container = Page::create('skeleton.php', 'council_send_message.php');
394
		$container['race_id'] = $raceID;
395
		$container['folder_id'] = MSG_POLITICAL;
396
		return $container->href();
397
	}
398
399
	public static function getTraderStatusHREF() : string {
400
		return Page::create('skeleton.php', 'trader_status.php')->href();
401
	}
402
403
	public static function getCouncilHREF(int $raceID = null) : string {
404
		$container = Page::create('skeleton.php', 'council_list.php');
405
		$container['race_id'] = $raceID;
406
		return $container->href();
407
	}
408
409
	public static function getTraderRelationsHREF() : string {
410
		return Page::create('skeleton.php', 'trader_relations.php')->href();
411
	}
412
413
	public static function getTraderBountiesHREF() : string {
414
		return Page::create('skeleton.php', 'trader_bounties.php')->href();
415
	}
416
417
	public static function getPoliticsHREF() : string {
418
		return Page::create('skeleton.php', 'council_list.php')->href();
419
	}
420
421
	public static function getCasinoHREF() : string {
422
		return Page::create('skeleton.php', 'chess.php')->href();
423
	}
424
425
	public static function getChessHREF() : string {
426
		return Page::create('skeleton.php', 'chess.php')->href();
427
	}
428
429
	public static function getChessCreateHREF() : string {
430
		return Page::create('chess_create_processing.php')->href();
431
	}
432
433
	public static function getBarMainHREF() : string {
434
		$container = Page::create('skeleton.php', 'bar_main.php');
435
		$container->addVar('LocationID');
436
		return $container->href();
437
	}
438
439
	public static function getBarLottoPlayHREF() : string {
440
		$container = Page::create('skeleton.php', 'bar_lotto_buy.php');
441
		$container->addVar('LocationID');
442
		return $container->href();
443
	}
444
445
	public static function getBarBlackjackHREF() : string {
446
		$container = Page::create('skeleton.php', 'bar_gambling_bet.php');
447
		$container->addVar('LocationID');
448
		return $container->href();
449
	}
450
451
	public static function getBuyMessageNotificationsHREF() : string {
452
		return Page::create('skeleton.php', 'buy_message_notifications.php')->href();
453
	}
454
455
	public static function getBuyShipNameHREF() : string {
456
		return Page::create('skeleton.php', 'buy_ship_name.php')->href();
457
	}
458
459
	public static function getBuyShipNameCosts() : array {
460
		return [
461
			'text' => CREDITS_PER_TEXT_SHIP_NAME,
462
			'html' => CREDITS_PER_HTML_SHIP_NAME,
463
			'logo' => CREDITS_PER_SHIP_LOGO,
464
		];
465
	}
466
467
	public static function getSectorBBLink(int $sectorID) : string {
468
		return '[sector=' . $sectorID . ']';
469
	}
470
471
	public static function getAvailableTemplates() : array {
472
		return array_keys(CSS_URLS);
473
	}
474
475
	public static function getAvailableColourSchemes(string $templateName) : array {
476
		return array_keys(CSS_COLOUR_URLS[$templateName]);
477
	}
478
479
	/**
480
	 * Returns an array of history databases for which we have ancient saved
481
	 * game data. Array keys are database names and values are the columns in
482
	 * the `account` table with the linked historical account ID's.
483
	 */
484
	public static function getHistoryDatabases() : array {
485
		if (defined('HISTORY_DATABASES')) {
486
			return HISTORY_DATABASES;
0 ignored issues
show
Bug introduced by
The constant HISTORY_DATABASES was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
487
		} else {
488
			return array();
489
		}
490
	}
491
492
}
493