ShowPlayersInRoom::execute()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 11
nc 1
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\Entity\Infrastructure\User;
8
9
/**
10
 * Отображение игроков в текущей комнате
11
 * Применение в js: Kingdom.Websocket.command('showPlayersInRoom')
12
 */
13
class ShowPlayersInRoom extends AbstractGameCommand
14
{
15
16
    /** {@inheritDoc} */
17
    public function execute(): CommandResponse
18
    {
19
        $playersInRoom = array_map(
20
            function (User $user) {
21
                return [
22
                    'name'   => $user->getName(),
23
                    'stance' => 'стоит тут.',
24
                ];
25
            },
26
            $this->container->get('kingdom.user_service')->getOnlineHumansInRoom(
27
                $this->user->getRoom(),
28
                $this->user->getId()
29
            )
30
        );
31
32
        $this->result->setData($playersInRoom);
33
34
        return $this->result;
35
    }
36
}
37