Test Failed
Push — master ( 359bf7...72eda2 )
by Emmanuel
02:11
created

ConfigDefinition   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 3
dl 0
loc 53
rs 10
c 0
b 0
f 0
ccs 0
cts 33
cp 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B getConfigTreeBuilder() 0 34 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
    {
46
        $treeBuilder = new TreeBuilder();
47
        $rootNode = $treeBuilder->root('config');
48
        $rootNode
49
            ->children()
50
                ->scalarNode('guesser_version')->isRequired()->end()
51
                ->scalarNode('language')->defaultValue('en_US')->end()
52
                ->arrayNode('entities')
53
                    ->isRequired()
54
                    ->requiresAtLeastOneElement()
55
                    ->prototype('array')
56
                        ->children()
57
                            ->arrayNode('cols')
58
                                ->requiresAtLeastOneElement()
59
                                ->prototype('array')
60
                                    ->children()
61
                                        ->scalarNode('method')->isRequired()->end()
62
                                        ->arrayNode('params')
63
                                            ->requiresAtLeastOneElement()->prototype('variable')->end()
64
                                        ->end()
65
                                    ->end()
66
                                ->end()
67
                            ->end()
68
                            ->scalarNode('delete')->defaultValue(false)->end()
69
                            ->scalarNode('delete_where')->cannotBeEmpty()->end()
70
                        ->end()
71
                    ->end()
72
                ->end()
73
            ->end()
74
        ;
75
76
        return $treeBuilder;
77
    }
78
}
79