Passed
Push — master ( 265c0b...e337ae )
by Webnet
01:48
created

ConfigWriter   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 46
rs 10
c 0
b 0
f 0
wmc 7

1 Method

Rating   Name   Duplication   Size   Complexity  
B write() 0 39 7
1
<?php
2
3
namespace WebnetFr\DatabaseAnonymizer\ConfigGuesser;
4
5
use Symfony\Component\Yaml\Yaml;
6
7
/**
8
 * @author Vlad Riabchenko <[email protected]>
9
 */
10
class ConfigWriter
11
{
12
    /**
13
     * @var array
14
     *
15
     * @return string
16
     */
17
    public function write(array $hints)
18
    {
19
        $config = [];
20
21
        foreach ($hints as $tableName => $tableHints) {
22
            foreach ($tableHints as $columnName => $hint) {
23
                /** @var ConfigGuesserHint $hint */
24
                $c = [
25
                    'generator' => 'faker',
26
                    'formatter' => $hint->formatter,
27
                ];
28
29
                if (null !== $hint->arguments) {
30
                    $c['arguments'] = $hint->arguments;
31
                }
32
33
                if (null !== $hint->locale) {
34
                    $c['locale'] = $hint->locale;
35
                }
36
37
                if (null !== $hint->unique) {
38
                    $c['unique'] = $hint->unique;
39
                }
40
41
                if (null !== $hint->date) {
42
                    $c['date_format'] = 'Y-m-d H:i:s';
43
                }
44
45
                $config[$tableName]['fields'][$columnName] = $c;
46
            }
47
        }
48
49
        $config = [
50
            'webnet_fr_database_anonymizer' => [
51
                'tables' => $config,
52
            ],
53
        ];
54
55
        return Yaml::dump($config, 6);
56
    }
57
}
58