ScanCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 58
Duplicated Lines 20.69 %

Coupling/Cohesion

Components 2
Dependencies 6

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 12 1
A execute() 12 12 1
A initConfiguration() 0 16 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 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