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
08:06 queued 03:15
created

AllianceGovernanceProcessor::build()   F

Complexity

Conditions 18
Paths > 20000

Size

Total Lines 66
Code Lines 42

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 18
eloc 42
nc 32768
nop 1
dl 0
loc 66
rs 0.7
c 1
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php declare(strict_types=1);
2
3
namespace Smr\Pages\Player;
4
5
use AbstractSmrPlayer;
6
use Smr\Database;
7
use Smr\Page\PlayerPageProcessor;
8
use Smr\Request;
9
use SmrAlliance;
10
11
class AllianceGovernanceProcessor extends PlayerPageProcessor {
12
13
	public function __construct(
14
		private readonly int $allianceID
15
	) {}
16
17
	public function build(AbstractSmrPlayer $player): never {
18
		$alliance_id = $this->allianceID;
19
20
		if (Request::has('description')) {
21
			$description = Request::get('description');
22
		}
23
		if (Request::has('discord_server')) {
24
			$discordServer = Request::get('discord_server');
25
		}
26
		if (Request::has('discord_channel')) {
27
			$discordChannel = Request::get('discord_channel');
28
		}
29
		if (Request::has('irc')) {
30
			$irc = Request::get('irc');
31
		}
32
		if (Request::has('mod')) {
33
			$mod = Request::get('mod');
34
		}
35
		if (Request::has('url')) {
36
			$url = Request::get('url');
37
		}
38
39
		// Prevent XSS attacks
40
		if (isset($url) && preg_match('/"/', $url)) {
41
			create_error('You cannot use a " in the image link!');
42
		}
43
44
		$alliance = SmrAlliance::getAlliance($alliance_id, $player->getGameID());
45
		if (Request::has('recruit_type')) {
46
			$recruitType = Request::get('recruit_type');
47
			$password = Request::get('password', '');
48
			$alliance->setRecruitType($recruitType, $password);
49
		}
50
		if (isset($description)) {
51
			$alliance->setAllianceDescription($description, $player);
52
		}
53
		if (isset($discordServer)) {
54
			$alliance->setDiscordServer($discordServer);
55
		}
56
		if (isset($discordChannel)) {
57
			if (empty($discordChannel)) {
58
				$alliance->setDiscordChannel(null);
59
			} else {
60
				// no duplicates in a given game
61
				$db = Database::getInstance();
62
				$dbResult = $db->read('SELECT 1 FROM alliance WHERE discord_channel =' . $db->escapeString($discordChannel) . ' AND game_id = ' . $db->escapeNumber($alliance->getGameID()) . ' AND alliance_id != ' . $db->escapeNumber($alliance->getAllianceID()) . ' LIMIT 1');
63
				if ($dbResult->hasRecord()) {
64
					create_error('Another alliance is already using that Discord Channel ID!');
65
				}
66
67
				$alliance->setDiscordChannel($discordChannel);
68
			}
69
		}
70
		if (isset($irc)) {
71
			$alliance->setIrcChannel($irc);
72
		}
73
		if (isset($mod)) {
74
			$alliance->setMotD($mod);
75
		}
76
		if (isset($url)) {
77
			$alliance->setImageURL($url);
78
		}
79
80
		$alliance->update();
81
		$container = new AllianceRoster($alliance_id);
82
		$container->go();
83
	}
84
85
}
86