Passed
Pull Request — develop (#24)
by Kevin
02:49
created

ConfigurationSet   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 24 %

Coupling/Cohesion

Components 2
Dependencies 7

Test Coverage

Coverage 96.15%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 2
cbo 7
dl 12
loc 50
ccs 25
cts 26
cp 0.9615
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 12 12 1
A setConfigurationFactory() 0 4 1
A getConfigurationFactory() 0 7 2
A execute() 0 14 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Magium\Configuration\Console\Command;
4
5
use Magium\Configuration\Config\Config;
6
use Magium\Configuration\Config\ConfigInterface;
7
use Magium\Configuration\MagiumConfigurationFactory;
8
use Magium\Configuration\MagiumConfigurationFactoryInterface;
9
use Symfony\Component\Console\Command\Command;
10
use Symfony\Component\Console\Input\InputArgument;
11
use Symfony\Component\Console\Input\InputInterface;
12
use Symfony\Component\Console\Input\InputOption;
13
use Symfony\Component\Console\Output\OutputInterface;
14
15
class ConfigurationSet extends Command
16
{
17
18
    const COMMAND = 'magium:configuration:set';
19
20
    protected $factory;
21
22 2 View Code Duplication
    protected function configure()
23
    {
24
        $this
25 2
            ->setName(self::COMMAND)
26 2
            ->setDescription('Set a configuration value')
27 2
            ->setHelp("This command sets a value for a specific configuration path")
28
        ;
29
30 2
        $this->addArgument('path', InputArgument::REQUIRED, 'Configuration Path');
31 2
        $this->addArgument('value', InputArgument::REQUIRED, 'Value');
32 2
        $this->addArgument('context', InputArgument::OPTIONAL, 'Configuration Context', Config::CONTEXT_DEFAULT);
33 2
    }
34
35 1
    public function setConfigurationFactory(MagiumConfigurationFactoryInterface $factory)
36
    {
37 1
        $this->factory = $factory;
38 1
    }
39
40 1
    protected function getConfigurationFactory()
41
    {
42 1
        if (!$this->factory instanceof MagiumConfigurationFactoryInterface) {
43
            $this->factory = new MagiumConfigurationFactory();
44
        }
45 1
        return $this->factory;
46
    }
47
48 1
    protected function execute(InputInterface $input, OutputInterface $output)
49
    {
50 1
        $factory = $this->getConfigurationFactory();
51 1
        $builderFactory = $factory->getBuilderFactory();
52 1
        $path = $input->getArgument('path');
53 1
        $value = $input->getArgument('value');
54 1
        $context = $input->getArgument('context');
55 1
        $builderFactory->getPersistence()->setValue($path, $value, $context);
56
57 1
        $out = sprintf("Set %s to %s (context: %s)", $path, $value, $context);
58
59 1
        $output->writeln($out);
60 1
        $output->writeln("Don't forget to rebuild your configuration cache with " . ConfigurationBuild::COMMAND);
61 1
    }
62
63
64
}
65