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 ( 5797ad...3faf69 )
by Dan
29s queued 24s
created

CurrentPlayers   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 58
dl 0
loc 91
rs 10
c 1
b 0
f 0
wmc 11

1 Method

Rating   Name   Duplication   Size   Complexity  
C build() 0 85 11
1
<?php declare(strict_types=1);
2
3
namespace Smr\Pages\Player;
4
5
use AbstractSmrPlayer;
6
use Smr\Database;
7
use Smr\Epoch;
8
use Smr\Page\PlayerPage;
9
use Smr\Page\ReusableTrait;
10
use Smr\Template;
11
use SmrPlayer;
12
13
class CurrentPlayers extends PlayerPage {
14
15
	use ReusableTrait;
16
17
	public string $file = 'current_players.php';
18
19
	public function build(AbstractSmrPlayer $player, Template $template): void {
20
		$inactiveTime = Epoch::time() - TIME_BEFORE_INACTIVE;
21
22
		$template->assign('PageTopic', 'Current Players');
23
		$db = Database::getInstance();
24
		$db->write('DELETE FROM cpl_tag WHERE expires > 0 AND expires < ' . $db->escapeNumber(Epoch::time()));
25
26
		$dbResult = $db->read('SELECT count(*) count FROM active_session
27
					WHERE last_accessed >= ' . $db->escapeNumber($inactiveTime) . ' AND
28
						game_id = ' . $db->escapeNumber($player->getGameID()));
29
		$count_active = $dbResult->record()->getInt('count');
30
31
		$dbResult = $db->read('SELECT * FROM player
32
				WHERE last_cpl_action >= ' . $db->escapeNumber($inactiveTime) . '
33
					AND game_id = ' . $db->escapeNumber($player->getGameID()) . '
34
				ORDER BY experience DESC, player_name DESC');
35
		$count_moving = $dbResult->getNumRecords();
36
37
		// fix it if some1 is using the logoff button
38
		$count_active = max($count_active, $count_moving);
39
40
		// Get the summary text
41
		$summary = 'There ';
42
		if ($count_active != 1) {
43
			$summary .= 'are ' . $count_active . ' players who have ';
44
		} else {
45
			$summary .= 'is 1 player who has ';
46
		}
47
		$summary .= 'accessed the server in the last ' . format_time(TIME_BEFORE_INACTIVE) . '.<br />';
48
49
		if ($count_moving == 0) {
50
			$summary .= 'No one was moving so your ship computer can\'t intercept any transmissions.';
51
		} else {
52
			if ($count_moving == $count_active) {
53
				$summary .= 'All ';
54
			} else {
55
				$summary .= 'A few ';
56
			}
57
			$summary .= 'of them were moving so your ship computer was able to intercept ' . pluralise($count_moving, 'transmission') . '.';
58
		}
59
60
		$summary .= '<br />The traders listed in <span class="italic">italics</span> are still ranked as Newbie or Beginner.';
61
62
		$template->assign('Summary', $summary);
63
64
		$allRows = [];
65
		foreach ($dbResult->records() as $dbRecord) {
66
			$row = [];
67
68
			$curr_player = SmrPlayer::getPlayer($dbRecord->getInt('account_id'), $player->getGameID(), false, $dbRecord);
69
			$row['player'] = $curr_player;
70
71
			// How should we style the row for this player?
72
			$class = '';
73
			if ($player->equals($curr_player)) {
74
				$class .= 'bold';
75
			}
76
			if ($curr_player->hasNewbieStatus()) {
77
				$class .= ' newbie';
78
			}
79
			if ($class != '') {
80
				$class = ' class="' . trim($class) . '"';
81
			}
82
			$row['tr_class'] = $class;
83
84
			// What should the player name be displayed as?
85
			$container = new SearchForTraderResult($curr_player->getPlayerID());
86
			$name = $curr_player->getLevelName() . ' ' . $curr_player->getDisplayName();
87
			$dbResult2 = $db->read('SELECT * FROM cpl_tag WHERE account_id = ' . $db->escapeNumber($curr_player->getAccountID()) . ' ORDER BY custom DESC');
88
			foreach ($dbResult2->records() as $dbRecord2) {
89
				$customRank = $dbRecord2->getString('custom_rank');
90
				$tag = $dbRecord2->getString('tag');
91
				if (!empty($customRank)) {
92
					$name = $customRank . ' ' . $curr_player->getDisplayName();
93
				}
94
				if (!empty($tag)) {
95
					$name .= ' ' . $tag;
96
				}
97
			}
98
			$row['name_link'] = create_link($container, $name);
99
100
			$allRows[] = $row;
101
		}
102
103
		$template->assign('AllRows', $allRows);
104
	}
105
106
}
107