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

Completed
Push — master ( 1adc02...750da7 )
by Dan
23s queued 16s
created

SmrInvitation::getExpires()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 2
rs 10
1
<?php declare(strict_types=1);
2
3
// Exception thrown when an alliance invitation cannot be found in the database
4
class InvitationNotFoundException extends Exception {}
5
6
/**
7
 * Object interfacing with the alliance_invites_player table.
8
 */
9
class SmrInvitation {
10
11
	private int $allianceID;
12
	private int $gameID;
13
	private int $receiverAccountID;
14
	private int $senderAccountID;
15
	private int $messageID;
16
	private int $expires;
17
18
	static public function send(int $allianceID, int $gameID, int $receiverAccountID, int $senderAccountID, int $messageID, int $expires) : void {
19
		$db = new SmrMySqlDatabase();
20
		$db->query('INSERT INTO alliance_invites_player (game_id, account_id, alliance_id, invited_by_id, expires, message_id) VALUES(' . $db->escapeNumber($gameID) . ', ' . $db->escapeNumber($receiverAccountID) . ', ' . $db->escapeNumber($allianceID) . ', ' . $db->escapeNumber($senderAccountID) . ', ' . $db->escapeNumber($expires) . ', ' . $db->escapeNumber($messageID) . ')');
21
	}
22
23
	/**
24
	 * Get all unexpired invitations for the given alliance
25
	 */
26
	static public function getAll(int $allianceID, int $gameID) : array {
27
		// Remove any expired invitations
28
		$db = new SmrMySqlDatabase();
29
		$db->query('DELETE FROM alliance_invites_player WHERE expires < ' . $db->escapeNumber(TIME));
30
31
		$db->query('SELECT * FROM alliance_invites_player WHERE alliance_id=' . $db->escapeNumber($allianceID) . ' AND game_id=' . $db->escapeNumber($gameID));
32
		$invites = [];
33
		while ($db->nextRecord()) {
34
			$invites[] = new SmrInvitation($db);
35
		}
36
		return $invites;
37
	}
38
39
	/**
40
	 * Get the alliance invitation for a single recipient, if not expired
41
	 */
42
	static public function get(int $allianceID, int $gameID, int $receiverAccountID) : SmrInvitation {
43
		// Remove any expired invitations
44
		$db = new SmrMySqlDatabase();
45
		$db->query('DELETE FROM alliance_invites_player WHERE expires < ' . $db->escapeNumber(TIME));
46
47
		$db->query('SELECT * FROM alliance_invites_player WHERE alliance_id=' . $db->escapeNumber($allianceID) . ' AND game_id=' . $db->escapeNumber($gameID) . ' AND account_id=' . $db->escapeNumber($receiverAccountID));
48
		if ($db->nextRecord()) {
49
			return new SmrInvitation($db);
50
		}
51
		throw new InvitationNotFoundException();
52
	}
53
54
	public function __construct(MySqlDatabase $db) {
55
		$this->allianceID = $db->getInt('alliance_id');
56
		$this->gameID = $db->getInt('game_id');
57
		$this->receiverAccountID = $db->getInt('account_id');
58
		$this->senderAccountID = $db->getInt('invited_by_id');
59
		$this->messageID = $db->getInt('message_id');
60
		$this->expires = $db->getInt('expires');
61
	}
62
63
	public function delete() : void {
64
		$db = new SmrMySqlDatabase();
65
		$db->query('DELETE FROM alliance_invites_player WHERE alliance_id=' . $db->escapeNumber($this->allianceID) . ' AND game_id=' . $db->escapeNumber($this->gameID) . ' AND account_id=' . $db->escapeNumber($this->receiverAccountID));
66
		$db->query('DELETE FROM message WHERE message_id=' . $db->escapeNumber($this->messageID));
67
	}
68
69
	public function getSender() : SmrPlayer {
70
		return SmrPlayer::getPlayer($this->senderAccountID, $this->gameID);
71
	}
72
73
	public function getReceiver() : SmrPlayer {
74
		return SmrPlayer::getPlayer($this->receiverAccountID, $this->gameID);
75
	}
76
77
	public function getExpires() : int {
78
		return $this->expires;
79
	}
80
81
}
82