Completed
Push — master ( dca6dc...178b4a )
by Richard
06:29
created

Config::project_storage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/******************************************************************************
3
 * An implementation of dicto (scg.unibe.ch/dicto) in and for PHP.
4
 * 
5
 * Copyright (c) 2016 Richard Klees <[email protected]>
6
 *
7
 * This software is licensed under The MIT License. You should have received 
8
 * a copy of the license along with the code.
9
 */
10
11
namespace Lechimp\Dicto\App;
12
13
use Symfony\Component\Config\Definition\Processor;
14
use Symfony\Component\Config\Definition\ConfigurationInterface;
15
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
16
17
/**
18
 * Configuration for the app and engine.
19
 */
20
class Config implements ConfigurationInterface {
21
    /**
22
     * @var array
23
     */
24
    protected $values;
25
26
    /**
27
     * Build the configuration from nested arrays using a processor.
28
     */
29 7
    public function __construct(array $values) {
30 7
        $processor = new \Symfony\Component\Config\Definition\Processor();
31 7
        $this->values = $processor->processConfiguration($this, $values);
32 7
    }
33
34
    /**
35
     * Definition of configuration for symfony.
36
     *
37
     * @inheritdocs
38
     */
39 7
    public function getConfigTreeBuilder() {
40 7
        $tree_builder = new TreeBuilder();
41 7
        $root = $tree_builder->root("dicto");
42
        $root
43 7
            ->children()
44 7
                ->arrayNode("project")
45 7
                    ->children()
46 7
                        ->scalarNode("root")
47 7
                            ->isRequired()
48 7
                        ->end()
49 7
                        ->scalarNode("storage")
50 7
                            ->isRequired()
51 7
                        ->end()
52 7
                    ->end()
53 7
                ->end()
54 7
                ->arrayNode("analysis")
55 7
                    ->children()
56 7
                        ->arrayNode("ignore")
57 7
                            ->prototype("scalar")
58 7
                            ->end()
59 7
                            ->defaultValue(array())
60 7
                        ->end()
61 7
                    ->end()
62 7
                    ->addDefaultsIfNotSet()
63 7
                ->end()
64 7
            ->end()
65 7
        ->end();
66
67 7
        return $tree_builder;
68
    }
69
70
    /**
71
     * @return  string
72
     */
73 5
    public function project_root() {
74 5
        return $this->values["project"]["root"];
75
    }
76
77
    /**
78
     * @return  string
79
     */
80 6
    public function project_storage() {
81 6
        return $this->values["project"]["storage"];
82
    }
83
84
    /**
85
     * @return  string[]
86
     */
87 5
    public function analysis_ignore() {
88 5
        return $this->values["analysis"]["ignore"];
89
    }
90
}
91