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
Pull Request — main (#1494)
by Dan
10:59 queued 05:29
created

AllianceDraftMemberProcessor   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 29
dl 0
loc 55
rs 10
c 0
b 0
f 0
wmc 8

2 Methods

Rating   Name   Duplication   Size   Complexity  
B build() 0 47 7
A __construct() 0 3 1
1
<?php declare(strict_types=1);
2
3
namespace Smr\Pages\Player;
4
5
use AbstractSmrPlayer;
6
use Exception;
7
use Smr\Database;
8
use Smr\Epoch;
9
use Smr\Page\PlayerPageProcessor;
10
use Smr\Page\ReusableTrait;
11
use SmrGame;
12
use SmrPlayer;
13
14
class AllianceDraftMemberProcessor extends PlayerPageProcessor {
15
16
	use ReusableTrait;
17
18
	public function __construct(
19
		private readonly int $pickedAccountID
20
	) {}
21
22
	public function build(AbstractSmrPlayer $player): never {
23
		if (!$player->getGame()->isGameType(SmrGame::GAME_TYPE_DRAFT)) {
24
			throw new Exception('This page is only allowed in Draft games!');
25
		}
26
27
		$pickedAccountID = $this->pickedAccountID;
28
29
		require_once(LIB . 'Default/alliance_pick.inc.php');
30
		$teams = get_draft_teams($player->getGameID());
31
		if (!$teams[$player->getAccountID()]['CanPick']) {
32
			create_error('You have to wait for others to pick first.');
33
		}
34
		$pickedPlayer = SmrPlayer::getPlayer($pickedAccountID, $player->getGameID());
35
36
		if ($pickedPlayer->isDraftLeader()) {
37
			create_error('You cannot pick another leader.');
38
		}
39
40
		if ($pickedPlayer->hasAlliance()) {
41
			if ($pickedPlayer->getAlliance()->isNHA()) {
42
				$pickedPlayer->leaveAlliance();
43
			} else {
44
				create_error('Picked player already has an alliance.');
45
			}
46
		}
47
48
		// assign the player to the current alliance
49
		$pickedPlayer->joinAlliance($player->getAllianceID());
50
51
		// move the player to the alliance home sector if not using traditional HQ's
52
		if ($pickedPlayer->getSectorID() === 1) {
53
			$pickedPlayer->setSectorID($pickedPlayer->getHome());
54
			$pickedPlayer->getSector()->markVisited($pickedPlayer);
55
		}
56
57
		$pickedPlayer->update();
58
59
		// Update the draft history
60
		$db = Database::getInstance();
61
		$db->insert('draft_history', [
62
			'game_id' => $db->escapeNumber($player->getGameID()),
63
			'leader_account_id' => $db->escapeNumber($player->getAccountID()),
64
			'picked_account_id' => $db->escapeNumber($pickedPlayer->getAccountID()),
65
			'time' => $db->escapeNumber(Epoch::time()),
66
		]);
67
68
		(new AllianceDraftMember())->go();
69
	}
70
71
}
72