Completed
Push — develop ( c6a956...40134e )
by Steven
9s
created

ReindexCommand::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

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