Passed
Branch master (e090ea)
by kacper
04:22
created

ConfigFactory::makeConfigFromArray()   F

Complexity

Conditions 19
Paths > 20000

Size

Total Lines 73
Code Lines 36

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 380

Importance

Changes 0
Metric Value
dl 0
loc 73
ccs 0
cts 72
cp 0
rs 2.4278
c 0
b 0
f 0
cc 19
eloc 36
nc 65537
nop 1
crap 380

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace MySQLReplication\Config;
4
5
/**
6
 * Class ConfigService
7
 * @package MySQLReplication\Config
8
 */
9
class ConfigFactory
10
{
11
    /**
12
     * @param array $config
13
     * @return Config
14
     */
15
    public function makeConfigFromArray(array $config)
16
    {
17
        $configBuilder = new ConfigBuilder();
18
        foreach ($config as $k => $v)
19
        {
20
            if ('user' === $k)
21
            {
22
                $configBuilder->withUser($v);
23
            }
24
            if ('ip' === $k || 'host' === $k)
25
            {
26
                $configBuilder->withHost($v);
27
            }
28
            if ('port' === $k)
29
            {
30
                $configBuilder->withPort($v);
31
            }
32
            if ('password' === $k)
33
            {
34
                $configBuilder->withPassword($v);
35
            }
36
            if ('charset' === $k)
37
            {
38
                $configBuilder->withCharset($v);
39
            }
40
            if ('gtid' === $k)
41
            {
42
                $configBuilder->withGtid($v);
43
            }
44
            if ('slaveId' === $k)
45
            {
46
                $configBuilder->withSlaveId($v);
47
            }
48
            if ('binLogFileName' === $k)
49
            {
50
                $configBuilder->withBinLogFileName($v);
51
            }
52
            if ('binLogPosition' === $k)
53
            {
54
                $configBuilder->withBinLogPosition($v);
55
            }
56
            if ('eventsOnly' === $k)
57
            {
58
                $configBuilder->withEventsOnly($v);
59
            }
60
            if ('eventsIgnore' === $k)
61
            {
62
                $configBuilder->withEventsIgnore($v);
63
            }
64
            if ('tablesOnly' === $k)
65
            {
66
                $configBuilder->withTablesOnly($v);
67
            }
68
            if ('databasesOnly' === $k)
69
            {
70
                $configBuilder->withDatabasesOnly($v);
71
            }
72
            if ('mariaDbGtid' === $k)
73
            {
74
                $configBuilder->withMariaDbGtid($v);
75
            }
76
            if ('tableCacheSize' === $k)
77
            {
78
                $configBuilder->withTableCacheSize($v);
79
            }
80
            if ('custom' === $k)
81
            {
82
                $configBuilder->withCustom($v);
83
            }
84
        }
85
86
        return $configBuilder->build();
87
    }
88
}