| Conditions | 19 |
| Paths | > 20000 |
| Total Lines | 73 |
| Code Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 380 |
| 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 | 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 | } |