Passed
Push — master ( c103e2...560387 )
by Emmanuel
03:39
created

ConfigDefinition   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 52
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 52
ccs 28
cts 28
cp 1
rs 10
c 0
b 0
f 0

1 Method

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