NodeLogCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 23 1
A execute() 0 18 3
1
<?php
2
3
namespace Rottenwood\KingdomBundle\Command\Console;
4
5
use Rottenwood\KingdomBundle\Exception\InvalidCommandParameter;
6
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
/** {@inheritDoc} */
12
class NodeLogCommand extends ContainerAwareCommand
13
{
14
15
    /** {@inheritDoc} */
16
    protected function configure()
17
    {
18
        $this->setName('kingdom:node:log');
19
        $this->setDescription('Точка входа для логирования событий из node.js');
20
21
        $this->addArgument(
22
            'event',
23
            InputArgument::REQUIRED,
24
            'имя события'
25
        );
26
27
        $this->addArgument(
28
            'userId',
29
            InputArgument::REQUIRED,
30
            'id игрока'
31
        );
32
33
        $this->addArgument(
34
            'userName',
35
            InputArgument::REQUIRED,
36
            'имя игрока'
37
        );
38
    }
39
40
    /** {@inheritDoc} */
41
    protected function execute(InputInterface $input, OutputInterface $output)
42
    {
43
        $logger = $this->getContainer()->get('kingdom.logger');
44
45
        $event = $input->getArgument('event');
46
        $userId = $input->getArgument('userId');
47
        $userName = $input->getArgument('userName');
48
49
        if ($event == 'playerEnter') {
50
            $eventPhrase = 'присоединился к игре';
51
        } elseif ($event == 'playerExit') {
52
            $eventPhrase = 'вышел из игры';
53
        } else {
54
            throw new InvalidCommandParameter('Неизвестное событие: ' . $event);
55
        }
56
57
        $logger->info(sprintf('[%d]%s %s', $userId, $userName, $eventPhrase));
58
    }
59
}
60