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 — main ( 5797ad...3faf69 )
by Dan
29s queued 24s
created

CreateLocations::build()   F

Complexity

Conditions 20
Paths 2322

Size

Total Lines 87
Code Lines 51

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 20
eloc 51
nc 2322
nop 2
dl 0
loc 87
rs 0
c 1
b 0
f 0

How to fix   Long Method    Complexity   

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\Admin\UniGen;
4
5
use Smr\Admin\UniGenLocationCategories;
6
use Smr\Page\AccountPage;
7
use Smr\Page\ReusableTrait;
8
use Smr\Request;
9
use Smr\Template;
10
use SmrAccount;
11
use SmrGalaxy;
12
use SmrLocation;
13
14
class CreateLocations extends AccountPage {
15
16
	use ReusableTrait;
17
18
	public string $file = 'admin/unigen/universe_create_locations.php';
19
20
	public function __construct(
21
		private readonly int $gameID,
22
		private ?int $galaxyID = null
23
	) {}
24
25
	public function build(SmrAccount $account, Template $template): void {
26
		$this->galaxyID ??= Request::getInt('gal_on');
27
		$template->assign('Galaxies', SmrGalaxy::getGameGalaxies($this->gameID));
28
29
		$container = new self($this->gameID);
30
		$template->assign('JumpGalaxyHREF', $container->href());
31
32
		$locations = SmrLocation::getAllLocations($this->gameID);
33
34
		// Initialize all location counts to zero
35
		$totalLocs = [];
36
		foreach ($locations as $location) {
37
			$totalLocs[$location->getTypeID()] = 0;
38
		}
39
40
		$galaxy = SmrGalaxy::getGalaxy($this->gameID, $this->galaxyID);
41
		$template->assign('Galaxy', $galaxy);
42
43
		// Determine the current amount of each location
44
		foreach ($galaxy->getSectors() as $galSector) {
45
			foreach ($galSector->getLocations() as $sectorLocation) {
46
				$totalLocs[$sectorLocation->getTypeID()]++;
47
			}
48
		}
49
		$template->assign('TotalLocs', $totalLocs);
50
51
		// Remove any linked locations, as they will be added automatically
52
		// with any corresponding HQs.
53
		foreach ($locations as $location) {
54
			foreach ($location->getLinkedLocations() as $linkedLoc) {
55
				unset($locations[$linkedLoc->getTypeID()]);
56
			}
57
		}
58
59
		// Set any extra information to be displayed with each location
60
		$locText = [];
61
		$categories = new UniGenLocationCategories();
62
		foreach ($locations as $location) {
63
			$extra = '<span class="small"><br />';
64
			if ($location->isWeaponSold()) {
65
				$extra .= $categories->addLoc($location->getTypeID(), 'Weapons');
66
				foreach ($location->getWeaponsSold() as $weapon) {
67
					$extra .= $weapon->getName() . '&nbsp;&nbsp;&nbsp;(' . $weapon->getShieldDamage() . '/' . $weapon->getArmourDamage() . '/' . $weapon->getBaseAccuracy() . ')<br />';
68
				}
69
			}
70
			if ($location->isShipSold()) {
71
				$extra .= $categories->addLoc($location->getTypeID(), 'Ships');
72
				foreach ($location->getShipsSold() as $shipSold) {
73
					$extra .= $shipSold->getName() . '<br />';
74
				}
75
			}
76
			if ($location->isHardwareSold()) {
77
				$extra .= $categories->addLoc($location->getTypeID(), 'Hardware');
78
				foreach ($location->getHardwareSold() as $hardware) {
79
					$extra .= $hardware['Name'] . '<br />';
80
				}
81
			}
82
			if ($location->isBar()) {
83
				$extra .= $categories->addLoc($location->getTypeID(), 'Bars');
84
			}
85
			if ($location->isBank()) {
86
				$extra .= $categories->addLoc($location->getTypeID(), 'Banks');
87
			}
88
			if ($location->isHQ() || $location->isUG() || $location->isFed()) {
89
				$extra .= $categories->addLoc($location->getTypeID(), 'Headquarters');
90
				foreach ($location->getLinkedLocations() as $linkedLoc) {
91
					$extra .= $linkedLoc->getName() . '<br />';
92
				}
93
			}
94
			if (!$categories->added($location->getTypeID())) {
95
				// Anything that doesn't fit the other categories
96
				$extra .= $categories->addLoc($location->getTypeID(), 'Miscellaneous');
97
			}
98
			$extra .= '</span>';
99
100
			$locText[$location->getTypeID()] = $location->getName() . $extra;
101
		}
102
		$template->assign('LocText', $locText);
103
		$template->assign('LocTypes', $categories->locTypes);
104
105
		// Form to make location changes
106
		$container = new SaveProcessor($this->gameID, $this->galaxyID);
107
		$template->assign('CreateLocationsFormHREF', $container->href());
108
109
		// HREF to cancel and return to the previous page
110
		$container = new EditGalaxy($this->gameID, $this->galaxyID);
111
		$template->assign('CancelHREF', $container->href());
112
	}
113
114
}
115