Completed
Push — master ( 8da12a...178c32 )
by Sébastien
14:05 queued 11:13
created

PjbServerRevealCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 91.3%

Importance

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