WarmUpCommand::initConfiguration()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 2
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 WarmUpCommand extends SmokeCommand
14
{
15
    /**
16
     * {@inheritdoc}
17
     */
18
    protected function configure()
19
    {
20
        $this
21
            ->setDefinition([
22
                new InputArgument('url', InputArgument::REQUIRED, 'the url to start with'),
23
                new InputOption('duration', 'd', InputOption::VALUE_OPTIONAL, 'duration in seconds', 60),
24
                new InputOption('parallel_requests', 'p', InputOption::VALUE_OPTIONAL, 'number of parallel requests.', 10),
25
            ])
26
            ->setDescription('analyses a website')
27
            ->setHelp('The <info>warmup</info> command warms a website up.')
28
            ->setName('warmup');
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34 View Code Duplication
    protected function execute(InputInterface $input, OutputInterface $output)
35
    {
36
        $this->init($input, $output, $input->getArgument('url'));
37
38
        $this->initConfiguration(
39
            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...
40
            $this->eventDispatcher);
41
42
        $timeStrategy = $this->config->getExtension('_SmokeStop')->getStrategy('_TimeStop');
43
        $timeStrategy->init($input->getOption('duration'));
44
45
        return $this->scan();
46
    }
47
48
    /**
49
     * Initializes the configuration.
50
     *
51
     * @param $configFile
52
     * @param $loadForeign
53
     * @param Uri $uri
54
     *
55
     * @return Configuration
56
     */
57
    private function initConfiguration(Uri $uri, Dispatcher $dispatcher)
58
    {
59
        $configArray = $this->getConfigArray(__DIR__ . '/../../settings/warmup.yml');
60
61
        $config = new Configuration($uri, $dispatcher, $configArray);
62
63
        $crawler = $config->getExtension('_ResponseRetriever')->getRetriever();
64
        $crawler->setStartPage($uri);
65
66
        $this->config = $config;
67
    }
68
}
69