| Conditions | 10 |
| Paths | 13 |
| Total Lines | 46 |
| Code Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 16 |
| CRAP Score | 10.7998 |
| 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 |
||
| 7 | 15 | public static function array_merge_defaults (array &$array1, array &$array2, $keyField) |
|
|
|
|||
| 8 | { |
||
| 9 | 15 | $merged = $array1; |
|
| 10 | |||
| 11 | 15 | foreach ($array2 as $key => &$value) |
|
| 12 | { |
||
| 13 | 15 | $valueMerged = false; |
|
| 14 | |||
| 15 | 15 | foreach ($merged as $mergedKey => &$item) |
|
| 16 | { |
||
| 17 | 15 | if (is_array($item) && array_key_exists($keyField, $item) && $item[$keyField] == $value[$keyField]) |
|
| 18 | { |
||
| 19 | $item = array_merge($item, $value); |
||
| 20 | $valueMerged = true; |
||
| 21 | |||
| 22 | break; |
||
| 23 | } |
||
| 24 | 15 | else if ($mergedKey == $key) |
|
| 25 | { |
||
| 26 | 15 | if (is_numeric($mergedKey)) |
|
| 27 | { |
||
| 28 | $merged[] = $value; |
||
| 29 | } |
||
| 30 | 15 | else if (is_array($item)) |
|
| 31 | { |
||
| 32 | 15 | $item = array_unique(array_merge($item, $value)); |
|
| 33 | } |
||
| 34 | else |
||
| 35 | { |
||
| 36 | 15 | $item = $value; |
|
| 37 | } |
||
| 38 | |||
| 39 | 15 | $valueMerged = true; |
|
| 40 | |||
| 41 | 15 | break; |
|
| 42 | } |
||
| 43 | } |
||
| 44 | |||
| 45 | 15 | if (!$valueMerged) |
|
| 46 | { |
||
| 47 | 15 | $merged[$key] = $value; |
|
| 48 | } |
||
| 49 | } |
||
| 50 | |||
| 51 | 15 | return $merged; |
|
| 52 | } |
||
| 53 | } |
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.