Completed
Push — master ( 34fefe...4d65b3 )
by Sébastien
03:46
created

PjbServerRestartCommand::execute()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3.0416

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 18
ccs 10
cts 12
cp 0.8333
rs 9.4285
cc 3
eloc 11
nc 2
nop 2
crap 3.0416
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 PjbServerRestartCommand 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:restart')
27 4
             ->setDescription(
28
                 'Restart 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 4
             ->setHelp(<<<EOT
36
Start the php java bridge server in the background.
37
EOT
38 4
        );
39 4
    }
40
41 1
    protected function execute(InputInterface $input, OutputInterface $output)
42
    {
43 1
        $file = $input->getArgument('config-file');
44
45
        // Test if config file exists
46 1
        if (!file_exists($file) || !is_readable($file)) {
47
            $msg = "Configuration file '$file' does not exists or is not readable'";
48
            throw new \InvalidArgumentException($msg);
49
        }
50 1
        $params = include($file);
51 1
        $port = $params['port'];
52 1
        $config = new StandaloneServer\Config($params);
53
54 1
        $this->server = new StandaloneServer($config);
55 1
        $this->server->restart();
56
57 1
        $output->write("Server successfully restarted on port $port" . PHP_EOL);
58 1
    }
59
}
60