Completed
Push — master ( c3eed0...8baa58 )
by Sébastien
04:16 queued 01:32
created

PjbServerStartCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 91.3%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 5
dl 0
loc 49
ccs 21
cts 23
cp 0.913
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 17 1
A execute() 0 19 3
1
<?php
2
3
namespace PjbServer\Tools\Console\Command;
4
5
use PjbServer\Tools\StandaloneServer;
6
use Symfony\Component\Console\Command\Command;
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
12
13
class PjbServerStartCommand extends Command
14
{
15
    /**
16
     * @var StandaloneServer
17
     */
18
    protected $server;
19
20
21
    /**
22
     * {@inheritdoc}
23
     */
24 4
    protected function configure()
25
    {
26 4
        $this->setName('pjbserver:start')
27 4
             ->setDescription(
28
                 'Start the standalone pjb server (java)'
29 4
               )
30 4
            ->addArgument(
31 4
                'config-file',
32 4
                InputArgument::REQUIRED,
33
                'Configuration file, see ./dist/pjbserver.config.php.dist'
34 4
            )
35
36 4
             ->setHelp(<<<EOT
37
Start the php java bridge server in the background.
38
EOT
39 4
        );
40 4
    }
41
42 1
    protected function execute(InputInterface $input, OutputInterface $output)
43
    {
44 1
        $file = $input->getArgument('config-file');
45
46
        // Test if config file exists
47 1
        if (!file_exists($file) || !is_readable($file)) {
48
            $msg = "Configuration file '$file' does not exists or is not readable'";
49
            throw new \InvalidArgumentException($msg);
50
        }
51 1
        $params = include($file);
52 1
        $port = $params['port'];
53
54 1
        $config = new StandaloneServer\Config($params);
55
56 1
        $this->server = new StandaloneServer($config);
57 1
        $this->server->start();
58
59 1
        $output->write("Server successfully started on port $port" . PHP_EOL);
60 1
    }
61
}
62