DownloadSeleniumCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 6
dl 56
loc 56
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A configure() 20 20 1
A execute() 7 7 1
A setDownloaderOptionsFromInput() 6 6 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 BeubiQA\Application\Command;
4
5
use BeubiQA\Application\Selenium\SeleniumHandler;
6
use Symfony\Component\Console\Command\Command;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Input\InputOption;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11 View Code Duplication
class DownloadSeleniumCommand extends Command
12
{
13
    /** @var SeleniumHandler  */
14
    protected $seleniumHandler;
15
16
    /**
17
     * @param SeleniumHandler $seleniumHandler
18
     */
19
    public function __construct(SeleniumHandler $seleniumHandler)
20
    {
21
        $this->seleniumHandler = $seleniumHandler;
22
        parent::__construct('start');
23
    }
24
25
    protected function configure()
26
    {
27
        $this
28
        ->setName('get')
29
        ->addOption(
30
            'selenium-version',
31
            's',
32
            InputOption::VALUE_REQUIRED,
33
            'Set a custom selenium version',
34
            '2.53.0'
35
        )
36
        ->addOption(
37
            'selenium-destination',
38
            'd',
39
            InputOption::VALUE_REQUIRED,
40
            'Set a custom selenium destination directory',
41
            '.'
42
        )
43
        ->setDescription('Downloads selenium server');
44
    }
45
46
    /**
47
     * @param InputInterface  $input
48
     * @param OutputInterface $output
49
     *
50
     * @throws \RuntimeException
51
     */
52
    protected function execute(InputInterface $input, OutputInterface $output)
53
    {
54
        $this->setDownloaderOptionsFromInput($input);
55
        $this->seleniumHandler->download();
56
        $output->writeln(PHP_EOL, true);
57
        $output->writeln('Done');
58
    }
59
60
    private function setDownloaderOptionsFromInput(InputInterface $input)
61
    {
62
        $downloaderOptions = $this->seleniumHandler->getDownloader()->getDownloaderOptions();
63
        $downloaderOptions->setSeleniumDestination($input->getOption('selenium-destination'));
64
        $downloaderOptions->setSeleniumVersion($input->getOption('selenium-version'));
65
    }
66
}
67