| Conditions | 16 |
| Paths | 14 |
| Total Lines | 87 |
| Code Lines | 55 |
| 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 ($text === false || mb_strlen($text) > 60) { |
||
|
|
|||
| 80 | $game->addInformation(_("Der Text darf nicht länger als 60 Zeichen sein")); |
||
| 81 | return; |
||
| 82 | } |
||
| 83 | |||
| 84 | if (empty($text)) { |
||
| 85 | $game->addInformation(_("Der Text darf nicht leer sein")); |
||
| 86 | return; |
||
| 87 | } |
||
| 88 | |||
| 89 | $storage = $ship->getStorage(); |
||
| 90 | |||
| 91 | $commodity = $this->commodityRepository->find(CommodityTypeEnum::BASE_ID_BUOY); |
||
| 92 | if ($commodity !== null && !$storage->containsKey($commodity->getId())) { |
||
| 93 | $game->addInformationf( |
||
| 94 | _('Es wird eine Boje benötigt') |
||
| 95 | ); |
||
| 96 | return; |
||
| 97 | } |
||
| 98 | |||
| 99 | if ($epsSystem->getEps() < 1) { |
||
| 100 | $game->addInformation(_('Es wird 1 Energie für den Start der Boje benötigt')); |
||
| 101 | return; |
||
| 102 | } |
||
| 103 | |||
| 104 | if ($commodity !== null) { |
||
| 105 | $this->shipStorageManager->lowerStorage( |
||
| 106 | $ship, |
||
| 107 | $commodity, |
||
| 108 | 1 |
||
| 109 | ); |
||
| 110 | } |
||
| 111 | |||
| 112 | $buoy = $this->buoyRepository->prototype(); |
||
| 113 | $buoy->setUser($game->getUser()); |
||
| 114 | $buoy->setText($text); |
||
| 115 | |||
| 116 | |||
| 117 | if ($ship->getStarsystemMap() !== null) { |
||
| 118 | $buoy->setSystemMap($ship->getStarsystemMap()); |
||
| 119 | } else { |
||
| 120 | $buoy->setMap($ship->getMap()); |
||
| 121 | } |
||
| 122 | |||
| 123 | |||
| 124 | $this->buoyRepository->save($buoy); |
||
| 125 | $epsSystem->lowerEps(1)->update(); |
||
| 126 | |||
| 127 | $game->addInformation(_('Die Boje wurde erfolgreich platziert')); |
||
| 128 | } |
||
| 134 | } |