LookUser::execute()   B
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 33
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 33
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
use Rottenwood\KingdomBundle\Exception\UserNotFound;
8
9
/**
10
 * Просмотр информации и одетых вещей другого игрока
11
 * Применение в js: Kingdom.Websocket.command('lookUser', 'ИмяПерсонажа')
12
 */
13
class LookUser extends AbstractGameCommand
14
{
15
16
    /**
17
     * @return CommandResponse
18
     * @throws UserNotFound
19
     */
20
    public function execute(): CommandResponse
21
    {
22
        $userToLookAt = $this->container->get('kingdom.human_repository')->findByName($this->parameters);
23
24
        if (!$userToLookAt) {
25
            throw new UserNotFound;
26
        }
27
28
        $itemData = [];
29
        foreach ($this->container->get('kingdom.inventory_item_repository')->findByUser(
30
            $userToLookAt
31
        ) as $inventoryItem) {
32
            $item = $inventoryItem->getItem();
33
34
            $itemData[] = [
35
                'name'        => $item->getName(),
36
                'description' => $item->getDescription(),
37
                'slots'       => $item->getSlots(),
38
                'pic'         => $item->getPicture(),
39
                'slot'        => $inventoryItem->getSlot(),
40
            ];
41
        }
42
43
        $this->result->setData(
44
            [
45
                'name'   => $userToLookAt->getName(),
46
                'items'  => $itemData,
47
                'avatar' => $userToLookAt->getAvatar(),
48
            ]
49
        );
50
51
        return $this->result;
52
    }
53
}
54