| Conditions | 8 |
| Paths | 7 |
| Total Lines | 66 |
| Code Lines | 44 |
| 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 |
||
| 42 | public function handle(GameControllerInterface $game): void |
||
| 43 | { |
||
| 44 | $game->setView(ShowTools::VIEW_IDENTIFIER); |
||
| 45 | $user = $game->getUser(); |
||
| 46 | |||
| 47 | // only Admins or NPC can trigger |
||
| 48 | if (!$game->isAdmin() && !$game->isNpc()) { |
||
| 49 | $game->addInformation(_('[b][color=#ff2626]Aktion nicht möglich, Spieler ist kein Admin/NPC![/color][/b]')); |
||
| 50 | return; |
||
| 51 | } |
||
| 52 | |||
| 53 | if (!request::getVarByMethod(request::postvars(), 'shipid')) { |
||
| 54 | $game->addInformation("Kein Schiff ausgewählt"); |
||
| 55 | return; |
||
| 56 | } else { |
||
| 57 | $shipId = request::postInt('shipid'); |
||
| 58 | $commodityId = request::postInt('commodityid'); |
||
| 59 | $amount = request::postInt('amount'); |
||
| 60 | $reason = request::postString('reason'); |
||
| 61 | |||
| 62 | |||
| 63 | $wrapper = $this->shipLoader->find($shipId); |
||
| 64 | |||
| 65 | if ($wrapper === null) { |
||
| 66 | throw new ShipDoesNotExistException(_('Ship does not exist!')); |
||
| 67 | } else { |
||
| 68 | $ship = $wrapper->get(); |
||
| 69 | } |
||
| 70 | |||
| 71 | if ($amount < 1) { |
||
| 72 | $game->addInformation("Anzahl muss größer als 0 sein"); |
||
| 73 | return; |
||
| 74 | } |
||
| 75 | |||
| 76 | if ($reason === '') { |
||
|
|
|||
| 77 | $game->addInformation("Grund fehlt"); |
||
| 78 | return; |
||
| 79 | } |
||
| 80 | |||
| 81 | $commodity = $this->commodityRepository->find($commodityId); |
||
| 82 | |||
| 83 | if ($commodity === null) { |
||
| 84 | $game->addInformation("Ungültige Ware"); |
||
| 85 | return; |
||
| 86 | } |
||
| 87 | |||
| 88 | $this->shipStorageManager->upperStorage( |
||
| 89 | $ship, |
||
| 90 | $commodity, |
||
| 91 | $amount |
||
| 92 | ); |
||
| 93 | |||
| 94 | $text = sprintf( |
||
| 95 | '%s hat dem Schiff %s (%d) von Spieler %s (%d) %d %s hinzugefügt. Grund: %s', |
||
| 96 | $user->getName(), |
||
| 97 | $ship->getName(), |
||
| 98 | $ship->getId(), |
||
| 99 | $ship->getUser()->getName(), |
||
| 100 | $ship->getUser()->getId(), |
||
| 101 | $amount, |
||
| 102 | $commodity->getName(), |
||
| 103 | $reason |
||
| 104 | ); |
||
| 105 | |||
| 106 | $this->createEntry($text, $user->getId()); |
||
| 107 | $game->addInformation("Waren hinzugefügt"); |
||
| 108 | } |
||
| 128 |