Inventory::execute()   B
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 31
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 8.8571
c 0
b 0
f 0
cc 3
eloc 20
nc 3
nop 0
1
<?php
2
3
namespace Rottenwood\KingdomBundle\Command\Game;
4
5
use Rottenwood\KingdomBundle\Command\Infrastructure\AbstractGameCommand;
6
use Rottenwood\KingdomBundle\Command\Infrastructure\CommandResponse;
7
8
/**
9
 * Просмотр инвентаря и одетых вещей игрока
10
 * Применение в js: Kingdom.Websocket.command('inventory')
11
 */
12
class Inventory extends AbstractGameCommand
13
{
14
15
    /** {@inheritDoc} */
16
    public function execute(): CommandResponse
17
    {
18
        $inventoryItems = $this->container->get('kingdom.inventory_item_repository')->findByUser($this->user);
19
20
        $itemData = [];
21
        foreach ($inventoryItems as $inventoryItem) {
22
            $item = $inventoryItem->getItem();
23
            $itemId = $item->getId();
24
            $itemSlot = $inventoryItem->getSlot();
25
26
            $itemResult = [
27
                'itemId'       => $itemId,
28
                'name'         => $item->getName(),
29
                'name4'        => $item->getName4(),
30
                'description'  => $item->getDescription(),
31
                'quantity'     => $inventoryItem->getQuantity(),
32
                'allowedSlots' => $item->getSlots(),
33
                'pic'          => $item->getPicture(),
34
            ];
35
36
            if ($itemSlot) {
37
                $itemResult['slot'] = $itemSlot;
38
            }
39
40
            $itemData[] = $itemResult;
41
        }
42
43
        $this->result->setData($itemData);
44
45
        return $this->result;
46
    }
47
}
48