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

RepositoriesNodeBuilder::getConfigTreeBuilder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
crap 1
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