LookUser   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 41
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B execute() 0 33 3
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