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 (#1508)
by Dan
04:48
created

TraderStatus::build()   B

Complexity

Conditions 7
Paths 36

Size

Total Lines 67
Code Lines 44

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 7
eloc 44
nc 36
nop 2
dl 0
loc 67
rs 8.2826
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;
4
5
use AbstractSmrPlayer;
6
use Exception;
7
use Menu;
8
use Smr\Database;
9
use Smr\HardwareType;
10
use Smr\Page\PlayerPage;
11
use Smr\Page\ReusableTrait;
12
use Smr\Template;
13
14
class TraderStatus extends PlayerPage {
15
16
	use ReusableTrait;
17
18
	public string $file = 'trader_status.php';
19
20
	public function build(AbstractSmrPlayer $player, Template $template): void {
21
		$template->assign('PageTopic', 'Trader Status');
22
23
		Menu::trader();
24
25
		if ($player->hasNewbieTurns()) {
26
			$container = new NewbieLeave();
27
			$template->assign('LeaveNewbieHREF', $container->href());
28
		}
29
30
		$container = new TraderRelations();
31
		$template->assign('RelationsHREF', $container->href());
32
33
		$container = new TraderSavings();
34
		$template->assign('SavingsHREF', $container->href());
35
36
		// Bounties
37
		$container = new TraderBounties();
38
		$template->assign('BountiesHREF', $container->href());
39
40
		$template->assign('BountiesClaimable', count($player->getClaimableBounties()));
41
42
		// Ship
43
		$container = new HardwareConfigure();
44
		$template->assign('HardwareHREF', $container->href());
45
46
		$shipType = $player->getShip()->getType();
47
		$hardwareChecks = [
48
			HARDWARE_SCANNER => $shipType->canHaveScanner(),
49
			HARDWARE_ILLUSION => $shipType->canHaveIllusion(),
50
			HARDWARE_CLOAK => $shipType->canHaveCloak(),
51
			HARDWARE_JUMP => $shipType->canHaveJump(),
52
			HARDWARE_DCS => $shipType->canHaveDCS(),
53
		];
54
		$hardware = [];
55
		foreach ($hardwareChecks as $hardwareTypeID => $shipTypeCanHave) {
56
			if ($shipTypeCanHave) {
57
				$hardware[] = HardwareType::get($hardwareTypeID)->name;
58
			}
59
		}
60
		if (empty($hardware)) {
61
			$hardware[] = 'none';
62
		}
63
		$template->assign('Hardware', $hardware);
64
65
		$template->assign('NextLevel', $player->getLevel()->next());
66
67
		$container = new UserRankingView();
68
		$template->assign('UserRankingsHREF', $container->href());
69
70
		$container = new TraderNoteDeleteProcessor();
71
		$template->assign('NoteDeleteHREF', $container->href());
72
73
		$notes = [];
74
		$db = Database::getInstance();
75
		$dbResult = $db->read('SELECT * FROM player_has_notes WHERE ' . $player->getSQL() . ' ORDER BY note_id DESC');
76
		foreach ($dbResult->records() as $dbRecord) {
77
			$note = gzuncompress($dbRecord->getString('note'));
78
			if ($note === false) {
79
				throw new Exception('Failed to gzuncompress note!');
80
			}
81
			$notes[$dbRecord->getInt('note_id')] = $note;
82
		}
83
		$template->assign('Notes', $notes);
84
85
		$container = new TraderNoteAddProcessor();
86
		$template->assign('NoteAddHREF', $container->href());
87
	}
88
89
}
90