BehatCommand   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 80.39 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 8 8 1
A execute() 12 12 2
A getCommand() 5 14 3

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 namespace Magestead\Command;
2
3
use Magestead\Helper\Config;
4
use Symfony\Component\Console\Input\InputArgument;
5
use Symfony\Component\Console\Command\Command;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Output\OutputInterface;
8
9
/**
10
 * Class BehatCommand
11
 * @package Magestead\Command
12
 */
13 View Code Duplication
class BehatCommand extends Command
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in 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...
14
{
15
    protected $_projectPath;
16
17
    protected function configure()
18
    {
19
        $this->_projectPath = getcwd();
20
21
        $this->setName("behat");
22
        $this->setDescription("Run Behat against your project");
23
        $this->addArgument('option', InputArgument::OPTIONAL, 'Add options to run');
24
    }
25
26
    /**
27
     * @param InputInterface $input
28
     * @param OutputInterface $output
29
     * @return mixed
30
     */
31
    protected function execute(InputInterface $input, OutputInterface $output)
32
    {
33
        $option  = $input->getArgument('option');
34
        $command = $this->getCommand(new Config($output), $option);
35
        if (!$command) {
36
            return $output->writeln('<error>Command not available for this application</error>');
37
        }
38
39
        $output->writeln('<info>Running Behat</info>');
40
        $passedCommand = "vagrant ssh -c '". $command ."'";
41
        passthru($passedCommand);
42
    }
43
44
    /**
45
     * @param Config $config
46
     * @param $option
47
     * @return bool|string
48
     */
49
    protected function getCommand(Config $config, $option)
50
    {
51
        $type = $config->type;
0 ignored issues
show
Bug introduced by
The property type does not seem to exist in Magestead\Helper\Config.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
52
        switch ($type) {
53
            case 'magento':
54
                return "cd /var/www;bin/behat $option";
55
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
56
            case 'magento2':
57
                return "cd /var/www/public;bin/behat $option";
58
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
59
        }
60
61
        return false;
62
    }
63
}
64