Completed
Push — master ( d4f9db...ec4c85 )
by Thibaud
15:08
created

RepositoriesNodeBuilder   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 94.74%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 0
cbo 2
dl 0
loc 39
ccs 18
cts 19
cp 0.9474
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfigTreeBuilder() 0 8 1
B getNode() 0 22 4
1
<?php
2
3
namespace Alchemy\PhraseanetBundle\DependencyInjection\Configuration;
4
5
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
6
use Symfony\Component\Config\Definition\ConfigurationInterface;
7
8
class RepositoriesNodeBuilder implements ConfigurationInterface
9
{
10
    /**
11
     * Generates the configuration tree builder.
12
     *
13
     * @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder
14
     */
15 1
    public function getConfigTreeBuilder()
16
    {
17 1
        $treeBuilder = new TreeBuilder();
18
19 1
        $this->getNode($treeBuilder);
20
21 1
        return $treeBuilder;
22
    }
23
24 2
    public function getNode(TreeBuilder $builder = null)
25
    {
26 2
        $builder = $builder ?: new TreeBuilder();
27 2
        $node = $builder->root('repositories');
28
29
        $node
30 2
            ->useAttributeAsKey('name')
31 2
            ->prototype('scalar')
32 2
            ->isRequired()
33 2
            ->cannotBeEmpty()
34 2
            ->validate()
35 2
            ->ifTrue(function ($value) {
36 2
                if ($value == 'search' || $value == 'orders') {
37
                    return false;
38
                }
39
40 2
                return ! class_exists("PhraseanetSDK\\Repository\\" . ucfirst($value));
41 2
            })
42 2
            ->thenInvalid('Repository type does not exist.');
43
44 2
        return $node;
45
    }
46
}
47