Configuration::getConfigTreeBuilder()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 48
Code Lines 43

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 48
ccs 0
cts 44
cp 0
rs 9.125
c 0
b 0
f 0
cc 1
eloc 43
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Nicofuma\SwaggerBundle\DependencyInjection;
4
5
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
6
use Symfony\Component\Config\Definition\ConfigurationInterface;
7
8
/**
9
 * This class contains the configuration information for the bundle.
10
 *
11
 * This information is solely responsible for how the different configuration
12
 * sections are normalized, and merged.
13
 */
14
class Configuration implements ConfigurationInterface
15
{
16
    /**
17
     * {@inheritdoc}
18
     */
19
    public function getConfigTreeBuilder()
20
    {
21
        $treeBuilder = new TreeBuilder();
22
        $rootNode = $treeBuilder->root('nicofuma_swagger', 'array');
23
24
        $rootNode
25
            ->fixXmlConfig('definition')
26
            ->children()
27
                ->arrayNode('definitions')
28
                    ->prototype('array')
29
                        ->children()
30
                            ->arrayNode('pattern')
31
                                ->beforeNormalization()->ifString()->then(function ($v) {
32
                                    return ['path' => $v];
33
                                })->end()
34
                                ->fixXmlConfig('ip')
35
                                ->fixXmlConfig('method')
36
                                ->children()
37
                                    ->scalarNode('path')
38
                                        ->defaultNull()
39
                                        ->info('use the urldecoded format')
40
                                     ->example('^/path to resource/')
41
                                    ->end()
42
                                    ->scalarNode('host')->defaultNull()->end()
43
                                    ->arrayNode('ips')
44
                                        ->beforeNormalization()->ifString()->then(function ($v) {
45
                                            return [$v];
46
                                        })->end()
47
                                        ->prototype('scalar')->end()
48
                                    ->end()
49
                                    ->arrayNode('methods')
50
                                        ->beforeNormalization()->ifString()->then(function ($v) {
51
                                            return preg_split('/\s*,\s*/', $v);
52
                                        })->end()
53
                                        ->prototype('scalar')->end()
54
                                    ->end()
55
                                ->end()
56
                            ->end()
57
                            ->scalarNode('swagger_file')->end()
58
                            ->booleanNode('strict')->defaultTrue()->end()
59
                        ->end()
60
                    ->end()
61
                ->end()
62
            ->end()
63
        ;
64
65
        return $treeBuilder;
66
    }
67
}
68