Completed
Push — master ( cc84b4...34fefe )
by Sébastien
03:30
created

PjbServerStopCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 47.83%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 5
dl 0
loc 48
ccs 11
cts 23
cp 0.4783
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 16 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 PjbServerStopCommand extends Command
14
{
15
    /**
16
     * @var StandaloneServer
17
     */
18
    protected $server;
19
20
21
    /**
22
     * {@inheritdoc}
23
     */
24 1
    protected function configure()
25
    {
26 1
        $this->setName('pjbserver:stop')
27 1
             ->setDescription(
28
                 'Stop the standalone pjb server (java)'
29 1
               )
30 1
            ->addArgument(
31 1
                'config-file',
32 1
                InputArgument::REQUIRED,
33
                'Configuration file, see ./dist/pjbserver.config.php.dist'
34 1
            )
35 1
             ->setHelp(<<<EOT
36
Stop the standalone php java bridge server (running in the background).
37
EOT
38 1
        );
39 1
    }
40
41
    protected function execute(InputInterface $input, OutputInterface $output)
42
    {
43
        $file = $input->getArgument('config-file');
44
45
        // Test if config file exists
46
        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
        $params = include($file);
51
        $port = $params['port'];
52
53
        $config = new StandaloneServer\Config($params);
54
        $this->server = new StandaloneServer($config);
55
56
        $this->server->stop();
57
58
        $output->write("Server running on port $port successfully stopped" . PHP_EOL);
59
    }
60
}
61