Completed
Push — master ( 651fd6...ce8064 )
by Sébastien
04:02
created

PjbServerRevealCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 91.3%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 17 1
A execute() 0 22 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 PjbServerRevealCommand extends Command
14
{
15
    use LoggerTrait;
16
17
    /**
18
     * @var StandaloneServer
19
     */
20
    protected $server;
21
22
23
    /**
24
     * {@inheritdoc}
25
     */
26 7
    protected function configure()
27
    {
28 7
        $this->setName('pjbserver:reveal')
29 7
             ->setDescription(
30
                 'Print the underlying java cli command'
31 7
               )
32 7
            ->addArgument(
33 7
                'config-file',
34 7
                InputArgument::REQUIRED,
35
                'Configuration file, see ./dist/pjbserver.config.php.dist'
36 7
            )
37
38 7
             ->setHelp(<<<EOT
39
Echo the underlying cli command (call to java) that will be called.
40
EOT
41 7
        );
42 7
    }
43
44 1
    protected function execute(InputInterface $input, OutputInterface $output)
45
    {
46 1
        $logger = $this->getConsoleLogger($output);
47
48 1
        $file = $input->getArgument('config-file');
49
50
        // Test if config file exists
51 1
        if (!file_exists($file) || !is_readable($file)) {
52
            $msg = "Configuration file '$file' does not exists or is not readable'";
53
            throw new \InvalidArgumentException($msg);
54
        }
55
56 1
        $params = include($file);
57
58 1
        $config = new StandaloneServer\Config($params);
59 1
        $this->logServerConfig($logger, $config);
60 1
        $this->server = new StandaloneServer($config, $logger);
61
62 1
        $output->writeln($this->server->getCommand());
63
64 1
        return 1;
65
    }
66
}
67