| Conditions | 20 |
| Paths | > 20000 |
| Total Lines | 76 |
| Code Lines | 37 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 73 |
| CRAP Score | 20 |
| Changes | 0 | ||
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:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 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 | } |