UnsetSetting   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 7

Importance

Changes 0
Metric Value
wmc 5
lcom 2
cbo 7
dl 0
loc 39
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setPath() 0 4 1
A configure() 0 6 1
A execute() 0 18 3
1
<?php
2
3
namespace Magium\Cli\Command;
4
5
use Magium\Cli\ConfigurationPathInterface;
6
use Magium\NotFoundException;
7
use Symfony\Component\Console\Command\Command;
8
use Symfony\Component\Console\Input\InputArgument;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Input\InputOption;
11
use Symfony\Component\Console\Output\OutputInterface;
12
use Zend\Config\Config;
13
use Zend\Config\Writer\Json;
14
15
class UnsetSetting extends Command implements ConfigurationPathInterface
16
{
17
18
    protected $path;
19
20
    public function setPath($path)
21
    {
22
        $this->path = $path;
23
    }
24
25
    protected function configure()
26
    {
27
        $this->setName('config:unset');
28
        $this->setDescription('Removes a setting');
29
        $this->addArgument('name', InputArgument::REQUIRED, 'Need the name of the setting');
30
    }
31
32
    protected function execute(InputInterface $input, OutputInterface $output)
33
    {
34
        if (!file_exists($this->path . '/magium.json')) {
35
            throw new NotFoundException('Configuration file not found.  Please execute magium:init.');
36
        }
37
        $reader = new \Zend\Config\Reader\Json();
38
        $config = new Config($reader->fromFile($this->path . '/magium.json'), true);
39
40
        $name = $input->getArgument('name');
41
42
        if (isset($config->config->$name)) {
43
            unset($config->config->$name);
44
        }
45
46
        $writer = new Json();
47
        $writer->toFile($this->path . '/magium.json', $config);
48
        $output->writeln(sprintf('Removed value for "%s" in %s/magium.json', $name, $this->path));
49
    }
50
51
52
53
}
54
55