ScanCommand::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
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\Annovent\Dispatcher;
6
use Symfony\Component\Console\Input\InputArgument;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Input\InputOption;
9
use Symfony\Component\Console\Output\OutputInterface;
10
use whm\Html\Uri;
11
use whm\Smoke\Config\Configuration;
12
13
class ScanCommand extends SmokeCommand
14
{
15
    const CONFIG_FILE = 'analyze.yml';
16
17
    /**
18
     * {@inheritdoc}
19
     */
20
    protected function configure()
21
    {
22
        $this
23
            ->setDefinition([
24
                new InputArgument('url', InputArgument::REQUIRED, 'the url to start with'),
25
                new InputOption('num_urls', 'u', InputOption::VALUE_OPTIONAL, 'number of urls to be checked', 20),
26
                new InputOption('run_level', 'l', InputOption::VALUE_OPTIONAL, 'limit the rules that are called', 10),
27
            ])
28
            ->setDescription('analyses a website')
29
            ->setHelp('The <info>analyse</info> command runs a cache test.')
30
            ->setName('analyse');
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36 View Code Duplication
    protected function execute(InputInterface $input, OutputInterface $output)
37
    {
38
        $this->init($input, $output, $input->getArgument('url'));
39
40
        $this->initConfiguration(
41
            $input->getOption('num_urls'),
42
            $input->getOption('run_level'),
43
            new Uri($input->getArgument('url')),
0 ignored issues
show
Bug introduced by
It seems like $input->getArgument('url') targeting Symfony\Component\Consol...nterface::getArgument() can also be of type array<integer,string> or null; however, whm\Html\Uri::__construct() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
44
            $this->eventDispatcher);
45
46
        return $this->scan();
47
    }
48
49
    /**
50
     * Initializes the configuration.
51
     *
52
     * @return Configuration
53
     */
54
    private function initConfiguration($num_urls, $run_level, Uri $uri, Dispatcher $dispatcher)
55
    {
56
        $configArray = $this->getConfigArray(__DIR__ . '/../../settings/' . self::CONFIG_FILE);
57
58
        $config = new Configuration($uri, $dispatcher, $configArray);
59
60
        $crawler = $config->getExtension('_ResponseRetriever')->getRetriever();
61
        $crawler->setStartPage($uri);
62
63
        $config->getExtension('_SmokeStop')->getStrategy('_CountStop')->init($num_urls);
64
        $config->getExtension('_ProgressBar')->setMax($num_urls);
65
66
        $config->getExtension('_SmokeRunLevel')->setRunLevel($run_level);
67
68
        $this->config = $config;
69
    }
70
}
71