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

RepositoriesNodeBuilder::getNode()   B

Complexity

Conditions 4
Paths 2

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 4.0047

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 22
ccs 14
cts 15
cp 0.9333
rs 8.9197
cc 4
eloc 15
nc 2
nop 1
crap 4.0047
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