CustomCommand::execute()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
namespace whm\Smoke\Cli\Command;
4
5
use phmLabs\Components\Annovent\Dispatcher;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Output\OutputInterface;
8
use whm\Html\Uri;
9
use whm\Smoke\Config\Configuration;
10
11
class CustomCommand extends ConfigurableCommand
12
{
13
    /**
14
     * {@inheritdoc}
15
     */
16
    protected function configure()
17
    {
18
        $this->configureCommand(
19
            'analyses a website given a config file',
20
            'The <info>custom</info> command runs a custom website analysis.',
21
            'custom'
22
        );
23
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    protected function execute(InputInterface $input, OutputInterface $output)
29
    {
30
        $this->init($input, $output);
31
32
        $this->initConfiguration(
33
            $input->getOption('config_file'),
34
            $this->eventDispatcher);
35
36
        if ($input->getOption('bootstrap')) {
37
            include $input->getOption('bootstrap');
38
        }
39
40
        return $this->scan();
41
    }
42
43
    /**
44
     * Initializes the configuration.
45
     *
46
     * @return Configuration
47
     */
48
    private function initConfiguration($configFile, Dispatcher $dispatcher)
49
    {
50
        $configArray = $this->getConfigArray($configFile, true);
51
52
        if (is_string($configArray)) {
53
            throw new \RuntimeException('Unable to load config file. Please check ' . $configFile);
54
        }
55
56
        $this->config = new Configuration(new Uri('http://www.example.com'), $dispatcher, $configArray);
57
    }
58
}
59