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

Passed
Pull Request — master (#924)
by
unknown
04:35
created

Council::getPresidentID()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 2
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
class Council {
4
	protected static $COUNCILS = array();
5
	protected static $PRESIDENTS = array();
6
	protected static $db = null;
7
8
	private function __construct() {
9
	}
10
11
	protected static function initialiseDatabase() {
12
		if (self::$db == null) {
13
			self::MySqlDatabase::getInstance();
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM on line 13 at column 22
Loading history...
14
		}
15
	}
16
17
	/**
18
	 * Returns an array of Account ID's of the Council for this race.
19
	 */
20
	public static function getRaceCouncil($gameID, $raceID) {
21
		if (!isset(self::$COUNCILS[$gameID][$raceID])) {
22
			self::initialiseDatabase();
23
			self::$COUNCILS[$gameID][$raceID] = array();
24
			self::$PRESIDENTS[$gameID][$raceID] = false;
25
26
			// Require council members to have > 0 exp to ensure that players
27
			// cannot perform council activities before the game starts.
28
			$i = 1;
29
			self::$db->query('SELECT account_id, alignment
30
								FROM player
31
								WHERE game_id = ' . self::$db->escapeNumber($gameID) . '
32
									AND race_id = ' . self::$db->escapeNumber($raceID) . '
33
									AND npc = \'FALSE\'
34
									AND experience > 0
35
								ORDER by experience DESC
36
								LIMIT ' . MAX_COUNCIL_MEMBERS);
37
			while (self::$db->nextRecord()) {
38
				// Add this player to the council
39
				self::$COUNCILS[$gameID][$raceID][$i++] = self::$db->getInt('account_id');
40
41
				// Determine if this player is also the president
42
				if (self::$PRESIDENTS[$gameID][$raceID] === false) {
43
					if (self::$db->getInt('alignment') >= ALIGNMENT_PRESIDENT) {
44
						self::$PRESIDENTS[$gameID][$raceID] = self::$db->getInt('account_id');
45
					}
46
				}
47
			}
48
		}
49
		return self::$COUNCILS[$gameID][$raceID];
50
	}
51
52
	/**
53
	 * Returns the Account ID of the President for this race (or false if no President).
54
	 */
55
	public static function getPresidentID($gameID, $raceID) {
56
		if (!isset(self::$PRESIDENTS[$gameID][$raceID])) {
57
			self::initialiseDatabase();
58
			self::getRaceCouncil($gameID, $raceID); // determines the president
59
		}
60
		return self::$PRESIDENTS[$gameID][$raceID];
61
	}
62
63
	public static function isOnCouncil($gameID, $raceID, $accountID) {
64
		return in_array($accountID, self::getRaceCouncil($gameID, $raceID));
65
	}
66
}
67