Completed
Push — master ( c9ff7a...90cf7c )
by Tobias
28:22 queued 18:22
created

Configuration   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 3
Bugs 0 Features 2
Metric Value
wmc 2
c 3
b 0
f 2
lcom 0
cbo 3
dl 0
loc 30
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B getConfigTreeBuilder() 0 24 2
1
<?php
2
3
namespace Happyr\SerializerBundle\DependencyInjection;
4
5
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
6
use Symfony\Component\Config\Definition\ConfigurationInterface;
7
8
/**
9
 * This is the class that validates and merges configuration from your app/config files.
10
 *
11
 * @author Tobias Nyholm <[email protected]>
12
 */
13
class Configuration implements ConfigurationInterface
14
{
15
    /**
16
     * {@inheritdoc}
17
     */
18
    public function getConfigTreeBuilder()
19
    {
20
        $treeBuilder = new TreeBuilder();
21
        $root = $treeBuilder->root('happyr_serializer');
22
23
        $root->children()
24
            ->booleanNode('twig_extension')->defaultFalse()->end()
25
            ->arrayNode('source')
26
                ->prototype('scalar')
27
                ->validate()
28
                ->always(function ($v) {
29
                    $v = str_replace(DIRECTORY_SEPARATOR, '/', $v);
30
31
                    if (!is_dir($v)) {
32
                        throw new \Exception(sprintf('The directory "%s" does not exist.', $v));
33
                    }
34
35
                    return $v;
36
                })
37
                ->end()
38
            ->end();
39
40
        return $treeBuilder;
41
    }
42
}
43