| Conditions | 23 |
| Paths | > 20000 |
| Total Lines | 115 |
| Code Lines | 70 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 552 |
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 |
||
| 65 | function display() |
||
| 66 | { |
||
| 67 | $editModule = $_REQUEST['view_module']; |
||
| 68 | $allLabels = (!empty($_REQUEST['labels']) && $_REQUEST['labels']== 'all'); |
||
| 69 | |||
| 70 | if (!isset($_REQUEST['MB'])) |
||
| 71 | { |
||
| 72 | global $app_list_strings; |
||
| 73 | $moduleNames = array_change_key_case($app_list_strings['moduleList']); |
||
| 74 | $translatedEditModule = $moduleNames[strtolower($editModule)]; |
||
| 75 | } |
||
| 76 | $selected_lang = (!empty($_REQUEST['selected_lang'])? $_REQUEST['selected_lang']:$_SESSION['authenticated_user_language']); |
||
| 77 | if(empty($selected_lang)){ |
||
| 78 | $selected_lang = $GLOBALS['sugar_config']['default_language']; |
||
| 79 | } |
||
| 80 | |||
| 81 | $smarty = new Sugar_Smarty(); |
||
| 82 | global $mod_strings; |
||
| 83 | $smarty->assign('mod_strings', $mod_strings); |
||
| 84 | $smarty->assign('available_languages',get_languages()); |
||
| 85 | |||
| 86 | |||
| 87 | $objectName = BeanFactory::getObjectName($editModule); |
||
| 88 | VardefManager::loadVardef($editModule, $objectName); |
||
| 89 | global $dictionary; |
||
| 90 | $vnames = array(); |
||
| 91 | //jchi 24557 . We should list all the lables in viewdefs(list,detail,edit,quickcreate) that the user can edit them. |
||
| 92 | require_once 'modules/ModuleBuilder/parsers/views/ListLayoutMetaDataParser.php' ; |
||
| 93 | $parser = new ListLayoutMetaDataParser ( MB_LISTVIEW, $editModule ) ; |
||
| 94 | foreach ( $parser->getLayout() as $key => $def ) |
||
| 95 | { |
||
| 96 | if(isset($def['label']) ) { |
||
| 97 | $vnames[$def['label']] = $def['label']; |
||
| 98 | } |
||
| 99 | } |
||
| 100 | |||
| 101 | require_once 'modules/ModuleBuilder/parsers/views/GridLayoutMetaDataParser.php' ; |
||
| 102 | $variableMap = $this->getVariableMap($editModule); |
||
| 103 | foreach($variableMap as $key => $value){ |
||
| 104 | $gridLayoutMetaDataParserTemp = new GridLayoutMetaDataParser ( $value, $editModule) ; |
||
| 105 | foreach ( $gridLayoutMetaDataParserTemp->getLayout() as $panel) |
||
| 106 | { |
||
| 107 | foreach ( $panel as $row ) |
||
| 108 | { |
||
| 109 | foreach ( $row as $fieldArray ) |
||
| 110 | { // fieldArray is an array('name'=>name,'label'=>label) |
||
| 111 | if (isset ( $fieldArray [ 'label' ] )) |
||
| 112 | { |
||
| 113 | $vnames[$fieldArray [ 'label' ] ] = $fieldArray [ 'label' ] ; |
||
| 114 | } |
||
| 115 | } |
||
| 116 | } |
||
| 117 | } |
||
| 118 | } |
||
| 119 | //end |
||
| 120 | |||
| 121 | //Get Subpanel Labels: |
||
| 122 | require_once ('include/SubPanel/SubPanel.php') ; |
||
| 123 | $subList = SubPanel::getModuleSubpanels ( $editModule ); |
||
| 124 | foreach($subList as $subpanel => $titleLabel) { |
||
| 125 | $vnames[$titleLabel] = $titleLabel; |
||
| 126 | } |
||
| 127 | |||
| 128 | foreach($dictionary[$objectName]['fields'] as $name=>$def) { |
||
| 129 | if(isset($def['vname'])) { |
||
| 130 | $vnames[$def['vname']] = $def['vname']; |
||
| 131 | } |
||
| 132 | } |
||
| 133 | $formatted_mod_strings = array(); |
||
| 134 | |||
| 135 | //we shouldn't set the $refresh=true here, or will lost template language mod_strings. |
||
| 136 | //return_module_language($selected_lang, $editModule,false) : the mod_strings will be included from cache files here. |
||
| 137 | foreach(return_module_language($selected_lang, $editModule,false) as $name=>$label) { |
||
|
|
|||
| 138 | //#25294 |
||
| 139 | if($allLabels || isset($vnames[$name]) || preg_match( '/lbl_city|lbl_country|lbl_billing_address|lbl_alt_address|lbl_shipping_address|lbl_postal_code|lbl_state$/si' , $name)) { |
||
| 140 | $formatted_mod_strings[$name] = htmlentities($label, ENT_QUOTES, 'UTF-8'); |
||
| 141 | } |
||
| 142 | } |
||
| 143 | //Grab everything from the custom files |
||
| 144 | $mod_bak = $mod_strings; |
||
| 145 | $files = array( |
||
| 146 | "custom/modules/$editModule/language/$selected_lang.lang.php", |
||
| 147 | "custom/modules/$editModule/Ext/Language/$selected_lang.lang.ext.php" |
||
| 148 | ); |
||
| 149 | foreach($files as $langfile){ |
||
| 150 | $mod_strings = array(); |
||
| 151 | if (is_file($langfile)) |
||
| 152 | { |
||
| 153 | include($langfile); |
||
| 154 | foreach($mod_strings as $key => $label) |
||
| 155 | { |
||
| 156 | $formatted_mod_strings[$key] = htmlentities($label, ENT_QUOTES, 'UTF-8'); |
||
| 157 | } |
||
| 158 | } |
||
| 159 | } |
||
| 160 | $mod_strings = $mod_bak; |
||
| 161 | ksort($formatted_mod_strings); |
||
| 162 | $smarty->assign('MOD', $formatted_mod_strings); |
||
| 163 | $smarty->assign('view_module', $editModule); |
||
| 164 | $smarty->assign('APP', $GLOBALS['app_strings']); |
||
| 165 | $smarty->assign('selected_lang', $selected_lang); |
||
| 166 | $smarty->assign('defaultHelp', 'labelsBtn'); |
||
| 167 | $smarty->assign('assistant', array('key'=>'labels', 'group'=>'module')); |
||
| 168 | $smarty->assign('labels_choice', $mod_strings['labelTypes']); |
||
| 169 | $smarty->assign('labels_current', $allLabels?"all":""); |
||
| 170 | |||
| 171 | $ajax = new AjaxCompose(); |
||
| 172 | $ajax->addCrumb($mod_strings['LBL_STUDIO'], 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard")'); |
||
| 173 | $ajax->addCrumb($translatedEditModule, 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view_module='.$editModule.'")'); |
||
| 174 | $ajax->addCrumb($mod_strings['LBL_LABELS'], ''); |
||
| 175 | |||
| 176 | $html = $smarty->fetch('modules/ModuleBuilder/tpls/labels.tpl'); |
||
| 177 | $ajax->addSection('center', $GLOBALS['mod_strings']['LBL_SECTION_EDLABELS'], $html); |
||
| 178 | echo $ajax->getJavascript(); |
||
| 179 | } |
||
| 180 | |||
| 210 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.