We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 26 |
Paths | > 20000 |
Total Lines | 135 |
Code Lines | 101 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php declare(strict_types=1); |
||
29 | public function build(AbstractSmrPlayer $player, Template $template): void { |
||
30 | $template->assign('PageTopic', 'Alliance VS Alliance Rankings'); |
||
31 | |||
32 | Menu::rankings(1, 4); |
||
33 | $db = Database::getInstance(); |
||
34 | $container = new self($this->detailsAllianceID); |
||
35 | $template->assign('SubmitHREF', $container->href()); |
||
36 | |||
37 | $this->versusAllianceIDs ??= Request::getIntArray('alliancer', []); |
||
38 | $this->detailsAllianceID ??= Request::getInt('alliance_id', $player->getAllianceID()); |
||
39 | |||
40 | // Get list of alliances that have kills or deaths |
||
41 | $activeAlliances = []; |
||
42 | $dbResult = $db->read('SELECT * FROM alliance WHERE game_id = ' . $db->escapeNumber($player->getGameID()) . ' AND (alliance_deaths > 0 OR alliance_kills > 0) ORDER BY alliance_kills DESC, alliance_name'); |
||
43 | foreach ($dbResult->records() as $dbRecord) { |
||
44 | $allianceID = $dbRecord->getInt('alliance_id'); |
||
45 | $activeAlliances[$allianceID] = SmrAlliance::getAlliance($allianceID, $player->getGameID(), false, $dbRecord); |
||
46 | } |
||
47 | $template->assign('ActiveAlliances', $activeAlliances); |
||
48 | |||
49 | // Get list of alliances to display (max of 5) |
||
50 | // These must be a subset of the active alliances |
||
51 | if (count($this->versusAllianceIDs) === 0) { |
||
|
|||
52 | $alliance_vs_ids = array_slice(array_keys($activeAlliances), 0, 4); |
||
53 | $alliance_vs_ids[] = 0; |
||
54 | } else { |
||
55 | $alliance_vs_ids = $this->versusAllianceIDs; |
||
56 | } |
||
57 | |||
58 | $alliance_vs = []; |
||
59 | foreach ($alliance_vs_ids as $curr_id) { |
||
60 | $curr_alliance = SmrAlliance::getAlliance($curr_id, $player->getGameID()); |
||
61 | $container = new self($curr_id, $this->versusAllianceIDs); |
||
62 | $style = ''; |
||
63 | if (!$curr_alliance->isNone() && $curr_alliance->hasDisbanded()) { |
||
64 | $style = 'class="red"'; |
||
65 | } |
||
66 | if ($player->getAllianceID() == $curr_id) { |
||
67 | $style = 'class="bold"'; |
||
68 | } |
||
69 | $alliance_vs[] = [ |
||
70 | 'ID' => $curr_id, |
||
71 | 'DetailsHREF' => $container->href(), |
||
72 | 'Name' => $curr_alliance->isNone() ? 'No Alliance' : $curr_alliance->getAllianceDisplayName(), |
||
73 | 'Style' => $style, |
||
74 | ]; |
||
75 | } |
||
76 | $template->assign('AllianceVs', $alliance_vs); |
||
77 | |||
78 | $alliance_vs_table = []; |
||
79 | foreach ($alliance_vs_ids as $curr_id) { |
||
80 | $curr_alliance = SmrAlliance::getAlliance($curr_id, $player->getGameID()); |
||
81 | foreach ($alliance_vs_ids as $id) { |
||
82 | $row_alliance = SmrAlliance::getAlliance($id, $player->getGameID()); |
||
83 | $showRed = (!$curr_alliance->isNone() && $curr_alliance->hasDisbanded()) || |
||
84 | (!$row_alliance->isNone() && $row_alliance->hasDisbanded()); |
||
85 | $showBold = $curr_id == $player->getAllianceID() || $id == $player->getAllianceID(); |
||
86 | $style = ''; |
||
87 | if ($curr_id == $id && !$row_alliance->isNone()) { |
||
88 | $value = '--'; |
||
89 | if ($showRed) { |
||
90 | $style = 'class="red"'; |
||
91 | } elseif ($showBold) { |
||
92 | $style = 'class="bold"'; |
||
93 | } |
||
94 | } else { |
||
95 | $dbResult = $db->read('SELECT kills FROM alliance_vs_alliance |
||
96 | WHERE alliance_id_2 = ' . $db->escapeNumber($curr_id) . ' |
||
97 | AND alliance_id_1 = ' . $db->escapeNumber($id) . ' |
||
98 | AND game_id = ' . $db->escapeNumber($player->getGameID())); |
||
99 | $value = $dbResult->hasRecord() ? $dbResult->record()->getInt('kills') : 0; |
||
100 | if ($showRed && $showBold) { |
||
101 | $style = 'class="bold red"'; |
||
102 | } elseif ($showRed) { |
||
103 | $style = 'class="red"'; |
||
104 | } elseif ($showBold) { |
||
105 | $style = 'class="bold"'; |
||
106 | } |
||
107 | } |
||
108 | $alliance_vs_table[$curr_id][$id] = [ |
||
109 | 'Value' => $value, |
||
110 | 'Style' => $style, |
||
111 | ]; |
||
112 | } |
||
113 | } |
||
114 | $template->assign('AllianceVsTable', $alliance_vs_table); |
||
115 | |||
116 | // Show details for a specific alliance |
||
117 | $main_alliance = SmrAlliance::getAlliance($this->detailsAllianceID, $player->getGameID()); |
||
118 | $mainName = $main_alliance->isNone() ? 'No Alliance' : $main_alliance->getAllianceDisplayName(); |
||
119 | $template->assign('DetailsName', $mainName); |
||
120 | |||
121 | $kills = []; |
||
122 | $dbResult = $db->read('SELECT * FROM alliance_vs_alliance |
||
123 | WHERE alliance_id_1 = ' . $db->escapeNumber($this->detailsAllianceID) . ' |
||
124 | AND game_id = ' . $db->escapeNumber($player->getGameID()) . ' ORDER BY kills DESC'); |
||
125 | foreach ($dbResult->records() as $dbRecord) { |
||
126 | $id = $dbRecord->getInt('alliance_id_2'); |
||
127 | $alliance_name = match (true) { |
||
128 | $id > 0 => SmrAlliance::getAlliance($id, $player->getGameID())->getAllianceDisplayName(), |
||
129 | $id == 0 => 'No Alliance', |
||
130 | $id == ALLIANCE_VS_FORCES => '<span class="yellow">Forces</span>', |
||
131 | $id == ALLIANCE_VS_PLANETS => '<span class="yellow">Planets</span>', |
||
132 | $id == ALLIANCE_VS_PORTS => '<span class="yellow">Ports</span>', |
||
133 | default => throw new Exception('Unknown alliance ID: ' . $id), |
||
134 | }; |
||
135 | |||
136 | $kills[] = [ |
||
137 | 'Name' => $alliance_name, |
||
138 | 'Kills' => $dbRecord->getInt('kills'), |
||
139 | ]; |
||
140 | } |
||
141 | $template->assign('Kills', $kills); |
||
142 | |||
143 | $deaths = []; |
||
144 | $dbResult = $db->read('SELECT * FROM alliance_vs_alliance |
||
145 | WHERE alliance_id_2 = ' . $db->escapeNumber($this->detailsAllianceID) . ' |
||
146 | AND game_id = ' . $db->escapeNumber($player->getGameID()) . ' ORDER BY kills DESC'); |
||
147 | foreach ($dbResult->records() as $dbRecord) { |
||
148 | $id = $dbRecord->getInt('alliance_id_1'); |
||
149 | $alliance_name = match (true) { |
||
150 | $id > 0 => SmrAlliance::getAlliance($id, $player->getGameID())->getAllianceDisplayName(), |
||
151 | $id == 0 => 'No Alliance', |
||
152 | $id == ALLIANCE_VS_FORCES => '<span class="yellow">Forces</span>', |
||
153 | $id == ALLIANCE_VS_PLANETS => '<span class="yellow">Planets</span>', |
||
154 | $id == ALLIANCE_VS_PORTS => '<span class="yellow">Ports</span>', |
||
155 | default => throw new Exception('Unknown alliance ID: ' . $id), |
||
156 | }; |
||
157 | |||
158 | $deaths[] = [ |
||
159 | 'Name' => $alliance_name, |
||
160 | 'Deaths' => $dbRecord->getInt('kills'), |
||
161 | ]; |
||
162 | } |
||
163 | $template->assign('Deaths', $deaths); |
||
164 | } |
||
167 |