Passed
Pull Request — develop (#31)
by Kevin
02:34
created

ConfigurationBuild   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
lcom 1
cbo 8
dl 0
loc 43
ccs 22
cts 22
cp 1
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 12 1
A execute() 0 20 4
1
<?php
2
3
namespace Magium\Configuration\Console\Command;
4
5
use Magium\Configuration\Config\InvalidContextException;
6
use Magium\Configuration\MagiumConfigurationFactory;
7
use Magium\Configuration\MagiumConfigurationFactoryInterface;
8
use Symfony\Component\Console\Command\Command;
9
use Symfony\Component\Console\Input\InputArgument;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Output\OutputInterface;
12
13
class ConfigurationBuild extends Command
14
{
15
    use ConfigurationFactoryTrait;
16
17
    const COMMAND = 'magium:configuration:build';
18
19
    protected $configurationFactory;
20
21 6
    protected function configure()
22
    {
23
        $this
24 6
            ->setName(self::COMMAND)
25 6
            ->setDescription('Build configuration')
26 6
            ->setHelp(
27
                'This command will build the configuration object based off of configuration files and '
28
                . 'persistent storage data.  By default, it will rebuild all contexts, but you can specify an '
29 6
                . 'individual context if you so like.');
30
31 6
        $this->addArgument('context', InputArgument::OPTIONAL, 'Configuration Context (ignore to build all contexts)');
32 6
    }
33
34 4
    protected function execute(InputInterface $input, OutputInterface $output)
35
    {
36 4
        $factory = $this->getConfigurationFactory();
37 4
        $builder = $factory->getBuilder();
38 4
        $manager = $factory->getManager();
39 4
        $contexts = $factory->getContextFile()->getContexts();
40 4
        $context = $input->getArgument('context');
41 4
        if ($context) {
42 2
            if (in_array($context, $contexts)) {
43 1
                $contexts = [$context];
44
            } else {
45 1
                throw new InvalidContextException('Context does not exist: ' . $context);
46
            }
47
        }
48 3
        foreach ($contexts as $context) {
49 3
            $output->writeln('Building context: ' . $context);
50 3
            $config = $builder->build($context);
51 3
            $manager->storeConfigurationObject($config, $context);
52
        }
53 3
    }
54
55
}
56