Configure::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
namespace LimeSoda\Environment;
4
5
use N98\Magento\Command\AbstractMagentoCommand;
6
use Symfony\Component\Console\Input\InputArgument;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Input\InputOption;
9
use Symfony\Component\Console\Input\StringInput;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
class Configure extends AbstractMagentoCommand
13
{
14
    protected function configure()
0 ignored issues
show
Coding Style Best Practice introduced by
Please use __construct() instead of a PHP4-style constructor that is named after the class.
Loading history...
15
    {
16
      $this
17
          ->setName('ls:env:configure')
18
          ->addArgument('environment', InputArgument::REQUIRED, 'Identifier of the environment')
19
          ->addOption('override', null, InputOption::VALUE_REQUIRED  | InputOption::VALUE_IS_ARRAY, 'pair of variable name and value overriding the values in the configuration, e.g. --variable="arg1=value1"')
20
          ->setDescription('Update settings and data for environment');
21
    }
22
23
   /**
24
    * @param \Symfony\Component\Console\Input\InputInterface $input
25
    * @param \Symfony\Component\Console\Output\OutputInterface $output
26
    * @return int|void
27
    */
28
    protected function execute(InputInterface $input, OutputInterface $output)
29
    {
30
        $this->detectMagento($output, true);
31
        if ($this->initMagento()) {
32
          
33
            $environment = $input->getArgument('environment');
34
            $helper = \Mage::helper('limesoda_environmentconfiguration');
35
36
            // Deactivating auto-exiting after command execution
37
            $this->getApplication()->setAutoExit(false);
38
39
            foreach ($helper->getParsedCommands($environment, $this->getVariableOverrides($input)) as $command) {
40
                $input = new StringInput($command);
41
                $this->getApplication()->run($input, $output);
42
            }
43
44
            // Reactivating auto-exiting after command execution
45
            $this->getApplication()->setAutoExit(true);
46
        }
47
    }
48
49
    /**
50
     * @param \Symfony\Component\Console\Input\InputInterface $input
51
     * @return array
52
     */
53
    protected function getVariableOverrides(InputInterface $input)
54
    {
55
        $result = array();
56
57
        foreach ($input->getOption('override') as $keyValueString) {
58
            $keyValuePair = explode('=', $keyValueString);
59
            if (count($keyValuePair) === 2) {
60
                $result[$keyValuePair[0]] = $keyValuePair[1];
61
            }
62
        }
63
64
        return $result;
65
    }
66
}
67