ShowModeCommand::getCommand()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
dl 10
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 2
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\InputArgument;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
10
/**
11
 * Class ShowModeCommand
12
 * @package Magestead\Command\Index
13
 */
14 View Code Duplication
class ShowModeCommand 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...
15
{
16
    protected $_config;
17
    protected $_projectPath;
18
19
    protected function configure()
20
    {
21
        $this->_projectPath = getcwd();
22
        $this->setName("index:mode:show");
23
        $this->setDescription("Show index mode");
24
        $this->addArgument('index', InputArgument::OPTIONAL, '[indexer]');
25
    }
26
27
    /**
28
     * @param InputInterface $input
29
     * @param OutputInterface $output
30
     * @return ProcessCommand|null
31
     */
32
    protected function execute(InputInterface $input, OutputInterface $output)
33
    {
34
        $index = $input->getArgument('index');
35
36
        $command = $this->getCommand(new Config($output), $index);
37
        if ($command) {
38
            $output->writeln('<info>Getting index mode</info>');
39
            $passedCommand = "vagrant ssh -c '". $command ."'";
40
            return new ProcessCommand($passedCommand, $this->_projectPath, $output);
41
        }
42
43
        $output->writeln('<error>Command not available for this application</error>');
44
    }
45
46
    /**
47
     * @param Config $config
48
     * @param $index
49
     * @return bool|string
50
     */
51
    protected function getCommand(Config $config, $index)
52
    {
53
        $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...
54
        switch ($type) {
55
            case 'magento2':
56
                return "cd /var/www/public;bin/magento indexer:show-mode $index";
57
        }
58
59
        return false;
60
    }
61
}