Configuration::getConfigTreeBuilder()   B
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 24
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 24
ccs 17
cts 17
cp 1
rs 8.9713
cc 2
eloc 17
nc 1
nop 0
crap 2
1
<?php
2
3
namespace GBProd\ElasticaSpecificationBundle\DependencyInjection;
4
5
use Elastica\QueryBuilder\Version;
6
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
7
use Symfony\Component\Config\Definition\ConfigurationInterface;
8
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
9
10
/**
11
 * Configuration
12
 *
13
 * @author gbprod <[email protected]>
14
 */
15
class Configuration implements ConfigurationInterface
16
{
17
    /**
18
     * {@inheritdoc}
19
     */
20 9
    public function getConfigTreeBuilder()
21
    {
22 9
        $treeBuilder = new TreeBuilder();
23 9
        $root = $treeBuilder->root('elastica_specification_bundle');
24
25
        $root
26 9
            ->children()
27 9
                ->scalarNode('dsl_version')
28 9
                    ->defaultValue('Latest')
29 9
                    ->cannotBeEmpty()
30 9
                    ->beforeNormalization()
31 9
                        ->ifTrue(function($value) {
32 3
                            return !is_string($value)
33 3
                                || !class_exists('Elastica\\QueryBuilder\\Version\\'.$value)
34
                            ;
35 9
                        })
36 9
                        ->thenInvalid('QueryBuilder version "%s" does not exists')
37 9
                    ->end()
38 9
                ->end()
39 9
            ->end()
40
        ;
41
42 9
        return $treeBuilder;
43
    }
44
}
45