We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 9 |
| Paths | 16 |
| Total Lines | 71 |
| Code Lines | 48 |
| 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); |
||
| 21 | public function build(AbstractSmrPlayer $player, Template $template): void { |
||
| 22 | $session = Session::getInstance(); |
||
| 23 | |||
| 24 | $account_num = $this->anonBankID; |
||
| 25 | $maxValue = $session->getRequestVarInt('maxValue', 0); |
||
| 26 | $minValue = $session->getRequestVarInt('minValue', 0); |
||
| 27 | |||
| 28 | $db = Database::getInstance(); |
||
| 29 | $dbResult = $db->read('SELECT * |
||
| 30 | FROM anon_bank |
||
| 31 | WHERE anon_id=' . $db->escapeNumber($account_num) . ' |
||
| 32 | AND game_id=' . $db->escapeNumber($player->getGameID())); |
||
| 33 | $dbRecord = $dbResult->record(); |
||
| 34 | |||
| 35 | $balance = $dbRecord->getInt('amount'); |
||
| 36 | $template->assign('Balance', $balance); |
||
| 37 | |||
| 38 | if ($maxValue <= 0) { |
||
| 39 | $dbResult = $db->read('SELECT IFNULL(MAX(transaction_id), 5) as max_transaction_id FROM anon_bank_transactions |
||
| 40 | WHERE game_id=' . $db->escapeNumber($player->getGameID()) . ' |
||
| 41 | AND anon_id=' . $db->escapeNumber($account_num)); |
||
| 42 | $maxValue = $dbResult->record()->getInt('max_transaction_id'); |
||
| 43 | } |
||
| 44 | |||
| 45 | if ($minValue <= 0 || $minValue >= $maxValue) { |
||
| 46 | $minValue = max(1, $maxValue - 5); |
||
| 47 | } |
||
| 48 | |||
| 49 | $query = 'SELECT * |
||
| 50 | FROM player |
||
| 51 | JOIN anon_bank_transactions USING (game_id, account_id) |
||
| 52 | WHERE player.game_id=' . $db->escapeNumber($player->getGameID()) . ' |
||
| 53 | AND anon_bank_transactions.anon_id=' . $db->escapeNumber($account_num); |
||
| 54 | |||
| 55 | if ($maxValue > 0) { |
||
| 56 | $query .= ' AND transaction_id>=' . $db->escapeNumber($minValue) . ' |
||
| 57 | AND transaction_id<=' . $db->escapeNumber($maxValue) . ' |
||
| 58 | ORDER BY time LIMIT ' . (1 + $maxValue - $minValue); |
||
| 59 | } else { |
||
| 60 | $query .= ' ORDER BY time LIMIT 10'; |
||
| 61 | } |
||
| 62 | |||
| 63 | $dbResult = $db->read($query); |
||
| 64 | |||
| 65 | // only if we have at least one result |
||
| 66 | if ($dbResult->hasRecord()) { |
||
| 67 | $template->assign('MinValue', $minValue); |
||
| 68 | $template->assign('MaxValue', $maxValue); |
||
| 69 | $container = new self($account_num); |
||
| 70 | $template->assign('ShowHREF', $container->href()); |
||
| 71 | |||
| 72 | $transactions = []; |
||
| 73 | foreach ($dbResult->records() as $dbRecord) { |
||
| 74 | $transactionPlayer = SmrPlayer::getPlayer($dbRecord->getInt('account_id'), $player->getGameID(), false, $dbRecord); |
||
| 75 | $transaction = $dbRecord->getString('transaction'); |
||
| 76 | $amount = number_format($dbRecord->getInt('amount')); |
||
| 77 | $transactions[$dbRecord->getInt('transaction_id')] = [ |
||
| 78 | 'date' => date($player->getAccount()->getDateTimeFormatSplit(), $dbRecord->getInt('time')), |
||
| 79 | 'payment' => $transaction == 'Payment' ? $amount : '', |
||
| 80 | 'deposit' => $transaction == 'Deposit' ? $amount : '', |
||
| 81 | 'link' => $transactionPlayer->getLinkedDisplayName(), |
||
| 82 | ]; |
||
| 83 | } |
||
| 84 | $template->assign('Transactions', $transactions); |
||
| 85 | } |
||
| 86 | |||
| 87 | $container = new AnonBankDetailProcessor($account_num); |
||
| 88 | $template->assign('TransactionHREF', $container->href()); |
||
| 89 | |||
| 90 | $template->assign('PageTopic', 'Anonymous Account #' . $account_num); |
||
| 91 | Menu::bank(); |
||
| 92 | } |
||
| 95 |