We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 21 |
Paths | 160 |
Total Lines | 74 |
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); |
||
35 | public function build(SmrAccount $account): never { |
||
36 | $usedNames = []; |
||
37 | |||
38 | $i = 1; |
||
39 | $attackers = []; |
||
40 | if (Request::has('attackers')) { |
||
41 | foreach (Request::getArray('attackers') as $attackerName) { |
||
42 | if ($attackerName == 'none') { |
||
43 | continue; |
||
44 | } |
||
45 | if (isset($usedNames[$attackerName])) { |
||
46 | create_error('Duplicate name used: ' . $attackerName); |
||
47 | } |
||
48 | $usedNames[$attackerName] = true; |
||
49 | $attackers[$i] = DummyShip::getCachedDummyShip($attackerName)->getPlayer(); |
||
50 | ++$i; |
||
51 | } |
||
52 | } |
||
53 | |||
54 | $i = 1; |
||
55 | $defenders = []; |
||
56 | foreach (Request::getArray('defenders') as $defenderName) { |
||
57 | if ($defenderName == 'none') { |
||
58 | continue; |
||
59 | } |
||
60 | if (isset($usedNames[$defenderName])) { |
||
61 | create_error('Duplicate name used: ' . $defenderName); |
||
62 | } |
||
63 | $usedNames[$defenderName] = true; |
||
64 | $defenders[$i] = DummyShip::getCachedDummyShip($defenderName)->getPlayer(); |
||
65 | ++$i; |
||
66 | } |
||
67 | |||
68 | if (Request::has('repair')) { |
||
69 | foreach ([...$attackers, ...$defenders] as $player) { |
||
70 | $player->setDead(false); |
||
71 | $player->getShip()->setHardwareToMax(); |
||
72 | } |
||
73 | } |
||
74 | |||
75 | $results = null; |
||
76 | if (Request::has('run') || Request::has('death_run')) { |
||
77 | if (Request::has('death_run')) { |
||
78 | $maxRounds = 100; |
||
79 | } else { |
||
80 | $maxRounds = 1; |
||
81 | } |
||
82 | $attackersLeft = $attackers; |
||
83 | $defendersLeft = $defenders; |
||
84 | for ($round = 0; $round < $maxRounds; $round++) { |
||
85 | foreach ($attackersLeft as $key => $teamPlayer) { |
||
86 | if ($teamPlayer->isDead()) { |
||
87 | unset($attackersLeft[$key]); |
||
88 | } |
||
89 | } |
||
90 | foreach ($defendersLeft as $key => $teamPlayer) { |
||
91 | if ($teamPlayer->isDead()) { |
||
92 | unset($defendersLeft[$key]); |
||
93 | } |
||
94 | } |
||
95 | if (count($attackersLeft) == 0 || count($defendersLeft) == 0) { |
||
96 | break; |
||
97 | } |
||
98 | $results = runAnAttack($attackersLeft, $defendersLeft); |
||
99 | } |
||
100 | } |
||
101 | |||
102 | // Save ships unless we're just updating the dummy list |
||
103 | if (!Request::has('update')) { |
||
104 | DummyShip::saveDummyShips(); |
||
105 | } |
||
106 | |||
107 | $container = new CombatSimulator($results, $attackers, $defenders); |
||
108 | $container->go(); |
||
109 | } |
||
112 |