Completed
Branch master (80ac3a)
by kacper
04:34 queued 51s
created

ConfigFactory::makeConfigFromArray()   F

Complexity

Conditions 20
Paths > 20000

Size

Total Lines 76
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 73
CRAP Score 20

Importance

Changes 0
Metric Value
cc 20
eloc 37
nc 131073
nop 1
dl 0
loc 76
ccs 73
cts 73
cp 1
crap 20
rs 2.3281
c 0
b 0
f 0

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