Completed
Push — master ( bd5921...d9293e )
by Christian
17:54 queued 08:59
created

SetCommand::execute()   B

Complexity

Conditions 4
Paths 3

Size

Total Lines 28
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 28
rs 8.5806
cc 4
eloc 17
nc 3
nop 2
1
<?php
2
3
namespace N98\Magento\Command\Config;
4
5
use Symfony\Component\Console\Input\InputArgument;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Input\InputOption;
8
use Symfony\Component\Console\Output\OutputInterface;
9
10
class SetCommand extends AbstractConfigCommand
11
{
12
    /**
13
     * @var array
14
     */
15
    protected $_scopes = array(
16
        'default',
17
        'websites',
18
        'stores',
19
    );
20
21 View Code Duplication
    protected function configure()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
22
    {
23
        $this
24
            ->setName('config:set')
25
            ->setDescription('Set a core config item')
26
            ->addArgument('path', InputArgument::REQUIRED, 'The config path')
27
            ->addArgument('value', InputArgument::REQUIRED, 'The config value')
28
            ->addOption('scope', null, InputOption::VALUE_OPTIONAL, 'The config value\'s scope (default, websites, stores)', 'default')
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 135 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
29
            ->addOption('scope-id', null, InputOption::VALUE_OPTIONAL, 'The config value\'s scope ID', '0')
30
            ->addOption('encrypt', null, InputOption::VALUE_NONE, 'The config value should be encrypted using local.xml\'s crypt key')
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 134 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
31
        ;
32
33
        $help = <<<HELP
34
Set a store config value by path.
35
To set a value of a specify store view you must set the "scope" and "scope-id" option.
36
37
HELP;
38
        $this->setHelp($help);
39
    }
40
41
    /**
42
     * @param InputInterface  $input
43
     * @param OutputInterface $output
44
     *
45
     * @return int|void
46
     */
47
    protected function execute(InputInterface $input, OutputInterface $output)
48
    {
49
        $this->detectMagento($output, true);
50
        if (!$this->initMagento()) {
51
            return;
52
        }
53
54
        $config = $this->_getConfigModel();
55
        if (!$config->getResourceModel()) {
56
            // without a resource model, a config option can't be saved.
57
            return;
58
        }
59
60
        $this->_validateScopeParam($input->getOption('scope'));
61
        $scopeId = $this->_convertScopeIdParam($input->getOption('scope'), $input->getOption('scope-id'));
62
63
        $value = str_replace(array('\n', '\r'), array("\n", "\r"), $input->getArgument('value'));
64
        $value = $this->_formatValue($value, ($input->getOption('encrypt') ? 'encrypt' : false));
0 ignored issues
show
Security Bug introduced by
It seems like $input->getOption('encrypt') ? 'encrypt' : false can also be of type false; however, N98\Magento\Command\Conf...Command::_formatValue() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
65
66
        $config->saveConfig(
67
            $input->getArgument('path'),
68
            $value,
69
            $input->getOption('scope'),
70
            $scopeId
71
        );
72
73
        $output->writeln('<comment>' . $input->getArgument('path') . "</comment> => <comment>" . $input->getArgument('value') . '</comment>');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 142 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
74
    }
75
}
76