Completed
Push — develop ( 6f71dd...40edc3 )
by Tom
11s
created

SetCommand::configure()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 30
Code Lines 22

Duplication

Lines 19
Ratio 63.33 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 19
loc 30
rs 8.8571
cc 1
eloc 22
nc 1
nop 0
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(
29
                'scope',
30
                null,
31
                InputOption::VALUE_OPTIONAL,
32
                'The config value\'s scope (default, websites, stores)',
33
                'default'
34
            )
35
            ->addOption('scope-id', null, InputOption::VALUE_OPTIONAL, 'The config value\'s scope ID', '0')
36
            ->addOption(
37
                'encrypt',
38
                null,
39
                InputOption::VALUE_NONE,
40
                'The config value should be encrypted using local.xml\'s crypt key'
41
            )
42
        ;
43
44
        $help = <<<HELP
45
Set a store config value by path.
46
To set a value of a specify store view you must set the "scope" and "scope-id" option.
47
48
HELP;
49
        $this->setHelp($help);
50
    }
51
52
    /**
53
     * @param InputInterface  $input
54
     * @param OutputInterface $output
55
     *
56
     * @return int|void
57
     */
58
    protected function execute(InputInterface $input, OutputInterface $output)
59
    {
60
        $this->detectMagento($output, true);
61
        if (!$this->initMagento()) {
62
            return;
63
        }
64
65
        $config = $this->_getConfigModel();
66
        if (!$config->getResourceModel()) {
67
            // without a resource model, a config option can't be saved.
68
            return;
69
        }
70
71
        $this->_validateScopeParam($input->getOption('scope'));
72
        $scopeId = $this->_convertScopeIdParam($input->getOption('scope'), $input->getOption('scope-id'));
73
74
        $value = str_replace(array('\n', '\r'), array("\n", "\r"), $input->getArgument('value'));
75
        $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...
76
77
        $config->saveConfig(
78
            $input->getArgument('path'),
79
            $value,
80
            $input->getOption('scope'),
81
            $scopeId
82
        );
83
84
        $output->writeln(
85
            '<comment>' . $input->getArgument('path') . "</comment> => <comment>" . $input->getArgument('value') .
86
            '</comment>'
87
        );
88
    }
89
}
90