| Conditions | 89 |
| Paths | > 20000 |
| Total Lines | 282 |
| Code Lines | 168 |
| 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:
Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.
There are several approaches to avoid long parameter lists:
| 1 | <?php |
||
| 235 | function getModuleField($module, $fieldname, $aow_field, $view='EditView',$value = '', $alt_type = '', $currency_id = '', $params= array()){ |
||
| 236 | global $current_language, $app_strings, $app_list_strings, $current_user, $beanFiles, $beanList; |
||
| 237 | |||
| 238 | // use the mod_strings for this module |
||
| 239 | $mod_strings = return_module_language($current_language,$module); |
||
| 240 | |||
| 241 | // set the filename for this control |
||
| 242 | $file = create_cache_directory('modules/AOW_WorkFlow/') . $module . $view . $alt_type . $fieldname . '.tpl'; |
||
| 243 | |||
| 244 | $displayParams = array(); |
||
| 245 | |||
| 246 | if ( !is_file($file) |
||
| 247 | || inDeveloperMode() |
||
| 248 | || !empty($_SESSION['developerMode']) ) { |
||
| 249 | |||
| 250 | if ( !isset($vardef) ) { |
||
| 251 | require_once($beanFiles[$beanList[$module]]); |
||
| 252 | $focus = new $beanList[$module]; |
||
| 253 | $vardef = $focus->getFieldDefinition($fieldname); |
||
| 254 | } |
||
| 255 | |||
| 256 | // Bug: check for AOR value SecurityGroups value missing |
||
| 257 | if(stristr($fieldname, 'securitygroups') != false && empty($vardef)) { |
||
| 258 | require_once($beanFiles[$beanList['SecurityGroups']]); |
||
| 259 | $module = 'SecurityGroups'; |
||
| 260 | $focus = new $beanList[$module]; |
||
| 261 | $vardef = $focus->getFieldDefinition($fieldname); |
||
| 262 | } |
||
| 263 | |||
| 264 | |||
| 265 | //$displayParams['formName'] = 'EditView'; |
||
| 266 | |||
| 267 | // if this is the id relation field, then don't have a pop-up selector. |
||
| 268 | if( $vardef['type'] == 'relate' && $vardef['id_name'] == $vardef['name']) { |
||
| 269 | $vardef['type'] = 'varchar'; |
||
| 270 | } |
||
| 271 | |||
| 272 | if(isset($vardef['precision'])) unset($vardef['precision']); |
||
| 273 | |||
| 274 | //$vardef['precision'] = $locale->getPrecedentPreference('default_currency_significant_digits', $current_user); |
||
| 275 | |||
| 276 | //TODO Fix datetimecomebo |
||
| 277 | //temp work around |
||
| 278 | if( $vardef['type'] == 'datetimecombo') { |
||
| 279 | $vardef['type'] = 'datetime'; |
||
| 280 | } |
||
| 281 | |||
| 282 | // trim down textbox display |
||
| 283 | if( $vardef['type'] == 'text' ) { |
||
| 284 | $vardef['rows'] = 2; |
||
| 285 | $vardef['cols'] = 32; |
||
| 286 | } |
||
| 287 | |||
| 288 | // create the dropdowns for the parent type fields |
||
| 289 | if ( $vardef['type'] == 'parent_type' ) { |
||
| 290 | $vardef['type'] = 'enum'; |
||
| 291 | } |
||
| 292 | |||
| 293 | if($vardef['type'] == 'link'){ |
||
| 294 | $vardef['type'] = 'relate'; |
||
| 295 | $vardef['rname'] = 'name'; |
||
| 296 | $vardef['id_name'] = $vardef['name'].'_id'; |
||
| 297 | if((!isset($vardef['module']) || $vardef['module'] == '') && $focus->load_relationship($vardef['name'])) { |
||
| 298 | $relName = $vardef['name']; |
||
| 299 | $vardef['module'] = $focus->$relName->getRelatedModuleName(); |
||
| 300 | } |
||
| 301 | |||
| 302 | } |
||
| 303 | |||
| 304 | //check for $alt_type |
||
| 305 | if ( $alt_type != '' ) { |
||
| 306 | $vardef['type'] = $alt_type; |
||
| 307 | } |
||
| 308 | |||
| 309 | // remove the special text entry field function 'getEmailAddressWidget' |
||
| 310 | if ( isset($vardef['function']) |
||
| 311 | && ( $vardef['function'] == 'getEmailAddressWidget' |
||
| 312 | || $vardef['function']['name'] == 'getEmailAddressWidget' ) ) |
||
| 313 | unset($vardef['function']); |
||
| 314 | |||
| 315 | if(isset($vardef['name']) && ($vardef['name'] == 'date_entered' || $vardef['name'] == 'date_modified')){ |
||
| 316 | $vardef['name'] = 'aow_temp_date'; |
||
| 317 | } |
||
| 318 | |||
| 319 | // load SugarFieldHandler to render the field tpl file |
||
| 320 | static $sfh; |
||
| 321 | |||
| 322 | if(!isset($sfh)) { |
||
| 323 | require_once('include/SugarFields/SugarFieldHandler.php'); |
||
| 324 | $sfh = new SugarFieldHandler(); |
||
| 325 | } |
||
| 326 | |||
| 327 | $contents = $sfh->displaySmarty('fields', $vardef, $view, $displayParams); |
||
| 328 | |||
| 329 | // Remove all the copyright comments |
||
| 330 | $contents = preg_replace('/\{\*[^\}]*?\*\}/', '', $contents); |
||
| 331 | |||
| 332 | if( $view == 'EditView' && ($vardef['type'] == 'relate' || $vardef['type'] == 'parent')){ |
||
| 333 | $contents = str_replace('"'.$vardef['id_name'].'"','{/literal}"{$fields.'.$vardef['name'].'.id_name}"{literal}', $contents); |
||
| 334 | $contents = str_replace('"'.$vardef['name'].'"','{/literal}"{$fields.'.$vardef['name'].'.name}"{literal}', $contents); |
||
| 335 | } |
||
| 336 | |||
| 337 | // hack to disable one of the js calls in this control |
||
| 338 | if ( isset($vardef['function']) && ( $vardef['function'] == 'getCurrencyDropDown' || $vardef['function']['name'] == 'getCurrencyDropDown' ) ) |
||
| 339 | $contents .= "{literal}<script>function CurrencyConvertAll() { return; }</script>{/literal}"; |
||
| 340 | |||
| 341 | // Save it to the cache file |
||
| 342 | if($fh = @sugar_fopen($file, 'w')) { |
||
| 343 | fputs($fh, $contents); |
||
| 344 | fclose($fh); |
||
| 345 | } |
||
| 346 | } |
||
| 347 | |||
| 348 | // Now render the template we received |
||
| 349 | $ss = new Sugar_Smarty(); |
||
| 350 | |||
| 351 | // Create Smarty variables for the Calendar picker widget |
||
| 352 | global $timedate; |
||
| 353 | $time_format = $timedate->get_user_time_format(); |
||
| 354 | $date_format = $timedate->get_cal_date_format(); |
||
| 355 | $ss->assign('USER_DATEFORMAT', $timedate->get_user_date_format()); |
||
| 356 | $ss->assign('TIME_FORMAT', $time_format); |
||
| 357 | $time_separator = ":"; |
||
| 358 | $match = array(); |
||
| 359 | if(preg_match('/\d+([^\d])\d+([^\d]*)/s', $time_format, $match)) { |
||
| 360 | $time_separator = $match[1]; |
||
| 361 | } |
||
| 362 | $t23 = strpos($time_format, '23') !== false ? '%H' : '%I'; |
||
| 363 | if(!isset($match[2]) || $match[2] == '') { |
||
| 364 | $ss->assign('CALENDAR_FORMAT', $date_format . ' ' . $t23 . $time_separator . "%M"); |
||
| 365 | } |
||
| 366 | else { |
||
| 367 | $pm = $match[2] == "pm" ? "%P" : "%p"; |
||
| 368 | $ss->assign('CALENDAR_FORMAT', $date_format . ' ' . $t23 . $time_separator . "%M" . $pm); |
||
| 369 | } |
||
| 370 | |||
| 371 | $ss->assign('CALENDAR_FDOW', $current_user->get_first_day_of_week()); |
||
| 372 | |||
| 373 | // populate the fieldlist from the vardefs |
||
| 374 | $fieldlist = array(); |
||
| 375 | if ( !isset($focus) || !($focus instanceof SugarBean) ) |
||
| 376 | require_once($beanFiles[$beanList[$module]]); |
||
| 377 | $focus = new $beanList[$module]; |
||
| 378 | // create the dropdowns for the parent type fields |
||
| 379 | $vardefFields = $focus->getFieldDefinitions(); |
||
| 380 | if (isset($vardefFields[$fieldname]['type']) && $vardefFields[$fieldname]['type'] == 'parent_type' ) { |
||
| 381 | $focus->field_defs[$fieldname]['options'] = $focus->field_defs[$vardefFields[$fieldname]['group']]['options']; |
||
| 382 | } |
||
| 383 | foreach ( $vardefFields as $name => $properties ) { |
||
| 384 | $fieldlist[$name] = $properties; |
||
| 385 | // fill in enums |
||
| 386 | if(isset($fieldlist[$name]['options']) && is_string($fieldlist[$name]['options']) && isset($app_list_strings[$fieldlist[$name]['options']])) |
||
| 387 | $fieldlist[$name]['options'] = $app_list_strings[$fieldlist[$name]['options']]; |
||
| 388 | // Bug 32626: fall back on checking the mod_strings if not in the app_list_strings |
||
| 389 | elseif(isset($fieldlist[$name]['options']) && is_string($fieldlist[$name]['options']) && isset($mod_strings[$fieldlist[$name]['options']])) |
||
| 390 | $fieldlist[$name]['options'] = $mod_strings[$fieldlist[$name]['options']]; |
||
| 391 | // Bug 22730: make sure all enums have the ability to select blank as the default value. |
||
| 392 | if(!isset($fieldlist[$name]['options'][''])) |
||
| 393 | $fieldlist[$name]['options'][''] = ''; |
||
| 394 | } |
||
| 395 | |||
| 396 | // fill in function return values |
||
| 397 | if ( !in_array($fieldname,array('email1','email2')) ) |
||
| 398 | { |
||
| 399 | if (!empty($fieldlist[$fieldname]['function']['returns']) && $fieldlist[$fieldname]['function']['returns'] == 'html') |
||
| 400 | { |
||
| 401 | $function = $fieldlist[$fieldname]['function']['name']; |
||
| 402 | // include various functions required in the various vardefs |
||
| 403 | if ( isset($fieldlist[$fieldname]['function']['include']) && is_file($fieldlist[$fieldname]['function']['include'])) |
||
| 404 | require_once($fieldlist[$fieldname]['function']['include']); |
||
| 405 | $_REQUEST[$fieldname] = $value; |
||
| 406 | $value = $function($focus, $fieldname, $value, $view); |
||
| 407 | |||
| 408 | $value = str_ireplace($fieldname, $aow_field, $value); |
||
| 409 | } |
||
| 410 | } |
||
| 411 | |||
| 412 | if(isset($fieldlist[$fieldname]['type']) && $fieldlist[$fieldname]['type'] == 'link'){ |
||
| 413 | $fieldlist[$fieldname]['id_name'] = $fieldlist[$fieldname]['name'].'_id'; |
||
| 414 | |||
| 415 | if((!isset($fieldlist[$fieldname]['module']) || $fieldlist[$fieldname]['module'] == '') && $focus->load_relationship($fieldlist[$fieldname]['name'])) { |
||
| 416 | $relName = $fieldlist[$fieldname]['name']; |
||
| 417 | $fieldlist[$fieldname]['module'] = $focus->$relName->getRelatedModuleName(); |
||
| 418 | } |
||
| 419 | } |
||
| 420 | |||
| 421 | if(isset($fieldlist[$fieldname]['name']) && ($fieldlist[$fieldname]['name'] == 'date_entered' || $fieldlist[$fieldname]['name'] == 'date_modified')){ |
||
| 422 | $fieldlist[$fieldname]['name'] = 'aow_temp_date'; |
||
| 423 | $fieldlist['aow_temp_date'] = $fieldlist[$fieldname]; |
||
| 424 | $fieldname = 'aow_temp_date'; |
||
| 425 | } |
||
| 426 | |||
| 427 | $quicksearch_js = ''; |
||
| 428 | if(isset( $fieldlist[$fieldname]['id_name'] ) && $fieldlist[$fieldname]['id_name'] != '' && $fieldlist[$fieldname]['id_name'] != $fieldlist[$fieldname]['name']){ |
||
| 429 | $rel_value = $value; |
||
| 430 | |||
| 431 | require_once("include/TemplateHandler/TemplateHandler.php"); |
||
| 432 | $template_handler = new TemplateHandler(); |
||
| 433 | $quicksearch_js = $template_handler->createQuickSearchCode($fieldlist,$fieldlist,$view); |
||
| 434 | $quicksearch_js = str_replace($fieldname, $aow_field.'_display', $quicksearch_js); |
||
| 435 | $quicksearch_js = str_replace($fieldlist[$fieldname]['id_name'], $aow_field, $quicksearch_js); |
||
| 436 | |||
| 437 | echo $quicksearch_js; |
||
| 438 | |||
| 439 | if(isset($fieldlist[$fieldname]['module']) && $fieldlist[$fieldname]['module'] == 'Users'){ |
||
| 440 | $rel_value = get_assigned_user_name($value); |
||
| 441 | } else if(isset($fieldlist[$fieldname]['module'])){ |
||
| 442 | require_once($beanFiles[$beanList[$fieldlist[$fieldname]['module']]]); |
||
| 443 | $rel_focus = new $beanList[$fieldlist[$fieldname]['module']]; |
||
| 444 | $rel_focus->retrieve($value); |
||
| 445 | if(isset($fieldlist[$fieldname]['rname']) && $fieldlist[$fieldname]['rname'] != ''){ |
||
| 446 | $relDisplayField = $fieldlist[$fieldname]['rname']; |
||
| 447 | } else { |
||
| 448 | $relDisplayField = 'name'; |
||
| 449 | } |
||
| 450 | $rel_value = $rel_focus->$relDisplayField; |
||
| 451 | } |
||
| 452 | |||
| 453 | $fieldlist[$fieldlist[$fieldname]['id_name']]['value'] = $value; |
||
| 454 | $fieldlist[$fieldname]['value'] = $rel_value; |
||
| 455 | $fieldlist[$fieldname]['id_name'] = $aow_field; |
||
| 456 | $fieldlist[$fieldlist[$fieldname]['id_name']]['name'] = $aow_field; |
||
| 457 | $fieldlist[$fieldname]['name'] = $aow_field.'_display'; |
||
| 458 | } else if(isset( $fieldlist[$fieldname]['type'] ) && $view == 'DetailView' && ($fieldlist[$fieldname]['type'] == 'datetimecombo' || $fieldlist[$fieldname]['type'] == 'datetime' || $fieldlist[$fieldname]['type'] == 'date')){ |
||
| 459 | $value = $focus->convertField($value, $fieldlist[$fieldname]); |
||
| 460 | if(!empty($params['date_format']) && isset($params['date_format'])){ |
||
| 461 | $convert_format = "Y-m-d H:i:s"; |
||
| 462 | if($fieldlist[$fieldname]['type'] == 'date') $convert_format = "Y-m-d"; |
||
| 463 | $fieldlist[$fieldname]['value'] = $timedate->to_display($value, $convert_format, $params['date_format']); |
||
| 464 | }else{ |
||
| 465 | $fieldlist[$fieldname]['value'] = $timedate->to_display_date_time($value, true, true); |
||
| 466 | } |
||
| 467 | $fieldlist[$fieldname]['name'] = $aow_field; |
||
| 468 | } else if(isset( $fieldlist[$fieldname]['type'] ) && ($fieldlist[$fieldname]['type'] == 'datetimecombo' || $fieldlist[$fieldname]['type'] == 'datetime' || $fieldlist[$fieldname]['type'] == 'date')){ |
||
| 469 | $value = $focus->convertField($value, $fieldlist[$fieldname]); |
||
| 470 | $fieldlist[$fieldname]['value'] = $timedate->to_display_date($value); |
||
| 471 | //$fieldlist[$fieldname]['value'] = $timedate->to_display_date_time($value, true, true); |
||
| 472 | //$fieldlist[$fieldname]['value'] = $value; |
||
| 473 | $fieldlist[$fieldname]['name'] = $aow_field; |
||
| 474 | } else { |
||
| 475 | $fieldlist[$fieldname]['value'] = $value; |
||
| 476 | $fieldlist[$fieldname]['name'] = $aow_field; |
||
| 477 | |||
| 478 | } |
||
| 479 | |||
| 480 | if(isset($fieldlist[$fieldname]['type']) && $fieldlist[$fieldname]['type'] == 'currency' && $view != 'EditView'){ |
||
| 481 | static $sfh; |
||
| 482 | |||
| 483 | if(!isset($sfh)) { |
||
| 484 | require_once('include/SugarFields/SugarFieldHandler.php'); |
||
| 485 | $sfh = new SugarFieldHandler(); |
||
| 486 | } |
||
| 487 | |||
| 488 | if($currency_id != '' && !stripos($fieldname, '_USD')){ |
||
| 489 | $userCurrencyId = $current_user->getPreference('currency'); |
||
| 490 | if($currency_id != $userCurrencyId){ |
||
| 491 | $currency = new Currency(); |
||
| 492 | $currency->retrieve($currency_id); |
||
| 493 | $value = $currency->convertToDollar($value); |
||
| 494 | $currency->retrieve($userCurrencyId); |
||
| 495 | $value = $currency->convertFromDollar($value); |
||
| 496 | } |
||
| 497 | } |
||
| 498 | |||
| 499 | $parentfieldlist[strtoupper($fieldname)] = $value; |
||
| 500 | |||
| 501 | return($sfh->displaySmarty($parentfieldlist, $fieldlist[$fieldname], 'ListView', $displayParams)); |
||
| 502 | } |
||
| 503 | |||
| 504 | $ss->assign("QS_JS", $quicksearch_js); |
||
| 505 | $ss->assign("fields",$fieldlist); |
||
| 506 | $ss->assign("form_name",$view); |
||
| 507 | $ss->assign("bean",$focus); |
||
| 508 | |||
| 509 | // add in any additional strings |
||
| 510 | $ss->assign("MOD", $mod_strings); |
||
| 511 | $ss->assign("APP", $app_strings); |
||
| 512 | |||
| 513 | //$return = str_replace($fieldname,$ss->fetch($file)); |
||
| 514 | |||
| 515 | return $ss->fetch($file); |
||
| 516 | } |
||
| 517 | |||
| 829 | } |
This check looks for calls to
isset(...)orempty()on variables that are yet undefined. These calls will always produce the same result and can be removed.This is most likely caused by the renaming of a variable or the removal of a function/method parameter.