ReindexCommand   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 5
dl 0
loc 47
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 7 1
A execute() 0 9 1
A getCommand() 0 13 4
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
            case 'magento2':
55
                return "cd /var/www/public;bin/magento indexer:reindex $index";
56
        }
57
58
        return false;
59
    }
60
}