Conditions | 17 |
Paths | 20 |
Total Lines | 94 |
Code Lines | 60 |
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 |
||
41 | public function handle(GameControllerInterface $game): void |
||
42 | { |
||
43 | $game->setView(ShowShip::VIEW_IDENTIFIER); |
||
44 | $userId = $game->getUser()->getId(); |
||
45 | $wrapper = $this->shipLoader->getWrapperByIdAndUser( |
||
46 | request::indInt('id'), |
||
47 | $userId |
||
48 | ); |
||
49 | $ship = $wrapper->get(); |
||
50 | |||
51 | if (!$ship->isSystemHealthy(ShipSystemTypeEnum::SYSTEM_TORPEDO)) { |
||
52 | $game->addInformation(_("Die Torpedorampe ist zerstört")); |
||
53 | return; |
||
54 | } |
||
55 | $epsSystem = $wrapper->getEpsSystemData(); |
||
56 | if ($epsSystem === null || $epsSystem->getEps() == 0) { |
||
57 | $game->addInformation(_("Keine Energie vorhanden")); |
||
58 | return; |
||
59 | } |
||
60 | if ($ship->getCloakState()) { |
||
61 | $game->addInformation(_("Die Tarnung ist aktiviert")); |
||
62 | return; |
||
63 | } |
||
64 | if ($ship->getWarpState()) { |
||
65 | $game->addInformation(_("Der Warpantrieb ist aktiviert")); |
||
66 | return; |
||
67 | } |
||
68 | if ($ship->getShieldState()) { |
||
69 | $game->addInformation(_("Die Schilde sind aktiviert")); |
||
70 | return; |
||
71 | } |
||
72 | if (count($this->buoyRepository->findByUserId($userId)) <= 16) { |
||
73 | $game->addInformation(_("Es können nicht mehr als 16 Bojen platziert werden")); |
||
74 | return; |
||
75 | } |
||
76 | |||
77 | $text = request::postString('text'); |
||
78 | |||
79 | if (mb_strlen($text) > 60) { |
||
|
|||
80 | |||
81 | $game->addInformation(_("Der Text darf nicht länger als 60 Zeichen sein")); |
||
82 | return; |
||
83 | } |
||
84 | |||
85 | if (empty($text)) { |
||
86 | $game->addInformation(_("Der Text darf nicht leer sein.")); |
||
87 | return; |
||
88 | } |
||
89 | |||
90 | $storage = $ship->getStorage(); |
||
91 | |||
92 | $commodity = $this->commodityRepository->find(CommodityTypeEnum::BASE_ID_BOUY); |
||
93 | if ($commodity !== null && !$storage->containsKey($commodity->getId())) { |
||
94 | $game->addInformationf( |
||
95 | _('Es wird eine Boje benötigt') |
||
96 | ); |
||
97 | return; |
||
98 | } |
||
99 | |||
100 | if ($epsSystem->getEps() < 1) { |
||
101 | $game->addInformation(_('Es wird 1 Energie für den Start der Boje benötigt')); |
||
102 | return; |
||
103 | } |
||
104 | |||
105 | if ($commodity !== null) { |
||
106 | $this->shipStorageManager->lowerStorage( |
||
107 | $ship, |
||
108 | $commodity, |
||
109 | 1 |
||
110 | ); |
||
111 | } |
||
112 | |||
113 | $buoy = $this->buoyRepository->prototype(); |
||
114 | $buoy->setUser($game->getUser()); |
||
115 | if ($text != false) { |
||
116 | if (mb_strlen($text) > 60) { |
||
117 | |||
118 | $game->addInformation(_("Der Text darf nicht länger als 60 Zeichen sein")); |
||
119 | return; |
||
120 | } else { |
||
121 | $buoy->setText($text); |
||
122 | } |
||
123 | } |
||
124 | |||
125 | if ($ship->getStarsystemMap() !== null) { |
||
126 | $buoy->setSystemMap($ship->getStarsystemMap()); |
||
127 | } else { |
||
128 | $buoy->setMap($ship->getMap()); |
||
129 | } |
||
130 | |||
131 | $this->buoyRepository->save($buoy); |
||
132 | $epsSystem->lowerEps(1)->update(); |
||
133 | |||
134 | $game->addInformation(_('Die Boje wurde erfolgreich platziert')); |
||
135 | } |
||
141 | } |