| Conditions | 10 |
| Paths | 13 |
| Total Lines | 46 |
| Code Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 25 |
| CRAP Score | 10.4632 |
| 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 |
||
| 18 | 16 | public static function array_merge_defaults (array &$array1, array &$array2, $keyField) |
|
| 19 | { |
||
| 20 | 16 | $merged = $array1; |
|
| 21 | |||
| 22 | 16 | foreach ($array2 as $key => &$value) |
|
| 23 | { |
||
| 24 | 16 | $valueMerged = false; |
|
| 25 | |||
| 26 | 16 | foreach ($merged as $mergedKey => &$item) |
|
| 27 | { |
||
| 28 | 16 | if (is_array($item) && array_key_exists($keyField, $item) && $item[$keyField] == $value[$keyField]) |
|
| 29 | 16 | { |
|
| 30 | $item = array_merge($item, $value); |
||
| 31 | $valueMerged = true; |
||
| 32 | |||
| 33 | break; |
||
| 34 | } |
||
| 35 | 16 | else if ($mergedKey == $key) |
|
| 36 | 16 | { |
|
| 37 | 15 | if (is_numeric($mergedKey)) |
|
| 38 | 15 | { |
|
| 39 | $merged[] = $value; |
||
| 40 | } |
||
| 41 | 15 | else if (is_array($item)) |
|
| 42 | 15 | { |
|
| 43 | 15 | $item = array_unique(array_merge($item, $value)); |
|
| 44 | 15 | } |
|
| 45 | else |
||
| 46 | { |
||
| 47 | 15 | $item = $value; |
|
| 48 | } |
||
| 49 | |||
| 50 | 15 | $valueMerged = true; |
|
| 51 | |||
| 52 | 15 | break; |
|
| 53 | } |
||
| 54 | 16 | } |
|
| 55 | |||
| 56 | 16 | if (!$valueMerged) |
|
| 57 | 16 | { |
|
| 58 | 16 | $merged[$key] = $value; |
|
| 59 | 16 | } |
|
| 60 | 16 | } |
|
| 61 | |||
| 62 | 16 | return $merged; |
|
| 63 | } |
||
| 64 | } |
This check looks for method names that are not written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes
databaseConnectionSeeker.