| Conditions | 32 |
| Paths | 1800 |
| Total Lines | 163 |
| Code Lines | 71 |
| 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 |
||
| 111 | function _getTabs($tabs, $showTabs = true, $selectedGroup='All') |
||
| 112 | { |
||
| 113 | //WDong Bug: 12258 "All" tab in the middle of a record's detail view is not localized. |
||
| 114 | if($selectedGroup=='All') |
||
| 115 | $selectedGroup=translate('LBL_TABGROUP_ALL'); |
||
| 116 | |||
| 117 | // Set up a mapping from subpanelID, found in the $tabs list, to the source module name |
||
| 118 | // As the $GLOBALS['tabStructure'] array holds the Group Tabs by module name we need to efficiently convert between the two |
||
| 119 | // when constructing the subpanel tabs |
||
| 120 | // Note that we can't use the very similar GroupedTabStructure class as it lacks this mapping, and logically, it is designed |
||
| 121 | // for use when constructing the module by module tabs, not the subpanel tabs, as we move away from using module names to represent |
||
| 122 | // subpanels, and use unique subpanel IDs instead. |
||
| 123 | |||
| 124 | $moduleNames = array () ; |
||
| 125 | foreach ( $tabs as $subpanelID ) |
||
| 126 | { |
||
| 127 | // Bug #44344 : Custom relationships under same module only show once in subpanel tabs |
||
| 128 | // use object property instead new object to have ability run unit test (can override subpanel_definitions) |
||
| 129 | $subpanel = $this->subpanel_definitions->load_subpanel( $subpanelID ); |
||
| 130 | if ($subpanel !== false) |
||
| 131 | $moduleNames [ $subpanelID ] = $subpanel->get_module_name() ; |
||
| 132 | } |
||
| 133 | |||
| 134 | $groups = array () ; |
||
| 135 | $found = array () ; |
||
| 136 | |||
| 137 | foreach( $GLOBALS['tabStructure'] as $mainTab => $subModules) |
||
| 138 | { |
||
| 139 | foreach( $subModules['modules'] as $key => $subModule ) |
||
| 140 | { |
||
| 141 | foreach ( $tabs as $subpanelID ) |
||
| 142 | if (isset($moduleNames[ $subpanelID ] ) && strcasecmp( $subModule , $moduleNames[ $subpanelID ] ) === 0) |
||
| 143 | { |
||
| 144 | // Bug #44344 : Custom relationships under same module only show once in subpanel tabs |
||
| 145 | $groups [ translate ( $mainTab ) ] [ 'modules' ] [] = $subpanelID ; |
||
| 146 | $found [ $subpanelID ] = true ; |
||
| 147 | } |
||
| 148 | } |
||
| 149 | } |
||
| 150 | |||
| 151 | // Put all the remaining subpanels into the 'Other' tab. |
||
| 152 | |||
| 153 | foreach( $tabs as $subpanelID ) |
||
| 154 | { |
||
| 155 | if ( ! isset ( $found [ $subpanelID ] ) ) |
||
| 156 | $groups [ translate ('LBL_TABGROUP_OTHER') ]['modules'] [] = $subpanelID ; |
||
| 157 | } |
||
| 158 | |||
| 159 | /* Move history to same tab as activities */ |
||
| 160 | if(in_array('history', $tabs) && in_array('activities', $tabs)) |
||
| 161 | { |
||
| 162 | foreach($groups as $mainTab => $group) |
||
| 163 | { |
||
| 164 | if(in_array('activities', array_map('strtolower', $group['modules']))) |
||
| 165 | { |
||
| 166 | if(!in_array('history', array_map('strtolower', $group['modules']))) |
||
| 167 | { |
||
| 168 | /* Move hist from there to here */ |
||
| 169 | $groups[$mainTab]['modules'] []= 'history'; |
||
| 170 | } |
||
| 171 | } |
||
| 172 | else if(false !== ($i = array_search('history', array_map('strtolower', $group['modules'])))) |
||
| 173 | { |
||
| 174 | unset($groups[$mainTab]['modules'][$i]); |
||
| 175 | if(empty($groups[$mainTab]['modules'])) |
||
| 176 | { |
||
| 177 | unset($groups[$mainTab]); |
||
| 178 | } |
||
| 179 | } |
||
| 180 | } |
||
| 181 | } |
||
| 182 | |||
| 183 | /* Add the 'All' group. |
||
| 184 | * Note that if a tab group already exists with the name 'All', |
||
| 185 | * it will be overwritten in this union operation. |
||
| 186 | */ |
||
| 187 | if(count($groups) <= 1) |
||
| 188 | $groups = array(translate('LBL_TABGROUP_ALL') => array('label' => translate('LBL_TABGROUP_ALL'), 'modules' => $tabs)); |
||
| 189 | else |
||
| 190 | $groups = array(translate('LBL_TABGROUP_ALL') => array('label' => translate('LBL_TABGROUP_ALL'), 'modules' => $tabs)) + $groups; |
||
| 191 | /* Note - all $display checking and array_intersects with $tabs |
||
| 192 | * are now redundant (thanks to GroupedTabStructure), and could |
||
| 193 | * be removed for performance, but for now can stay to help ensure |
||
| 194 | * that the tabs get renedered correctly. |
||
| 195 | */ |
||
| 196 | |||
| 197 | $retTabs = array(); |
||
| 198 | if($showTabs) |
||
| 199 | { |
||
| 200 | require_once('include/SubPanel/SugarTab.php'); |
||
| 201 | $sugarTab = new SugarTab(); |
||
| 202 | |||
| 203 | $displayTabs = array(); |
||
| 204 | $otherTabs = array(); |
||
| 205 | |||
| 206 | foreach ($groups as $key=>$tab) |
||
| 207 | { |
||
| 208 | $display = false; |
||
| 209 | foreach($tab['modules'] as $subkey=>$subtab) |
||
| 210 | { |
||
| 211 | if(in_array(strtolower($subtab), $tabs)) |
||
| 212 | { |
||
| 213 | $display = true; |
||
| 214 | break; |
||
| 215 | } |
||
| 216 | } |
||
| 217 | |||
| 218 | $selected = ''; |
||
| 219 | |||
| 220 | if($selectedGroup == $key) |
||
| 221 | { |
||
| 222 | $selected = 'current'; |
||
| 223 | } |
||
| 224 | |||
| 225 | if($display) |
||
| 226 | { |
||
| 227 | $relevantTabs = SubPanelTilesTabs::applyUserCustomLayoutToTabs($tabs, $key); |
||
| 228 | |||
| 229 | $sugarTabs[$key] = array(//'url'=>'index.php?module=' . $_REQUEST['module'] . '&record=' . $_REQUEST['record'] . '&action=' . $_REQUEST['action']. '&subpanel=' . $key.'#tabs', |
||
| 230 | //'url'=>"javascript:SUGAR.util.retrieveAndFill('index.php?to_pdf=1&module=MySettings&action=LoadTabSubpanels&loadModule={$_REQUEST['module']}&record={$_REQUEST['record']}&subpanel=$key','subpanel_list',null,null,null);", |
||
| 231 | 'label'=>( !empty($tab['label']) ? $tab['label']: $key ), |
||
| 232 | 'type'=>$selected); |
||
| 233 | |||
| 234 | $otherTabs[$key] = array('key'=>$key, 'tabs'=>array()); |
||
| 235 | |||
| 236 | $orderedTabs = array_intersect($relevantTabs, array_map('strtolower', $groups[$key]['modules'])); |
||
| 237 | |||
| 238 | foreach($orderedTabs as $subkey => $subtab) |
||
| 239 | { |
||
| 240 | $otherTabs[$key]['tabs'][$subkey] = array('key'=>$subtab, 'label'=>translate($this->subpanel_definitions->layout_defs['subpanel_setup'][$subtab]['title_key'])); |
||
| 241 | } |
||
| 242 | |||
| 243 | if($selectedGroup == $key) |
||
| 244 | { |
||
| 245 | $displayTabs = $otherTabs[$key]['tabs']; |
||
| 246 | $retTabs = $orderedTabs; |
||
| 247 | } |
||
| 248 | } |
||
| 249 | } |
||
| 250 | |||
| 251 | if(empty($displayTabs) && !empty($otherTabs)) |
||
| 252 | { |
||
| 253 | //WDong Bug: 12258 "All" tab in the middle of a record's detail view is not localized. |
||
| 254 | $selectedGroup = translate('LBL_TABGROUP_ALL'); |
||
| 255 | $displayTabs = $otherTabs[$selectedGroup]['tabs']; |
||
| 256 | $sugarTabs[$selectedGroup]['type'] = 'current'; |
||
| 257 | $retTabs = array_intersect($tabs, array_map('strtolower', $groups[$selectedGroup]['modules'])); |
||
| 258 | } |
||
| 259 | |||
| 260 | if (!empty($sugarTabs) || !empty($otherTabs) ) { |
||
| 261 | $sugarTab->setup($sugarTabs, $otherTabs, $displayTabs, $selectedGroup); |
||
| 262 | $sugarTab->display(); |
||
| 263 | } |
||
| 264 | } |
||
| 265 | else |
||
| 266 | { |
||
| 267 | $tabs = SubPanelTilesTabs::applyUserCustomLayoutToTabs($tabs, $selectedGroup); |
||
| 268 | |||
| 269 | $retTabs = array_intersect($tabs, array_map('strtolower', $groups[$selectedGroup]['modules'])); |
||
| 270 | } |
||
| 271 | |||
| 272 | return $retTabs; |
||
| 273 | } |
||
| 274 | } |
||
| 276 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.