| Conditions | 8 |
| Paths | 15 |
| Total Lines | 59 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 25 | public function execute(): CommandResponse |
||
| 26 | { |
||
| 27 | $currentRoom = $this->user->getRoom(); |
||
| 28 | $currentX = $currentRoom->getX(); |
||
| 29 | $currentY = $currentRoom->getY(); |
||
| 30 | |||
| 31 | $roomRepository = $this->container->get('kingdom.room_repository'); |
||
| 32 | $resourceRepository = $this->container->get('kingdom.room_resource_repository'); |
||
| 33 | |||
| 34 | $map = []; |
||
| 35 | |||
| 36 | for ($y = $currentY - $this->mapRadius, $relativeY = 1, $relativeX = 1; |
||
|
|
|||
| 37 | $y <= $currentY + $this->mapRadius; |
||
| 38 | $y++, $relativeY++, $relativeX = 1) { |
||
| 39 | |||
| 40 | for ($x = $currentX - $this->mapRadius; |
||
| 41 | $x <= $currentX + $this->mapRadius; |
||
| 42 | $x++, $relativeX++) { |
||
| 43 | |||
| 44 | // пропуск центра карты, комнаты где находится персонаж |
||
| 45 | if ($relativeY == 3 && $relativeX == 3) { |
||
| 46 | continue; |
||
| 47 | } |
||
| 48 | |||
| 49 | $room = $roomRepository->findOneByXandY($x, $y); |
||
| 50 | |||
| 51 | if ($room) { |
||
| 52 | $map[] = $this->addRoom($room, $relativeX, $relativeY); |
||
| 53 | } |
||
| 54 | } |
||
| 55 | } |
||
| 56 | |||
| 57 | $result = [ |
||
| 58 | 'name' => $currentRoom->getName(), |
||
| 59 | 'description' => $currentRoom->getDescription(), |
||
| 60 | 'x' => $currentX, |
||
| 61 | 'y' => $currentY, |
||
| 62 | ]; |
||
| 63 | |||
| 64 | $roomResources = $resourceRepository->findByRoom($currentRoom); |
||
| 65 | |||
| 66 | foreach ($roomResources as $roomResource) { |
||
| 67 | $resourceQuantity = $roomResource->getQuantity(); |
||
| 68 | |||
| 69 | if ($resourceQuantity > 0) { |
||
| 70 | $result['resources'][] = [ |
||
| 71 | 'id' => $roomResource->getItem()->getId(), |
||
| 72 | 'name' => $roomResource->getItem()->getName(), |
||
| 73 | 'name4' => $roomResource->getItem()->getName4(), |
||
| 74 | 'quantity' => $resourceQuantity, |
||
| 75 | ]; |
||
| 76 | } |
||
| 77 | } |
||
| 78 | |||
| 79 | $this->result->setData($result); |
||
| 80 | $this->result->setMapData($map); |
||
| 81 | |||
| 82 | return $this->result; |
||
| 83 | } |
||
| 84 | |||
| 100 |