Conditions | 10 |
Paths | 5 |
Total Lines | 34 |
Code Lines | 25 |
Lines | 0 |
Ratio | 0 % |
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 |
||
24 | public static function merge(&$origin, $merge, array $saveKeys = [], $idKey = null) |
||
25 | { |
||
26 | $checkMergeType = function ($a) { |
||
27 | if ($a instanceof Aggregate) { |
||
28 | return 16; |
||
29 | } elseif ($a instanceof PreAggregate) { |
||
30 | return 4; |
||
31 | } else { |
||
32 | if (is_array($a)) { |
||
33 | return 1; |
||
34 | } |
||
35 | } |
||
36 | |||
37 | return null; |
||
38 | }; |
||
39 | |||
40 | $typeOne = $checkMergeType($origin); |
||
41 | $typeTwo = $checkMergeType($merge); |
||
42 | $mergeType = $typeOne + $typeTwo; |
||
43 | |||
44 | if (32 === $mergeType) { |
||
45 | self::mergePre($origin, $merge, $saveKeys, $idKey); |
||
46 | self::mergeAgg($origin, $merge); |
||
47 | } elseif (16 === $typeOne && 4 === $typeTwo) { |
||
48 | self::mergePre($origin, $merge, $saveKeys, $idKey); |
||
49 | self::mergePreToAgg($origin, $merge); |
||
50 | } elseif (4 <= $typeOne && 4 <= $typeTwo) { |
||
51 | self::mergePre($origin, $merge, $saveKeys, $idKey); |
||
52 | } elseif (2 === $mergeType) { |
||
53 | self::mergeArrays($origin, $merge, $saveKeys); |
||
54 | } else { |
||
55 | throw new AggregatorException('cant be merged'); |
||
56 | } |
||
57 | } |
||
58 | |||
149 | } |