Passed
Push — master ( ca0b2f...372969 )
by Emmanuel
03:25
created

ConfigDefinition   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 3
dl 0
loc 53
ccs 29
cts 29
cp 1
rs 10
c 0
b 0
f 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 25
    public function getConfigTreeBuilder()
45
    {
46 25
        $treeBuilder = new TreeBuilder();
47 25
        $rootNode = $treeBuilder->root('config');
48
        $rootNode
49 25
            ->children()
50 25
                ->scalarNode('guesser_version')->isRequired()->end()
51 25
                ->scalarNode('language')->defaultValue('en_US')->end()
52 25
                ->arrayNode('entities')
53 25
                    ->isRequired()
54 25
                    ->requiresAtLeastOneElement()
55 25
                    ->prototype('array')
56 25
                        ->children()
57 25
                            ->arrayNode('cols')
58 25
                                ->requiresAtLeastOneElement()
59 25
                                ->prototype('array')
60 25
                                    ->children()
61 25
                                        ->scalarNode('method')->isRequired()->end()
62 25
                                        ->arrayNode('params')
63 25
                                            ->requiresAtLeastOneElement()->prototype('variable')->end()
64 25
                                        ->end()
65 25
                                    ->end()
66 25
                                ->end()
67 25
                            ->end()
68 25
                            ->scalarNode('delete')->defaultValue(false)->end()
69 25
                            ->scalarNode('delete_where')->cannotBeEmpty()->end()
70 25
                        ->end()
71 25
                    ->end()
72 25
                ->end()
73 25
            ->end()
74
        ;
75
76 25
        return $treeBuilder;
77
    }
78
}
79