We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 14 |
Paths | 576 |
Total Lines | 81 |
Code Lines | 53 |
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); |
||
27 | public function build(SmrAccount $account, Template $template): void { |
||
28 | $game = SmrGame::getGame($this->gameID); |
||
29 | $template->assign('PageTopic', 'Check Map : ' . $game->getDisplayName()); |
||
30 | |||
31 | $container = new EditGalaxy($this->gameID, $this->galaxyID); |
||
32 | $template->assign('BackHREF', $container->href()); |
||
33 | |||
34 | $galaxies = $game->getGalaxies(); |
||
35 | |||
36 | // Check if any locations are missing |
||
37 | $existingLocs = []; |
||
38 | foreach ($galaxies as $galaxy) { |
||
39 | foreach ($galaxy->getLocations() as $sectorLocs) { |
||
40 | foreach (array_keys($sectorLocs) as $locID) { |
||
41 | $existingLocs[$locID] = true; |
||
42 | } |
||
43 | } |
||
44 | } |
||
45 | $missingLocs = array_diff( |
||
46 | array_keys(SmrLocation::getAllLocations($this->gameID)), |
||
47 | array_keys($existingLocs) |
||
48 | ); |
||
49 | $missingLocNames = []; |
||
50 | foreach ($missingLocs as $locID) { |
||
51 | $missingLocNames[] = SmrLocation::getLocation($this->gameID, $locID)->getName(); |
||
52 | } |
||
53 | $template->assign('MissingLocNames', $missingLocNames); |
||
54 | |||
55 | // Calculate the best trade routes for each galaxy |
||
56 | $tradeGoods = [GOODS_NOTHING => true]; |
||
57 | foreach (TradeGood::getAllIDs() as $goodID) { |
||
58 | $tradeGoods[$goodID] = true; |
||
59 | } |
||
60 | $tradeRaces = []; |
||
61 | foreach (Race::getAllIDs() as $raceID) { |
||
62 | $tradeRaces[$raceID] = true; |
||
63 | } |
||
64 | |||
65 | $maxNumberOfPorts = 2; |
||
66 | $routesForPort = -1; |
||
67 | $numberOfRoutes = 1; |
||
68 | $maxDistance = 999; |
||
69 | |||
70 | $allGalaxyRoutes = []; |
||
71 | foreach ($galaxies as $galaxy) { |
||
72 | $galaxy->getSectors(); // Efficiently construct the sector cache |
||
73 | $ports = $galaxy->getPorts(); |
||
74 | $distances = Plotter::calculatePortToPortDistances($ports, $tradeRaces, $maxDistance, $galaxy->getStartSector(), $galaxy->getEndSector()); |
||
75 | $allGalaxyRoutes[$galaxy->getDisplayName()] = RouteGenerator::generateMultiPortRoutes($maxNumberOfPorts, $ports, $tradeGoods, $tradeRaces, $distances, $routesForPort, $numberOfRoutes); |
||
76 | } |
||
77 | $template->assign('AllGalaxyRoutes', $allGalaxyRoutes); |
||
78 | |||
79 | $routeTypes = [ |
||
80 | RouteGenerator::EXP_ROUTE => 'Experience', |
||
81 | RouteGenerator::MONEY_ROUTE => 'Profit', |
||
82 | ]; |
||
83 | $template->assign('RouteTypes', $routeTypes); |
||
84 | |||
85 | // Largest port sell multipliers per galaxy |
||
86 | $maxSellMultipliers = []; |
||
87 | foreach ($galaxies as $galaxy) { |
||
88 | $max = []; |
||
89 | foreach ($galaxy->getPorts() as $port) { |
||
90 | foreach ($port->getSellGoodIDs() as $goodID) { |
||
91 | $distance = $port->getGoodDistance($goodID); |
||
92 | // For distance ties, prefer higher good IDs |
||
93 | if (empty($max) || $distance >= $max['Distance']) { |
||
94 | $max = [ |
||
95 | 'Port' => $port, |
||
96 | 'GoodID' => $goodID, |
||
97 | 'Distance' => $distance, |
||
98 | ]; |
||
99 | } |
||
100 | } |
||
101 | } |
||
102 | if (!empty($max)) { |
||
103 | $output = $max['Distance'] . 'x ' . TradeGood::get($max['GoodID'])->name . ' at Port #' . $max['Port']->getSectorID() . ' (' . $max['Port']->getRaceName() . ')'; |
||
104 | $maxSellMultipliers[$galaxy->getDisplayName()] = $output; |
||
105 | } |
||
106 | } |
||
107 | $template->assign('MaxSellMultipliers', $maxSellMultipliers); |
||
108 | } |
||
111 |