| Conditions | 18 |
| Paths | 984 |
| Total Lines | 92 |
| Code Lines | 45 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 342 |
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 |
||
| 56 | function get_tab_structure($modList = '', $patch = '', $ignoreSugarConfig=false, $labelAsKey=false) |
||
| 57 | { |
||
| 58 | global $modListHeader, $app_strings, $app_list_strings, $modInvisListActivities; |
||
| 59 | |||
| 60 | /* Use default if not provided */ |
||
| 61 | if(!$modList) |
||
| 62 | { |
||
| 63 | $modList =& $modListHeader; |
||
| 64 | } |
||
| 65 | |||
| 66 | require 'include/tabConfig.php'; |
||
| 67 | |||
| 68 | /* Apply patch, use a reference if we can */ |
||
| 69 | if($patch) |
||
| 70 | { |
||
| 71 | $tabStructure = $GLOBALS['tabStructure']; |
||
| 72 | |||
| 73 | foreach($patch as $mainTab => $subModules) |
||
|
|
|||
| 74 | { |
||
| 75 | $tabStructure[$mainTab]['modules'] = array_merge($tabStructure[$mainTab]['modules'], $subModules); |
||
| 76 | } |
||
| 77 | } |
||
| 78 | else |
||
| 79 | { |
||
| 80 | $tabStructure =& $GLOBALS['tabStructure']; |
||
| 81 | } |
||
| 82 | |||
| 83 | $retStruct = array(); |
||
| 84 | $mlhUsed = array(); |
||
| 85 | //the invisible list should be merged if activities is set to be hidden |
||
| 86 | if(in_array('Activities', $modList)){ |
||
| 87 | $modList = array_merge($modList,$modInvisListActivities); |
||
| 88 | } |
||
| 89 | |||
| 90 | //Add any iFrame tabs to the 'other' group. |
||
| 91 | $moduleExtraMenu = array(); |
||
| 92 | if(!should_hide_iframes()) { |
||
| 93 | $iFrame = new iFrame(); |
||
| 94 | $frames = $iFrame->lookup_frames('tab'); |
||
| 95 | foreach($frames as $key => $values){ |
||
| 96 | $moduleExtraMenu[$key] = $values; |
||
| 97 | } |
||
| 98 | } else if(isset($modList['iFrames'])) { |
||
| 99 | unset($modList['iFrames']); |
||
| 100 | } |
||
| 101 | |||
| 102 | $modList = array_merge($modList,$moduleExtraMenu); |
||
| 103 | |||
| 104 | /* Only return modules which exists in the modList */ |
||
| 105 | foreach($tabStructure as $mainTab => $subModules) |
||
| 106 | { |
||
| 107 | //Ensure even empty groups are returned |
||
| 108 | if($labelAsKey){ |
||
| 109 | $retStruct[$subModules['label']]['modules'] = array(); |
||
| 110 | }else{ |
||
| 111 | $retStruct[$app_strings[$subModules['label']]]['modules']= array(); |
||
| 112 | } |
||
| 113 | |||
| 114 | foreach($subModules['modules'] as $key => $subModule) |
||
| 115 | { |
||
| 116 | /* Perform a case-insensitive in_array check |
||
| 117 | * and mark whichever module matched as used. |
||
| 118 | */ |
||
| 119 | foreach($modList as $module) |
||
| 120 | { |
||
| 121 | if(is_string($module) && strcasecmp($subModule, $module) === 0) |
||
| 122 | { |
||
| 123 | if($labelAsKey){ |
||
| 124 | $retStruct[$subModules['label']]['modules'][$module] = $app_list_strings['moduleList'][$module]; |
||
| 125 | }else{ |
||
| 126 | $retStruct[$app_strings[$subModules['label']]]['modules'][$module] = $app_list_strings['moduleList'][$module]; |
||
| 127 | } |
||
| 128 | $mlhUsed[$module] = true; |
||
| 129 | break; |
||
| 130 | } |
||
| 131 | } |
||
| 132 | } |
||
| 133 | //remove the group tabs if it has no sub modules under it |
||
| 134 | if($labelAsKey){ |
||
| 135 | if (empty($retStruct[$subModules['label']]['modules'])){ |
||
| 136 | unset($retStruct[$subModules['label']]); |
||
| 137 | } |
||
| 138 | }else{ |
||
| 139 | if (empty($retStruct[$app_strings[$subModules['label']]]['modules'])){ |
||
| 140 | unset($retStruct[$app_strings[$subModules['label']]]); |
||
| 141 | } |
||
| 142 | } |
||
| 143 | } |
||
| 144 | |||
| 145 | // _pp($retStruct); |
||
| 146 | return $retStruct; |
||
| 147 | } |
||
| 148 | } |
||
| 151 |