StopSeleniumCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 57
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 4
lcom 1
cbo 7
dl 57
loc 57
rs 10
c 5
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 setStopperOptionsFromInput() 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 StopSeleniumCommand 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('stop')
29
        ->addOption(
30
            'timeout',
31
            't',
32
            InputOption::VALUE_REQUIRED,
33
            'Set how much you are willing to wait until selenium server is stopped (in seconds)',
34
            30
35
        )
36
        ->addOption(
37
            'port',
38
            'p',
39
            InputOption::VALUE_REQUIRED,
40
            'Set how much you are willing to wait until selenium server is stopped (in seconds)',
41
            4444
42
        )
43
        ->setDescription('Stops selenium server');
44
    }
45
46
    /**
47
     * @param InputInterface  $input
48
     * @param OutputInterface $output
49
     */
50
    protected function execute(InputInterface $input, OutputInterface $output)
51
    {
52
        $this->setStopperOptionsFromInput($input);
53
        $this->seleniumHandler->stop();
54
        $output->writeln(PHP_EOL, true);
55
        $output->writeln("\nDone");
56
    }
57
58
    /**
59
     * @param InputInterface $input
60
     */
61
    private function setStopperOptionsFromInput(InputInterface $input)
62
    {
63
        $stopper = $this->seleniumHandler->getStopper();
64
        $stopper->getStopOptions()->setSeleniumPort($input->getOption('port'));
65
        $stopper->getResponseWaitter()->setTimeout($input->getOption('timeout'));
66
    }
67
}
68