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
Push — main ( d9cfb9...10f5c7 )
by Dan
32s queued 21s
created

Globals::getGoods()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 21
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 15
nc 2
nop 0
dl 0
loc 21
rs 9.7666
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A Globals::getCurrentPlayersHREF() 0 2 1
A Globals::getLocalMapHREF() 0 2 1
A Globals::getBetaFunctionsHREF() 0 2 1
A Globals::getAttackTraderHREF() 0 3 1
A Globals::getTradeHREF() 0 2 1
1
<?php declare(strict_types=1);
2
3
use Smr\Database;
4
use Smr\Exceptions\UserError;
5
use Smr\Pages\Account\BugReportProcessor;
6
use Smr\Pages\Account\BuyMessageNotifications;
7
use Smr\Pages\Account\FeatureRequest;
8
use Smr\Pages\Account\NewsReadAdvanced;
9
use Smr\Pages\Player\AllianceBroadcast;
10
use Smr\Pages\Player\AllianceForces;
11
use Smr\Pages\Player\AllianceList;
12
use Smr\Pages\Player\AllianceMessageBoard;
13
use Smr\Pages\Player\AllianceMotd;
14
use Smr\Pages\Player\AllianceOptions;
15
use Smr\Pages\Player\AllianceRoster;
16
use Smr\Pages\Player\AttackPlayerProcessor;
17
use Smr\Pages\Player\Bank\AllianceBank;
18
use Smr\Pages\Player\BetaFunctions\BetaFunctions;
19
use Smr\Pages\Player\BuyShipName;
20
use Smr\Pages\Player\Chess\MatchList;
21
use Smr\Pages\Player\Chess\MatchStartProcessor;
22
use Smr\Pages\Player\Council\MessageCouncil;
23
use Smr\Pages\Player\Council\ViewCouncil;
24
use Smr\Pages\Player\CurrentPlayers;
25
use Smr\Pages\Player\CurrentSector;
26
use Smr\Pages\Player\ListPlanetDefense;
27
use Smr\Pages\Player\ListPlanetFinancial;
28
use Smr\Pages\Player\LocalMap;
29
use Smr\Pages\Player\MessageBlacklist;
30
use Smr\Pages\Player\MessageBox;
31
use Smr\Pages\Player\MessageSend;
32
use Smr\Pages\Player\PlotCourse;
33
use Smr\Pages\Player\PlotCourseConventionalProcessor;
34
use Smr\Pages\Player\SectorMoveProcessor;
35
use Smr\Pages\Player\SectorScan;
36
use Smr\Pages\Player\SectorsFileDownloadProcessor;
37
use Smr\Pages\Player\ShopGoods;
38
use Smr\Pages\Player\TraderBounties;
39
use Smr\Pages\Player\TraderRelations;
40
use Smr\Pages\Player\TraderStatus;
41
use Smr\Pages\Player\WeaponReorderProcessor;
42
use Smr\Race;
43
44
class Globals {
45
46
	/** @var array<int> */
47
	protected static array $HIDDEN_PLAYERS;
48
	protected static bool $FEATURE_REQUEST_OPEN;
49
	/** @var array<int, array<int, array<int, int>>> */
50
	protected static array $RACE_RELATIONS;
51
	/** @var array<string, string> */
52
	protected static array $AVAILABLE_LINKS = [];
53
54
	/**
55
	 * @return array<string, string>
56
	 */
57
	public static function getAvailableLinks(): array {
58
		return self::$AVAILABLE_LINKS;
59
	}
60
61
	/**
62
	 * @param array<string, int> $extraInfo
63
	 */
64
	public static function canAccessPage(string $pageName, AbstractSmrPlayer $player, array $extraInfo): void {
65
		switch ($pageName) {
66
			case 'AllianceMOTD':
67
				if ($player->getAllianceID() != $extraInfo['AllianceID']) {
68
					logException(new Exception('Tried to access page without permission.'));
0 ignored issues
show
Bug introduced by
The function logException was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

68
					/** @scrutinizer ignore-call */ 
69
     logException(new Exception('Tried to access page without permission.'));
Loading history...
69
					throw new UserError('You cannot access this page.');
70
				}
71
				break;
72
		}
73
	}
74
75
	/**
76
	 * @return array<int>
77
	 */
78
	public static function getHiddenPlayers(): array {
79
		if (!isset(self::$HIDDEN_PLAYERS)) {
80
			$db = Database::getInstance();
81
			$dbResult = $db->read('SELECT account_id FROM hidden_players');
82
			self::$HIDDEN_PLAYERS = [0]; //stop errors
83
			foreach ($dbResult->records() as $dbRecord) {
84
				self::$HIDDEN_PLAYERS[] = $dbRecord->getInt('account_id');
85
			}
86
		}
87
		return self::$HIDDEN_PLAYERS;
88
	}
89
90
	/**
91
	 * @return array<int>
92
	 */
93
	public static function getGalacticPostEditorIDs(int $gameID): array {
94
		$editorIDs = [];
95
		$db = Database::getInstance();
96
		$dbResult = $db->read('SELECT account_id FROM galactic_post_writer WHERE position=\'editor\' AND game_id=' . $db->escapeNumber($gameID));
97
		foreach ($dbResult->records() as $dbRecord) {
98
			$editorIDs[] = $dbRecord->getInt('account_id');
99
		}
100
		return $editorIDs;
101
	}
102
103
	public static function getColouredRaceNameForRace(int $raceID, int $gameID, int $fromRaceID, bool $linked = true): string {
104
		$raceRelations = self::getRaceRelations($gameID, $fromRaceID);
105
		return self::getColouredRaceName($raceID, $raceRelations[$raceID], $linked);
106
	}
107
108
	public static function getColouredRaceName(int $raceID, int $relations, bool $linked = true): string {
109
		$raceName = get_colored_text($relations, Race::getName($raceID));
110
		if ($linked === true) {
111
			$container = new ViewCouncil($raceID);
112
			$raceName = create_link($container, $raceName);
113
		}
114
		return $raceName;
115
	}
116
117
	public static function isFeatureRequestOpen(): bool {
118
		if (!isset(self::$FEATURE_REQUEST_OPEN)) {
119
			$db = Database::getInstance();
120
			$dbResult = $db->read('SELECT open FROM open_forms WHERE type=\'FEATURE\'');
121
122
			self::$FEATURE_REQUEST_OPEN = $dbResult->record()->getBoolean('open');
123
		}
124
		return self::$FEATURE_REQUEST_OPEN;
125
	}
126
127
	/**
128
	 * @return array<int, int>
129
	 */
130
	public static function getRaceRelations(int $gameID, int $raceID): array {
131
		if (!isset(self::$RACE_RELATIONS[$gameID][$raceID])) {
132
			//get relations
133
			self::$RACE_RELATIONS[$gameID][$raceID] = [];
134
			foreach (Race::getAllIDs() as $otherRaceID) {
135
				self::$RACE_RELATIONS[$gameID][$raceID][$otherRaceID] = 0;
136
			}
137
			$db = Database::getInstance();
138
			$dbResult = $db->read('SELECT race_id_2,relation FROM race_has_relation WHERE race_id_1=' . $db->escapeNumber($raceID) . ' AND game_id=' . $db->escapeNumber($gameID));
139
			foreach ($dbResult->records() as $dbRecord) {
140
				self::$RACE_RELATIONS[$gameID][$raceID][$dbRecord->getInt('race_id_2')] = $dbRecord->getInt('relation');
141
			}
142
		}
143
		return self::$RACE_RELATIONS[$gameID][$raceID];
144
	}
145
146
	public static function getFeatureRequestHREF(): string {
147
		return (new FeatureRequest())->href();
148
	}
149
150
	public static function getCurrentSectorHREF(): string {
151
		return self::$AVAILABLE_LINKS['CurrentSector'] = (new CurrentSector())->href();
152
	}
153
154
	public static function getLocalMapHREF(): string {
155
		return self::$AVAILABLE_LINKS['LocalMap'] = (new LocalMap())->href();
156
	}
157
158
	public static function getCurrentPlayersHREF(): string {
159
		return self::$AVAILABLE_LINKS['CurrentPlayers'] = (new CurrentPlayers())->href();
160
	}
161
162
	public static function getTradeHREF(): string {
163
		return self::$AVAILABLE_LINKS['EnterPort'] = (new ShopGoods())->href();
164
	}
165
166
	public static function getAttackTraderHREF(int $accountID): string {
167
		$container = new AttackPlayerProcessor($accountID);
168
		return self::$AVAILABLE_LINKS['AttackTrader'] = $container->href();
169
	}
170
171
	public static function getBetaFunctionsHREF(): string { //BETA
172
		return (new BetaFunctions())->href();
173
	}
174
175
	public static function getBugReportProcessingHREF(): string {
176
		return (new BugReportProcessor())->href();
177
	}
178
179
	public static function getWeaponReorderHREF(int $weaponOrderID, string $direction): string {
180
		$container = new WeaponReorderProcessor($weaponOrderID, $direction);
181
		return $container->href();
182
	}
183
184
	public static function getSmrFileCreateHREF(): string {
185
		$container = new SectorsFileDownloadProcessor();
186
		return $container->href();
187
	}
188
189
	public static function getCurrentSectorMoveHREF(AbstractSmrPlayer $player, int $toSector): string {
190
		return self::getSectorMoveHREF($player, $toSector, new CurrentSector());
191
	}
192
193
	public static function getSectorMoveHREF(AbstractSmrPlayer $player, int $toSector, CurrentSector|LocalMap $targetPage): string {
194
		$container = new SectorMoveProcessor($toSector, $targetPage);
195
		return self::$AVAILABLE_LINKS['Move' . $player->getSector()->getSectorDirection($toSector)] = $container->href();
196
	}
197
198
	public static function getSectorScanHREF(AbstractSmrPlayer $player, int $toSector): string {
199
		$container = new SectorScan($toSector);
200
		return self::$AVAILABLE_LINKS['Scan' . $player->getSector()->getSectorDirection($toSector)] = $container->href();
201
	}
202
203
	public static function getPlotCourseHREF(int $fromSector = null, int $toSector = null): string {
204
		if ($fromSector === null && $toSector === null) {
205
			return self::$AVAILABLE_LINKS['PlotCourse'] = (new PlotCourse())->href();
206
		}
207
		return (new PlotCourseConventionalProcessor(from: $fromSector, to: $toSector))->href();
208
	}
209
210
	public static function getAllianceHREF(int $allianceID = null): string {
211
		if ($allianceID > 0) {
212
			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

212
			return self::getAllianceMotdHREF(/** @scrutinizer ignore-type */ $allianceID);
Loading history...
213
		}
214
		return self::getAllianceListHREF();
215
	}
216
217
	public static function getAllianceBankHREF(int $allianceID): string {
218
		$container = new AllianceBank($allianceID);
219
		return $container->href();
220
	}
221
222
	public static function getAllianceRosterHREF(int $allianceID = null): string {
223
		return (new AllianceRoster($allianceID))->href();
224
	}
225
226
	public static function getAllianceListHREF(): string {
227
		return (new AllianceList())->href();
228
	}
229
230
	public static function getAllianceNewsHREF(int $gameID, int $allianceID): string {
231
		return (new NewsReadAdvanced(gameID: $gameID, submit: 'Search For Alliance', allianceIDs: [$allianceID]))->href();
232
	}
233
234
	public static function getAllianceMotdHREF(int $allianceID): string {
235
		return (new AllianceMotd($allianceID))->href();
236
	}
237
238
	public static function getAllianceMessageHREF(int $allianceID): string {
239
		return (new AllianceBroadcast($allianceID))->href();
240
	}
241
242
	public static function getAllianceMessageBoardHREF(int $allianceID): string {
243
		return (new AllianceMessageBoard($allianceID))->href();
244
	}
245
246
	public static function getAllianceForcesHREF(int $allianceID): string {
247
		return (new AllianceForces($allianceID))->href();
248
	}
249
250
	public static function getAllianceOptionsHREF(): string {
251
		return (new AllianceOptions())->href();
252
	}
253
254
	public static function getPlanetListHREF(int $allianceID): string {
255
		return (new ListPlanetDefense($allianceID))->href();
256
	}
257
258
	public static function getPlanetListFinancialHREF(int $allianceID): string {
259
		return (new ListPlanetFinancial($allianceID))->href();
260
	}
261
262
	public static function getViewMessageBoxesHREF(): string {
263
		return (new MessageBox())->href();
264
	}
265
266
	public static function getSendGlobalMessageHREF(): string {
267
		return (new MessageSend())->href();
268
	}
269
270
	public static function getManageBlacklistHREF(): string {
271
		return (new MessageBlacklist())->href();
272
	}
273
274
	public static function getSendCouncilMessageHREF(int $raceID): string {
275
		$container = new MessageCouncil($raceID);
276
		return $container->href();
277
	}
278
279
	public static function getTraderStatusHREF(): string {
280
		return (new TraderStatus())->href();
281
	}
282
283
	public static function getCouncilHREF(int $raceID): string {
284
		$container = new ViewCouncil($raceID);
285
		return $container->href();
286
	}
287
288
	public static function getTraderRelationsHREF(): string {
289
		return (new TraderRelations())->href();
290
	}
291
292
	public static function getTraderBountiesHREF(): string {
293
		return (new TraderBounties())->href();
294
	}
295
296
	public static function getCasinoHREF(): string {
297
		return (new MatchList())->href();
298
	}
299
300
	public static function getChessHREF(): string {
301
		return (new MatchList())->href();
302
	}
303
304
	public static function getChessCreateHREF(): string {
305
		return (new MatchStartProcessor())->href();
306
	}
307
308
	public static function getBuyMessageNotificationsHREF(): string {
309
		return (new BuyMessageNotifications())->href();
310
	}
311
312
	public static function getBuyShipNameHREF(): string {
313
		return (new BuyShipName())->href();
314
	}
315
316
	/**
317
	 * @return array<string, int>
318
	 */
319
	public static function getBuyShipNameCosts(): array {
320
		return [
321
			'text' => CREDITS_PER_TEXT_SHIP_NAME,
322
			'html' => CREDITS_PER_HTML_SHIP_NAME,
323
			'logo' => CREDITS_PER_SHIP_LOGO,
324
		];
325
	}
326
327
	public static function getSectorBBLink(int $sectorID): string {
328
		return '[sector=' . $sectorID . ']';
329
	}
330
331
	/**
332
	 * @return array<string>
333
	 */
334
	public static function getAvailableTemplates(): array {
335
		return array_keys(CSS_URLS);
336
	}
337
338
	/**
339
	 * @return array<string>
340
	 */
341
	public static function getAvailableColourSchemes(string $templateName): array {
342
		return array_keys(CSS_COLOUR_URLS[$templateName]);
343
	}
344
345
	/**
346
	 * Returns an array of history databases for which we have ancient saved
347
	 * game data. Array keys are database names and values are the columns in
348
	 * the `account` table with the linked historical account ID's.
349
	 *
350
	 * @return array<string, string>
351
	 */
352
	public static function getHistoryDatabases(): array {
353
		if (!defined('HISTORY_DATABASES')) {
354
			return [];
355
		}
356
		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...
357
	}
358
359
}
360