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
Push — master ( a2e803...8f5da7 )
by Dan
04:54 queued 28s
created

redirectIfOffline()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 23
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 11
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 23
rs 9.9
1
<?php declare(strict_types=1);
2
3
function redirectIfDisabled(SmrAccount $account) {
4
	// We skip the redirect for specific disabled reasons, because they are
5
	// handled elsewhere.
6
	$skipReasons = [
7
		CLOSE_ACCOUNT_INVALID_EMAIL_REASON,
8
		CLOSE_ACCOUNT_BY_REQUEST_REASON,
9
	];
10
11
	$disabled = $account->isDisabled();
12
	if ($disabled === false || in_array($disabled['Reason'], $skipReasons)) {
13
		return $disabled;
14
	}
15
16
	// Otherwise, we redirect to the login page with a message
17
	$msg = '<span class="red">Your account is disabled!</span><br />Reason: ' . $disabled['Reason'] . '<br /><br />It is set to ';
18
	if ($disabled['Time'] > 0) {
19
		$msg .= 'reopen on ' . date(DEFAULT_DATE_FULL_LONG, $disabled['Time']);
20
	} else {
21
		$msg .= 'never reopen';
22
	}
23
	$msg .= '.<br />Please contact an admin for further information.';
24
25
	// Destroy the SmrSession, since there is no way to "log off" from the login page
26
	SmrSession::destroy();
27
28
	// Store the message in a session to avoid URL length restrictions
29
	if (session_status() === PHP_SESSION_NONE) {
30
		session_start();
31
	}
32
	$_SESSION['login_msg'] = $msg;
33
34
	header('location: /login.php?status=disabled');
35
	exit;
36
}
37
38
function redirectIfOffline(SmrAccount $account) : void {
39
	// Check if the game is offline
40
	$db = new SmrMySqlDatabase();
41
	$db->query('SELECT * FROM game_disable');
42
	$offline = $db->nextRecord();
43
44
	// Skip redirect if we're not offline or if account has admin permission
45
	if ($offline === false || $account->hasPermission(PERMISSION_GAME_OPEN_CLOSE)) {
46
		return;
47
	}
48
49
	// We need to destroy the session so that the login page doesn't
50
	// redirect to the in-game loader (bypassing the server closure).
51
	SmrSession::destroy();
52
53
	// Store the message in a session to avoid URL length restrictions
54
	if (session_status() === PHP_SESSION_NONE) {
55
		session_start();
56
	}
57
	$_SESSION['login_msg'] = '<span class="red">Space Merchant Realms is temporarily offline.<br />' . $db->getField('reason') . '</span>';
58
59
	header('location: /login.php?status=offline');
60
	exit;
61
}
62