| Conditions | 38 |
| Paths | > 20000 |
| Total Lines | 162 |
| Code Lines | 95 |
| 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 |
||
| 120 | function &_get_form($defines, $additionalFormFields = null, $asUrl = false) |
||
| 121 | { |
||
| 122 | global $app_strings; |
||
| 123 | global $currentModule; |
||
| 124 | |||
| 125 | // Create the additional form fields with real values if they were not passed in |
||
| 126 | if(empty($additionalFormFields) && $this->additional_form_fields) |
||
| 127 | { |
||
| 128 | foreach($this->additional_form_fields as $key=>$value) |
||
| 129 | { |
||
| 130 | if(!empty($defines['focus']->$value)) |
||
| 131 | { |
||
| 132 | $additionalFormFields[$key] = $defines['focus']->$value; |
||
| 133 | } |
||
| 134 | else |
||
| 135 | { |
||
| 136 | $additionalFormFields[$key] = ''; |
||
| 137 | } |
||
| 138 | } |
||
| 139 | } |
||
| 140 | |||
| 141 | |||
| 142 | if(!empty($this->module)) |
||
| 143 | { |
||
| 144 | $defines['child_module_name'] = $this->module; |
||
| 145 | } |
||
| 146 | else |
||
| 147 | { |
||
| 148 | $defines['child_module_name'] = $defines['module']; |
||
| 149 | } |
||
| 150 | |||
| 151 | $defines['parent_bean_name'] = get_class( $defines['focus']); |
||
| 152 | $relationship_name = $this->get_subpanel_relationship_name($defines); |
||
| 153 | |||
| 154 | |||
| 155 | $formValues = array(); |
||
| 156 | |||
| 157 | //module_button is used to override the value of module name |
||
| 158 | $formValues['module'] = $defines['child_module_name']; |
||
| 159 | $formValues[strtolower($defines['parent_bean_name'])."_id"] = $defines['focus']->id; |
||
| 160 | |||
| 161 | if(isset($defines['focus']->name)) |
||
| 162 | { |
||
| 163 | $formValues[strtolower($defines['parent_bean_name'])."_name"] = $defines['focus']->name; |
||
| 164 | // #26451,add these fields for custom one-to-many relate field. |
||
| 165 | if(!empty($defines['child_module_name'])){ |
||
| 166 | $formValues[$relationship_name."_name"] = $defines['focus']->name; |
||
| 167 | $childFocusName = !empty($GLOBALS['beanList'][$defines['child_module_name']]) ? $GLOBALS['beanList'][$defines['child_module_name']] : ""; |
||
| 168 | if(!empty($GLOBALS['dictionary'][ $childFocusName ]["fields"][$relationship_name .'_name']['id_name'])){ |
||
| 169 | $formValues[$GLOBALS['dictionary'][ $childFocusName ]["fields"][$relationship_name .'_name']['id_name']] = $defines['focus']->id; |
||
| 170 | } |
||
| 171 | } |
||
| 172 | } |
||
| 173 | |||
| 174 | $formValues['return_module'] = $currentModule; |
||
| 175 | |||
| 176 | if($currentModule == 'Campaigns'){ |
||
| 177 | $formValues['return_action'] = "DetailView"; |
||
| 178 | }else{ |
||
| 179 | $formValues['return_action'] = $defines['action']; |
||
| 180 | if ( $formValues['return_action'] == 'SubPanelViewer' ) { |
||
| 181 | $formValues['return_action'] = 'DetailView'; |
||
| 182 | } |
||
| 183 | } |
||
| 184 | |||
| 185 | $formValues['return_id'] = $defines['focus']->id; |
||
| 186 | $formValues['return_relationship'] = $relationship_name; |
||
| 187 | switch ( strtolower( $currentModule ) ) |
||
| 188 | { |
||
| 189 | case 'prospects' : |
||
|
|
|||
| 190 | $name = $defines['focus']->account_name ; |
||
| 191 | break ; |
||
| 192 | case 'documents' : |
||
| 193 | $name = $defines['focus']->document_name ; |
||
| 194 | break ; |
||
| 195 | case 'kbdocuments' : |
||
| 196 | $name = $defines['focus']->kbdocument_name ; |
||
| 197 | break ; |
||
| 198 | case 'leads' : |
||
| 199 | case 'contacts' : |
||
| 200 | $name = $defines['focus']->first_name . " " .$defines['focus']->last_name ; |
||
| 201 | break ; |
||
| 202 | default : |
||
| 203 | $name = (isset($defines['focus']->name)) ? $defines['focus']->name : ""; |
||
| 204 | } |
||
| 205 | $formValues['return_name'] = $name; |
||
| 206 | |||
| 207 | // TODO: move this out and get $additionalFormFields working properly |
||
| 208 | if(empty($additionalFormFields['parent_type'])) |
||
| 209 | { |
||
| 210 | if($defines['focus']->object_name=='Contact') { |
||
| 211 | $additionalFormFields['parent_type'] = 'Accounts'; |
||
| 212 | } |
||
| 213 | else { |
||
| 214 | $additionalFormFields['parent_type'] = $defines['focus']->module_dir; |
||
| 215 | } |
||
| 216 | } |
||
| 217 | if(empty($additionalFormFields['parent_name'])) |
||
| 218 | { |
||
| 219 | if($defines['focus']->object_name=='Contact') { |
||
| 220 | $additionalFormFields['parent_name'] = $defines['focus']->account_name; |
||
| 221 | $additionalFormFields['account_name'] = $defines['focus']->account_name; |
||
| 222 | } |
||
| 223 | else { |
||
| 224 | $additionalFormFields['parent_name'] = $defines['focus']->name; |
||
| 225 | } |
||
| 226 | } |
||
| 227 | if(empty($additionalFormFields['parent_id'])) |
||
| 228 | { |
||
| 229 | if($defines['focus']->object_name=='Contact') { |
||
| 230 | $additionalFormFields['parent_id'] = $defines['focus']->account_id; |
||
| 231 | $additionalFormFields['account_id'] = $defines['focus']->account_id; |
||
| 232 | } else if($defines['focus']->object_name=='Contract') { |
||
| 233 | $additionalFormFields['contract_id'] = $defines['focus']->id; |
||
| 234 | } else { |
||
| 235 | $additionalFormFields['parent_id'] = $defines['focus']->id; |
||
| 236 | } |
||
| 237 | } |
||
| 238 | |||
| 239 | if ($defines['focus']->object_name=='Opportunity') { |
||
| 240 | $additionalFormFields['account_id'] = $defines['focus']->account_id; |
||
| 241 | $additionalFormFields['account_name'] = $defines['focus']->account_name; |
||
| 242 | } |
||
| 243 | |||
| 244 | if (!empty($defines['child_module_name']) and $defines['child_module_name']=='Contacts' and !empty($defines['parent_bean_name']) and $defines['parent_bean_name']=='contact' ) { |
||
| 245 | if (!empty($defines['focus']->id ) and !empty($defines['focus']->name)) { |
||
| 246 | $formValues['reports_to_id'] = $defines['focus']->id; |
||
| 247 | $formValues['reports_to_name'] = $defines['focus']->name; |
||
| 248 | } |
||
| 249 | } |
||
| 250 | $formValues['action'] = "EditView"; |
||
| 251 | |||
| 252 | if ( $asUrl ) { |
||
| 253 | $returnLink = ''; |
||
| 254 | foreach($formValues as $key => $value ) { |
||
| 255 | $returnLink .= $key.'='.$value.'&'; |
||
| 256 | } |
||
| 257 | foreach($additionalFormFields as $key => $value ) { |
||
| 258 | $returnLink .= $key.'='.$value.'&'; |
||
| 259 | } |
||
| 260 | $returnLink = rtrim($returnLink,'&'); |
||
| 261 | |||
| 262 | return $returnLink; |
||
| 263 | } else { |
||
| 264 | |||
| 265 | $form = 'form' . $relationship_name; |
||
| 266 | $button = '<form action="index.php" method="post" name="form" id="' . $form . "\">\n"; |
||
| 267 | foreach($formValues as $key => $value) { |
||
| 268 | $button .= "<input type='hidden' name='" . $key . "' value='" . $value . "' />\n"; |
||
| 269 | } |
||
| 270 | |||
| 271 | // fill in additional form fields for all but action |
||
| 272 | foreach($additionalFormFields as $key => $value) { |
||
| 273 | if($key != 'action') { |
||
| 274 | $button .= "<input type='hidden' name='" . $key . "' value='" . $value . "' />\n"; |
||
| 275 | } |
||
| 276 | } |
||
| 277 | |||
| 278 | |||
| 279 | return $button; |
||
| 280 | } |
||
| 281 | } |
||
| 282 | |||
| 344 |
As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.