| Conditions | 9 |
| Paths | 24 |
| Total Lines | 54 |
| Code Lines | 39 |
| Lines | 32 |
| Ratio | 59.26 % |
| 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 |
||
| 72 | function getGroupings($orgId, $app, $id, &$matchedGrouping, &$parentGrouping) { |
||
| 73 | $return = array(); |
||
| 74 | $currentData = array(); |
||
| 75 | $currentGrouping = null; |
||
| 76 | $match = false; |
||
| 77 | |||
| 78 | $data = ORM::for_table('grouping')-> |
||
| 79 | order_by_asc('grouping_left')-> |
||
| 80 | where('organization_id', $orgId)-> |
||
| 81 | where_gt('grouping_level', 0)-> |
||
| 82 | find_array(); |
||
| 83 | |||
| 84 | foreach ($data as $grouping) { |
||
| 85 | if ($grouping['grouping_level'] == 1) { |
||
| 86 | View Code Duplication | if ($currentGrouping != null) { |
|
| 87 | array_unshift($currentData, |
||
| 88 | array( |
||
| 89 | 'caption' => $currentGrouping['display_name'] |
||
| 90 | )); |
||
| 91 | $return[] = $currentData; |
||
| 92 | if ($match) { |
||
| 93 | $parentGrouping = $currentGrouping; |
||
| 94 | } |
||
| 95 | } |
||
| 96 | $currentData = array(); |
||
| 97 | $currentGrouping = $grouping; |
||
| 98 | $match = false; |
||
| 99 | } |
||
| 100 | View Code Duplication | else { |
|
| 101 | $localMatch = ($id == $grouping['id']); |
||
| 102 | $currentData[] = array( |
||
| 103 | 'caption' => $grouping['display_name'], |
||
| 104 | 'active' => $localMatch, |
||
| 105 | 'target' => $app->urlFor('grouping', array('id' => $grouping['id'])) |
||
| 106 | ); |
||
| 107 | if ($localMatch) { |
||
| 108 | $matchedGrouping = $grouping; |
||
| 109 | } |
||
| 110 | $match = $match || $localMatch; |
||
| 111 | } |
||
| 112 | } |
||
| 113 | View Code Duplication | if ($currentGrouping != null) { |
|
| 114 | array_unshift($currentData, |
||
| 115 | array( |
||
| 116 | 'caption' => $currentGrouping['display_name'] |
||
| 117 | )); |
||
| 118 | $return[] = $currentData; |
||
| 119 | if ($match) { |
||
| 120 | $parentGrouping = $currentGrouping; |
||
| 121 | } |
||
| 122 | } |
||
| 123 | |||
| 124 | return $return; |
||
| 125 | } |
||
| 126 | |||
| 159 |