Completed
Push — master ( 69fb56...37d2a4 )
by James
05:09
created

AnalyzeCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 90.48%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 5
c 3
b 0
f 0
lcom 0
cbo 5
dl 0
loc 45
ccs 19
cts 21
cp 0.9048
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 10 1
A execute() 0 20 4
1
<?php
2
3
/**
4
 * This file is, guess what, part of WebHelper.
5
 *
6
 * (c) James <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace JamesRezo\WebHelper\Command;
13
14
use Symfony\Component\Console\Input\InputInterface;
15
use Symfony\Component\Console\Output\OutputInterface;
16
use Symfony\Component\Console\Input\InputArgument;
17
use JamesRezo\WebHelper\WebServer\NullWebServer;
18
19
/**
20
 * Analyze a webserver configuration.
21
 */
22
class AnalyzeCommand extends BaseCommand
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27 5
    protected function configure()
28
    {
29 5
        $this
30 5
            ->setName('analyze')
31 5
            ->setDescription('Analyze a webserver configuration')
32 5
            ->setHelp('The <info>analyze</info> command parses the configuration of a webserver.')
33 5
            ->addArgument('webserver', InputArgument::REQUIRED, 'a webserver name.')
34 5
            ->addArgument('configfile', InputArgument::REQUIRED, 'a configuration file.')
35
        ;
36 5
    }
37
38
    /**
39
     * Execute the command.
40
     *
41
     * {@inheritdoc}
42
     *
43
     * @param InputInterface  $input  the input interface
44
     * @param OutputInterface $output the output interface
45
     */
46 4
    protected function execute(InputInterface $input, OutputInterface $output)
47
    {
48 4
        $webserver = $this->getWebServer($input, $output);
49 4
        if ($webserver instanceof NullWebServer) {
50 1
            return 1;
51
        }
52
53 3
        $configfile = $input->getArgument('configfile');
54 3
        if (!is_readable($configfile)) {
55 1
            $output->writeln('<error>Configuration file "'.$configfile.'" does not exist.</error>');
56
57 1
            return 1;
58
        }
59
60
        //For now, just outputs a cleaned list of directives
61 2
        $activeConfig = $webserver->getActiveConfig($configfile);
62 2
        if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) {
63
            $output->write(implode(PHP_EOL, $activeConfig));
64
        }
65 2
    }
66
}
67