WarmUpCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 56
Duplicated Lines 23.21 %

Coupling/Cohesion

Components 2
Dependencies 6

Importance

Changes 0
Metric Value
wmc 3
lcom 2
cbo 6
dl 13
loc 56
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 12 1
A execute() 13 13 1
A initConfiguration() 0 11 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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