Completed
Push — develop ( d9f94b...0703cb )
by Samuel
08:04
created

Configuration::getConfigTreeBuilder()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 1

Importance

Changes 2
Bugs 1 Features 1
Metric Value
c 2
b 1
f 1
dl 0
loc 24
ccs 19
cts 19
cp 1
rs 8.9714
cc 1
eloc 20
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * Configuration definition to be able to define every swagger source via /app/config/config.yml
4
 */
5
6
namespace Graviton\ProxyBundle\DependencyInjection;
7
8
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
9
use Symfony\Component\Config\Definition\ConfigurationInterface;
10
11
/**
12
 * Class Configuration
13
 *
14
 * To learn more see {@link http://scm.to/00Yb}
15
 *
16
 * @author  List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
17
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
18
 * @link    http://swisscom.ch
19
 */
20
class Configuration implements ConfigurationInterface
21
{
22
    /**
23
     * Defines the structure of the configuration information.
24
     *
25
     * Example structure to be used in /app/config/config.yml:
26
     *
27
     *   graviton_proxy:
28
     *     sources:
29
     *       swagger:
30
     *         petstore:
31
     *           prefix: petstore
32
     *           uri:    http://petstore.swagger.io/v2/swagger.json
33
     *         another_source:
34
     *           prefix: myswaggerinstance
35
     *           uri:    http://swagger.example.org/swagger.json
36
     *
37
     * @return TreeBuilder
38
     */
39 1
    public function getConfigTreeBuilder()
40
    {
41 1
        $treeBuilder = new TreeBuilder();
42 1
        $rootNode = $treeBuilder->root('graviton_proxy');
43
44
        $rootNode
45 1
            ->children()
46 1
                ->arrayNode('sources')
47 1
                    ->useAttributeAsKey('name')
48 1
                    ->prototype('array')
49 1
                        ->useAttributeAsKey('name')
50 1
                        ->prototype('array')
51 1
                        ->children()
52 1
                            ->scalarNode('prefix')->isRequired()->cannotBeEmpty()->end()
53 1
                            ->scalarNode('uri')->isRequired()->cannotBeEmpty()->end()
54 1
                            ->scalarNode('host')->cannotBeEmpty()->end()
55 1
                            ->end()
56 1
                        ->end()
57 1
                    ->end()
58 1
                ->end() // swagger_proxy
59 1
            ->end();
60
61 1
        return $treeBuilder;
62
    }
63
}
64