ProcessCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 2
cbo 3
dl 0
loc 49
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A configure() 0 9 1
A execute() 0 8 1
1
<?php
2
3
namespace SfCod\SocketIoBundle\Command;
4
5
use Psr\Log\LoggerInterface;
6
use SfCod\SocketIoBundle\Service\Broadcast;
7
use Symfony\Component\Console\Command\Command;
8
use Symfony\Component\Console\Input\InputArgument;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
/**
13
 * Class ProcessCommand
14
 * Run this daemon for listen socketio. Don't forget about run npm install in the folder "server".
15
 *
16
 * @package yiicod\socketio\commands
17
 */
18
class ProcessCommand extends Command
19
{
20
    /**
21
     * @var LoggerInterface
22
     */
23
    protected $logger;
24
25
    /**
26
     * @var Broadcast
27
     */
28
    protected $broadcast;
29
30
    /**
31
     * ProcessCommand constructor.
32
     */
33
    public function __construct(Broadcast $broadcast)
34
    {
35
        $this->broadcast = $broadcast;
36
37
        parent::__construct();
38
    }
39
40
    /**
41
     * Configure command.
42
     */
43
    protected function configure()
44
    {
45
        parent::configure();
46
47
        $this->setName('socket-io:process')
48
            ->setDescription('Starts socket-io process.')
49
            ->addOption('handler', null, InputArgument::OPTIONAL, 'Process handler class', null)
50
            ->addOption('data', null, InputArgument::OPTIONAL, 'Serialized handle data.', null);
51
    }
52
53
    /**
54
     * Execute command.
55
     *
56
     * @return int|void|null
57
     */
58
    public function execute(InputInterface $input, OutputInterface $output)
59
    {
60
        $handler = $input->getOption('handler');
61
62
        $this->broadcast->process($handler, @unserialize($input->getOption('data')) ?? []);
63
64
        return 0;
65
    }
66
}
67