We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 11 |
Paths | 432 |
Total Lines | 63 |
Code Lines | 45 |
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); |
||
23 | public function build(AbstractSmrPlayer $player, Template $template): void { |
||
24 | $alliance_id = $this->allianceID; |
||
25 | |||
26 | //get all transactions |
||
27 | $db = Database::getInstance(); |
||
28 | $dbResult = $db->read('SELECT * FROM alliance_bank_transactions WHERE alliance_id = ' . $db->escapeNumber($alliance_id) . ' AND game_id = ' . $db->escapeNumber($player->getGameID())); |
||
29 | if (!$dbResult->hasRecord()) { |
||
30 | create_error('Your alliance has no recorded transactions.'); |
||
31 | } |
||
32 | $trans = []; |
||
33 | foreach ($dbResult->records() as $dbRecord) { |
||
34 | $transType = ($dbRecord->getString('transaction') == 'Payment') ? self::WITHDRAW : self::DEPOSIT; |
||
35 | $payeeId = ($dbRecord->getInt('exempt')) ? 0 : $dbRecord->getInt('payee_id'); |
||
36 | // initialize payee if necessary |
||
37 | if (!isset($trans[$payeeId])) { |
||
38 | $trans[$payeeId] = [self::WITHDRAW => 0, self::DEPOSIT => 0]; |
||
39 | } |
||
40 | $trans[$payeeId][$transType] += $dbRecord->getInt('amount'); |
||
41 | } |
||
42 | |||
43 | //ordering |
||
44 | $playerIDs = array_keys($trans); |
||
45 | $totals = []; |
||
46 | foreach ($trans as $accId => $transArray) { |
||
47 | $totals[$accId] = $transArray[self::DEPOSIT] - $transArray[self::WITHDRAW]; |
||
48 | } |
||
49 | arsort($totals, SORT_NUMERIC); |
||
50 | $dbResult = $db->read('SELECT * FROM player WHERE account_id IN (' . $db->escapeArray($playerIDs) . ') AND game_id = ' . $db->escapeNumber($player->getGameID()) . ' ORDER BY player_name'); |
||
51 | $players = [0 => 'Alliance Funds']; |
||
52 | foreach ($dbResult->records() as $dbRecord) { |
||
53 | $players[$dbRecord->getInt('account_id')] = htmlentities($dbRecord->getString('player_name')); |
||
54 | } |
||
55 | |||
56 | //format it this way so its easy to send to the alliance MB if requested. |
||
57 | $text = '<table class="nobord centered" cellspacing="1">'; |
||
58 | $text .= '<tr><th>Player</th><th>Deposits</th><th>Withdrawals</th><th>Total</th></tr>'; |
||
59 | $balance = 0; |
||
60 | foreach ($totals as $accId => $total) { |
||
61 | $balance += $total; |
||
62 | $text .= '<tr>'; |
||
63 | $text .= '<td><span class="yellow">' . $players[$accId] . '</span></td>'; |
||
64 | $text .= '<td class="right">' . number_format($trans[$accId][self::DEPOSIT]) . '</td>'; |
||
65 | $text .= '<td class="right">-' . number_format($trans[$accId][self::WITHDRAW]) . '</td>'; |
||
66 | $text .= '<td class="right"><span class="'; |
||
67 | if ($total < 0) { |
||
68 | $text .= 'red bold'; |
||
69 | } else { |
||
70 | $text .= 'bold'; |
||
71 | } |
||
72 | $text .= '">' . number_format($total) . '</span></td>'; |
||
73 | $text .= '</tr>'; |
||
74 | } |
||
75 | $text .= '</table>'; |
||
76 | $text = '<div class="center"><br />Ending Balance: ' . number_format($balance) . '</div><br />' . $text; |
||
77 | $template->assign('BankReport', $text); |
||
78 | |||
79 | if (!$this->reportSent) { |
||
80 | $container = new AllianceBankReportProcessor($alliance_id, $text); |
||
81 | $template->assign('SendReportHREF', $container->href()); |
||
82 | } |
||
83 | |||
84 | $template->assign('PageTopic', 'Alliance Bank Report'); |
||
85 | Menu::bank(); |
||
86 | } |
||
89 |