Passed
Push — master ( bf62c3...8c031b )
by Emmanuel
01:56
created

ConfigDefinition::getConfigTreeBuilder()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 34
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 31
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 34
ccs 31
cts 31
cp 1
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 30
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * neuralyzer : Data Anonymization Library and CLI Tool
4
 *
5
 * PHP Version 7.1
6
 *
7
 * @author Emmanuel Dyan
8
 * @author Rémi Sauvat
9
 * @copyright 2018 Emmanuel Dyan
10
 *
11
 * @package edyan/neuralyzer
12
 *
13
 * @license GNU General Public License v2.0
14
 *
15
 * @link https://github.com/edyan/neuralyzer
16
 */
17
18
namespace Edyan\Neuralyzer\Configuration;
19
20
use Symfony\Component\Config\Definition\ConfigurationInterface;
21
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
22
23
/**
24
 * Configuration Validation
25
 */
26
class ConfigDefinition implements ConfigurationInterface
27
{
28
    /**
29
     * Validate the configuration
30
     *
31
     * The config structure is something like :
32
     * ## Root
33
     * entities:
34
     *    ## Can be repeated : the name of the table, is an array
35
     *    accounts:
36
     *        cols:
37
     *            ## Can be repeated : the name of the field, is an array
38
     *            name:
39
     *                method: words # Required: name of the method
40
     *                params: [8] # Optional: parameters (an array)
41
     *
42
     * @return TreeBuilder
43
     */
44
    public function getConfigTreeBuilder()
45 27
    {
46
        $treeBuilder = new TreeBuilder();
47 27
        $rootNode = $treeBuilder->root('config');
48 27
        $rootNode
49
            ->children()
50 27
                ->scalarNode('guesser_version')->isRequired()->end()
51 27
                ->scalarNode('language')->defaultValue('en_US')->end()
52 27
                ->arrayNode('entities')
53 27
                    ->isRequired()
54 27
                    ->requiresAtLeastOneElement()
55 27
                    ->prototype('array')
56 27
                        ->children()
57 27
                            ->arrayNode('cols')
58 27
                                ->requiresAtLeastOneElement()
59 27
                                ->prototype('array')
60 27
                                    ->children()
61 27
                                        ->scalarNode('method')->isRequired()->end()
62 27
                                        ->arrayNode('params')
63 27
                                            ->requiresAtLeastOneElement()->prototype('variable')->end()
64 27
                                        ->end()
65 27
                                    ->end()
66 27
                                ->end()
67 27
                            ->end()
68 27
                            ->scalarNode('delete')->defaultValue(false)->end()
69 27
                            ->scalarNode('delete_where')->cannotBeEmpty()->end()
70 27
                        ->end()
71 27
                    ->end()
72 27
                ->end()
73 27
            ->end()
74 27
        ;
75 27
76 27
        return $treeBuilder;
77 27
    }
78
}
79