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
Push — page-classes ( c69fb3 )
by Dan
07:23
created

AnonBankDetail::build()   B

Complexity

Conditions 9
Paths 16

Size

Total Lines 71
Code Lines 48

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 9
eloc 48
nc 16
nop 2
dl 0
loc 71
rs 7.5789
c 1
b 0
f 0

How to fix   Long Method   

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\Bank;
4
5
use AbstractSmrPlayer;
6
use Menu;
7
use Smr\Database;
8
use Smr\Page\PlayerPage;
9
use Smr\Session;
10
use Smr\Template;
11
use SmrPlayer;
12
13
class AnonBankDetail extends PlayerPage {
14
15
	public string $file = 'bank_anon_detail.php';
16
17
	public function __construct(
18
		private readonly int $anonBankID,
19
	) {}
20
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
	}
93
94
}
95