ExplainCommand::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace whm\Smoke\Cli\Command;
4
5
use PhmLabs\Components\Init\Init;
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 ExplainCommand extends ConfigurableCommand
12
{
13
    /**
14
     * Defines what arguments and options are available for the user. Can be listed using
15
     * Smoke.phar analyse --help.
16
     */
17
    protected function configure()
18
    {
19
        $this->configureCommand('explain the rules that are configured',
20
            'The <info>explain</info> command explains all the rules that will be executed.',
21
            'explain');
22
    }
23
24
    /**
25
     * Runs the analysis of the given website with all given parameters.
26
     *
27
     * @param InputInterface  $input
28
     * @param OutputInterface $output
29
     */
30
    protected function execute(InputInterface $input, OutputInterface $output)
31
    {
32
        $this->init($input, $output);
33
34
        $config = $this->initConfiguration($input->getOption('config_file'));
35
36
        $rules = $config->getRules();
37
38
        foreach ($rules as $name => $rule) {
39
            $info = Init::getInitInformationByClass(get_class($rule));
0 ignored issues
show
Bug introduced by
The call to getInitInformationByClass() misses a required argument $initMethod.

This check looks for function calls that miss required arguments.

Loading history...
40
            $output->writeln('  ' . $name . ':');
41
            $output->writeln('    class: ' . get_class($rule));
42
            $output->writeln('    description: ' . str_replace("\n", "\n                 ", $info['documentation']));
43
44
            if (count($info['parameters']) > 0) {
45
                $output->writeln('    parameter:');
46
47
                foreach ($info['parameters'] as $parameter) {
48
                    $output->writeln('      ' . $parameter['name'] . ': ' . $parameter['description'] . ' (default: ' . $parameter['default'] . ')');
49
                }
50
            }
51
52
            $output->writeln('');
53
        }
54
    }
55
56
    /**
57
     * Initializes the configuration.
58
     *
59
     * @param $configFile
60
     *
61
     * @return Configuration
62
     */
63
    private function initConfiguration($configFile)
64
    {
65
        $configArray = $this->getConfigArray($configFile);
66
        $config = new Configuration(new Uri(''), $this->eventDispatcher, $configArray);
67
68
        return $config;
69
    }
70
}
71