ChatServerCommand   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
eloc 11
c 2
b 0
f 0
dl 0
loc 28
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 5 1
A execute() 0 13 1
1
<?php
2
3
namespace AppBundle\Command;
4
5
use AppBundle\Server\Chat;
6
use Ratchet\Http\HttpServer;
7
use Ratchet\Server\IoServer;
8
use Ratchet\WebSocket\WsServer;
9
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Output\OutputInterface;
12
13
/**
14
 * Chat Server Command.
15
 */
16
class ChatServerCommand extends ContainerAwareCommand
17
{
18
    /**
19
     * {@inheritdoc}
20
     */
21
    protected function configure()
22
    {
23
        $this
24
            ->setName('afsy:app:chat-server')
25
            ->setDescription('Start chat server');
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    protected function execute(InputInterface $input, OutputInterface $output)
32
    {
33
        // Initialize
34
        $wsConfig = $this->getContainer()->getParameter('afsy_chat.websocket');
35
36
        // Create server and run it!
37
        $server = IoServer::factory(
38
            new HttpServer(new WsServer(new Chat())),
39
            $wsConfig['port'],
40
            $wsConfig['host']
41
        );
42
        echo sprintf('Run server on %s:%s'."\n", $wsConfig['host'], $wsConfig['port']);
43
        $server->run();
44
    }
45
}
46