WebDriver   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 36.36 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 17 1
B execute() 20 32 5

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 Magium\Cli\Command;
4
5
use Magium\InvalidInstructionException;
6
use Symfony\Component\Console\Command\Command;
7
use Symfony\Component\Console\Input\ArrayInput;
8
use Symfony\Component\Console\Input\InputArgument;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
class WebDriver extends Command
13
{
14
15
    protected function configure()
16
    {
17
        $this->setName('magium:webdriver');
18
        $this->setDescription('Configures the WebDriver settings');
19
        $this->addOption(
20
            'url',
21
            null,
22
            InputArgument::OPTIONAL,
23
            'The URL to connect to'
24
        );
25
        $this->addOption(
26
            'capability',
27
            null,
28
            InputArgument::OPTIONAL,
29
            'The browser capability (chrome, firefox, phantomjs, etc.)'
30
        );
31
    }
32
33
    protected function execute(InputInterface $input, OutputInterface $output)
34
    {
35
        $command = $this->getApplication()->find('element:set');
36
37
        if (!$input->getOption('url') && !$input->getOption('capability')) {
38
            throw new InvalidInstructionException('url and/or capability required.  Neither found.');
39
        }
40
41
        $url = $input->getOption('url');
42 View Code Duplication
        if ($url) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
43
            $arguments = [
44
                'command' => $command->getName(),
45
                'class'    => 'Magium\\TestCaseConfiguration',
46
                'property'  => 'webDriverRemote',
47
                'value'     => $url
48
            ];
49
            $webDriverInput = new ArrayInput($arguments);
50
            $command->run($webDriverInput, $output);
51
        }
52
53
        $capability = $input->getOption('capability');
54 View Code Duplication
        if ($capability) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
55
            $arguments = [
56
                'command' => $command->getName(),
57
                'class'    => 'Magium\\TestCaseConfiguration',
58
                'property'  => 'capabilities',
59
                'value'     => $capability
60
            ];
61
            $webDriverInput = new ArrayInput($arguments);
62
            $command->run($webDriverInput, $output);
63
        }
64
    }
65
66
}