Code Duplication    Length = 49-49 lines in 2 locations

src/Magestead/Command/Index/SetModeCommand.php 1 location

@@ 10-58 (lines=49) @@
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
10
class SetModeCommand extends Command
11
{
12
    protected $_config;
13
    protected $_projectPath;
14
15
    protected function configure()
16
    {
17
        $this->_projectPath = getcwd();
18
        $this->setName("index:mode:set");
19
        $this->setDescription("Set index mode type");
20
        $this->addArgument('mode', InputArgument::REQUIRED, '{realtime|schedule} [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>Setting index mode</info>');
31
        $mode = $input->getArgument('mode');
32
33
        $command = $this->getCommand(new Config($output), $mode);
34
        if ($command) {
35
            $passedCommand = "vagrant ssh -c '". $command ."'";
36
            return new ProcessCommand($passedCommand, $this->_projectPath, $output);
37
        }
38
39
        $output->writeln('<error>Command not available for this application</error>');
40
    }
41
42
    /**
43
     * @param Config $config
44
     * @param $mode
45
     * @return bool|string
46
     */
47
    protected function getCommand(Config $config, $mode)
48
    {
49
        $type = $config->type;
50
        switch ($type) {
51
            case 'magento2':
52
                return "cd /var/www/public;bin/magento indexer:set-mode $mode";
53
                break;
54
        }
55
56
        return false;
57
    }
58
}

src/Magestead/Command/Index/ShowModeCommand.php 1 location

@@ 10-58 (lines=49) @@
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
10
class ShowModeCommand extends Command
11
{
12
    protected $_config;
13
    protected $_projectPath;
14
15
    protected function configure()
16
    {
17
        $this->_projectPath = getcwd();
18
        $this->setName("index:mode:show");
19
        $this->setDescription("Show index mode");
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>Getting index mode</info>');
31
        $index = $input->getArgument('index');
32
33
        $command = $this->getCommand(new Config($output), $index);
34
        if ($command) {
35
            $passedCommand = "vagrant ssh -c '". $command ."'";
36
            return new ProcessCommand($passedCommand, $this->_projectPath, $output);
37
        }
38
39
        $output->writeln('<error>Command not available for this application</error>');
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;
50
        switch ($type) {
51
            case 'magento2':
52
                return "cd /var/www/public;bin/magento indexer:show-mode $index";
53
                break;
54
        }
55
56
        return false;
57
    }
58
}