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

ReindexCommand::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 9
rs 9.6666
cc 1
eloc 6
nc 1
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
class ReindexCommand extends Command
11
{
12
    protected $_config;
13
    protected $_projectPath;
14
15
    protected function configure()
16
    {
17
        $this->_projectPath = getcwd();
18
        $this->setName("index:reindex");
19
        $this->setDescription("Reindex data");
20
        $this->addArgument('index', InputArgument::OPTIONAL, '[indexer]');
21
    }
22
23
    /**
24
     * @param InputInterface $input
25
     * @param OutputInterface $output
26
     * @return ProcessCommand
27
     */
28
    protected function execute(InputInterface $input, OutputInterface $output)
29
    {
30
        $output->writeln('<info>Reindexing data</info>');
31
        $index = $input->getArgument('index');
32
33
        $command = $this->getCommand(new Config($output), $index);
34
        $passedCommand = "vagrant ssh -c '". $command ."'";
35
        return new ProcessCommand($passedCommand, $this->_projectPath, $output);
36
    }
37
38
    /**
39
     * @param Config $config
40
     * @param $index
41
     * @return bool|string
42
     */
43
    protected function getCommand(Config $config, $index)
44
    {
45
        $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...
46
        switch ($type) {
47
            case 'magento':
48
                // todo add magerun commands
49
                return "";
50
                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...
51
            case 'magento2':
52
                return "cd /var/www/public;bin/magento indexer:reindex $index";
53
                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...
54
        }
55
56
        return false;
57
    }
58
}