Completed
Push — feature/add-cli-installers ( a5e20d...179a1d )
by Steven
13:45
created

InfoCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
c 1
b 0
f 1
lcom 1
cbo 4
dl 46
loc 46
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 6 6 1
A execute() 8 8 1
A getCommand() 15 15 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\Index;
2
3
use Magestead\Command\ProcessCommand;
4
use Magestead\Helper\Config;
5
use Symfony\Component\Console\Command\Command;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Output\OutputInterface;
8
9 View Code Duplication
class InfoCommand 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...
10
{
11
    protected $_config;
12
    protected $_projectPath;
13
14
    protected function configure()
15
    {
16
        $this->_projectPath = getcwd();
17
        $this->setName("index:info");
18
        $this->setDescription("Show available indexes");
19
    }
20
21
    /**
22
     * @param InputInterface $input
23
     * @param OutputInterface $output
24
     * @return ProcessCommand
25
     */
26
    protected function execute(InputInterface $input, OutputInterface $output)
27
    {
28
        $output->writeln('<info>Getting index information</info>');
29
30
        $command = $this->getCommand(new Config($output));
31
        $passedCommand = "vagrant ssh -c '". $command ."'";
32
        return new ProcessCommand($passedCommand, $this->_projectPath, $output);
33
    }
34
35
    /**
36
     * @param Config $config
37
     * @return bool|string
38
     */
39
    protected function getCommand(Config $config)
40
    {
41
        $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...
42
        switch ($type) {
43
            case 'magento':
44
                // todo add magerun commands
45
                return "";
46
                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...
47
            case 'magento2':
48
                return "cd /var/www/public;bin/magento indexer:info";
49
                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...
50
        }
51
52
        return false;
53
    }
54
}