| Conditions | 10 |
| Paths | 13 |
| Total Lines | 46 |
| Code Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 23 |
| CRAP Score | 10.5696 |
| 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 |
||
| 25 | 30 | public static function array_merge_defaults(array &$array1, array &$array2, $keyField) |
|
| 26 | { |
||
| 27 | 30 | $merged = $array1; |
|
| 28 | |||
| 29 | 30 | foreach ($array2 as $key => &$value) |
|
| 30 | { |
||
| 31 | 17 | $valueMerged = false; |
|
| 32 | |||
| 33 | 17 | foreach ($merged as $mergedKey => &$item) |
|
| 34 | { |
||
| 35 | 17 | if (is_array($item) && array_key_exists($keyField, $item) && $item[$keyField] == $value[$keyField]) |
|
| 36 | 17 | { |
|
| 37 | $item = array_merge($item, $value); |
||
| 38 | $valueMerged = true; |
||
| 39 | |||
| 40 | break; |
||
| 41 | } |
||
| 42 | 17 | elseif ($mergedKey == $key) |
|
| 43 | { |
||
| 44 | 17 | if (is_numeric($mergedKey)) |
|
| 45 | 17 | { |
|
| 46 | $merged[] = $value; |
||
| 47 | } |
||
| 48 | 17 | elseif (is_array($item)) |
|
| 49 | { |
||
| 50 | 17 | $item = array_unique(array_merge($item, $value)); |
|
| 51 | 17 | } |
|
| 52 | else |
||
| 53 | { |
||
| 54 | 17 | $item = $value; |
|
| 55 | } |
||
| 56 | |||
| 57 | 17 | $valueMerged = true; |
|
| 58 | |||
| 59 | 17 | break; |
|
| 60 | } |
||
| 61 | 17 | } |
|
| 62 | |||
| 63 | 17 | if (!$valueMerged) |
|
| 64 | 17 | { |
|
| 65 | 17 | $merged[$key] = $value; |
|
| 66 | 17 | } |
|
| 67 | 30 | } |
|
| 68 | |||
| 69 | 30 | return $merged; |
|
| 70 | } |
||
| 71 | } |
||
| 72 |
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.