Completed
Push — master ( 9f496f...3325cc )
by Дмитрий
06:00
created

Configuration::setValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
ccs 0
cts 3
cp 0
crap 2
rs 10
1
<?php
2
/**
3
 * @author Patsura Dmitry https://github.com/ovr <[email protected]>
4
 */
5
6
namespace PHPSA;
7
8
use PhpParser\ParserFactory;
9
use Symfony\Component\Config\Definition\Builder\NodeBuilder;
10
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
11
use Symfony\Component\Config\Definition\ConfigurationInterface;
12
use Symfony\Component\Config\Definition\Processor;
13
14
class Configuration implements ConfigurationInterface
15
{
16
    /**
17
     * @var array
18
     */
19
    protected $configuration;
20
21 387
    public function __construct(array $configuration = [])
22
    {
23 387
        $processor = new Processor();
24 387
        $treeBuilder = $this->getConfigTreeBuilder();
25
26 387
        $this->configuration = $processor->process(
27 387
            $treeBuilder->buildTree(),
28
            $configuration
29 387
        );
30 387
    }
31
32
    /**
33
     * Generates the configuration tree builder.
34
     *
35
     * @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder
36
     */
37 387
    public function getConfigTreeBuilder()
38
    {
39 387
        $treeBuilder = new TreeBuilder();
40
41 387
        $treeBuilder->root('common', 'array', new NodeBuilder())
42 387
            ->children()
43 387
                ->booleanNode('blame')
44 387
                ->defaultFalse()
45 387
                ->end()
46 387
            ->end()
47 387
            ->children()
48 387
                ->enumNode('parser')
49 387
                    ->defaultValue('prefer-7')
50 387
                    ->attribute('label', 'Check types of Arguments.')
51 387
                    ->values([
52 387
                        ParserFactory::PREFER_PHP7 => 'prefer-7',
53 387
                        ParserFactory::PREFER_PHP5 => 'prefer-5',
54 387
                        ParserFactory::ONLY_PHP7 => 'only-7',
55 387
                        ParserFactory::ONLY_PHP5 => 'only-5'
56 387
                    ]);
57
58
59 387
        return $treeBuilder;
60
    }
61
62
    public function setValue($key, $value)
63
    {
64
        $this->configuration[$key] = $value;
65
    }
66
67
    /**
68
     * @param string $key
69
     * @return bool
70
     */
71 14
    public function valueIsTrue($key)
72
    {
73 14
        return (bool) $this->configuration[$key];
74
    }
75
}
76