| Conditions | 10 |
| Paths | 11 |
| Total Lines | 70 |
| Code Lines | 46 |
| 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 |
||
| 45 | public function handle(GameControllerInterface $game): void |
||
| 46 | { |
||
| 47 | $game->setView(ShowShip::VIEW_IDENTIFIER); |
||
| 48 | $userId = $game->getUser()->getId(); |
||
| 49 | $wrapper = $this->shipLoader->getWrapperByIdAndUser( |
||
| 50 | request::indInt('id'), |
||
| 51 | $userId |
||
| 52 | ); |
||
| 53 | $ship = $wrapper->get(); |
||
| 54 | $buoyId = request::indInt('buoy_id'); |
||
| 55 | $epsSystem = $wrapper->getEpsSystemData(); |
||
| 56 | |||
| 57 | if ($epsSystem === null || $epsSystem->getEps() == 0) { |
||
| 58 | $game->addInformation(_("Keine Energie vorhanden")); |
||
| 59 | return; |
||
| 60 | } |
||
| 61 | if ($ship->getCloakState()) { |
||
| 62 | $game->addInformation(_("Die Tarnung ist aktiviert")); |
||
| 63 | return; |
||
| 64 | } |
||
| 65 | if ($ship->getWarpState()) { |
||
| 66 | $game->addInformation(_("Der Warpantrieb ist aktiviert")); |
||
| 67 | return; |
||
| 68 | } |
||
| 69 | if ($ship->getShieldState()) { |
||
| 70 | $game->addInformation(_("Die Schilde sind aktiviert")); |
||
| 71 | return; |
||
| 72 | } |
||
| 73 | |||
| 74 | if ($epsSystem->getEps() < 1) { |
||
| 75 | $game->addInformation(_('Es wird 1 Energie für den Start der Boje benötigt')); |
||
| 76 | return; |
||
| 77 | } |
||
| 78 | |||
| 79 | $commodity = $this->commodityRepository->find(CommodityTypeEnum::BASE_ID_BUOY); |
||
| 80 | |||
| 81 | if ($commodity !== null) { |
||
| 82 | $this->shipStorageManager->upperStorage( |
||
| 83 | $ship, |
||
| 84 | $commodity, |
||
| 85 | 1 |
||
| 86 | ); |
||
| 87 | } |
||
| 88 | |||
| 89 | $buoy = $this->buoyRepository->find($buoyId); |
||
| 90 | if ($buoy === null) { |
||
| 91 | $game->addInformation(_("Die Boje existiert nicht")); |
||
| 92 | return; |
||
| 93 | } |
||
| 94 | |||
| 95 | if ($buoy->getUserId() !== $userId) { |
||
| 96 | $this->privateMessageSender->send( |
||
| 97 | $game->getUser()->getId(), |
||
| 98 | $buoy->getUserId(), |
||
| 99 | sprintf( |
||
| 100 | _('Deine Boje %s wurde von der %s bei %s aufgebracht.'), |
||
| 101 | $buoy->getText(), |
||
| 102 | $ship->getName(), |
||
| 103 | $ship->getSectorString() |
||
| 104 | ), |
||
| 105 | PrivateMessageFolderSpecialEnum::PM_SPECIAL_SHIP, |
||
| 106 | null |
||
| 107 | ); |
||
| 108 | } |
||
| 109 | |||
| 110 | $this->buoyRepository->delete($buoy); |
||
| 111 | |||
| 112 | $epsSystem->lowerEps(1)->update(); |
||
| 113 | |||
| 114 | $game->addInformation(_('Die Boje wurde erfolgreich eingesammelt')); |
||
| 115 | } |
||
| 121 | } |