| Conditions | 3 |
| Paths | 4 |
| Total Lines | 65 |
| Code Lines | 43 |
| 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 |
||
| 77 | function update_lg() |
||
| 78 | { |
||
| 79 | global $xoopsDB; |
||
| 80 | |||
| 81 | // $moduleDirName = basename ( dirname( __DIR__ ) ) ; |
||
| 82 | |||
| 83 | if (defined('_AD_XDONATION_DONATIONS')) { |
||
| 84 | $prefixV = '_AD_XDONATION_V_'; |
||
| 85 | $prefixT = '_AD_XDONATION_T_'; |
||
| 86 | } else { |
||
| 87 | $prefixV = '_MI_XDONATION_V_'; |
||
| 88 | $prefixT = '_MI_XDONATION_T_'; |
||
| 89 | } |
||
| 90 | |||
| 91 | $lstName = 'receiver_email_;paypal_url_array;use_goal_array;' |
||
| 92 | . 'week_goal_1st;week_goal_2nd;week_goal_3rd;week_goal_4th;' |
||
| 93 | . 'month_goal_Jan;month_goal_Feb;month_goal_Mar;month_goal_Apr;' |
||
| 94 | . 'month_goal_May;month_goal_Jun;month_goal_Jul;' |
||
| 95 | . 'month_goal_Aug;month_goal_Sep;month_goal_Oct;' |
||
| 96 | . 'month_goal_Nov;month_goal_Dec;quarter_goal_1st;quarter_goal_2nd;' |
||
| 97 | . 'quarter_goal_3rd;quarter_goal_4th;swing_day_;ty_url_;' |
||
| 98 | . 'pp_itemname_;don_button_submit_;don_button_top_;pp_image_url_;' |
||
| 99 | . 'pp_cancel_url_;pp_get_addr_;pp_curr_code_array;don_amount_1;' |
||
| 100 | . 'don_amount_2;don_amount_3;don_amount_4;don_amount_5;' |
||
| 101 | . 'don_amount_6;don_amount_7;don_amt_checked_;pp_item_num_;' |
||
| 102 | . 'don_top_img_width_;don_top_img_height_;don_sub_img_width_;' |
||
| 103 | . 'don_sub_img_height_;don_text_rawtext;don_name_prompt_;' |
||
| 104 | . 'don_name_yes_;don_name_no_;don_forceadd_;ipn_dbg_lvl_;ipn_log_entries_;' |
||
| 105 | . 'assign_group_;assign_rank_'; |
||
| 106 | |||
| 107 | $table = $xoopsDB->prefix('donations_config'); |
||
| 108 | $sql0 = "INSERT INTO `{$table}` (`name`, `subtype`, `value`, `text`) " . "VALUES ('%1\$s', '%2\$s', '%3\$s', '%4\$s')"; |
||
| 109 | |||
| 110 | $sql = "DELETE FROM {$table}"; |
||
| 111 | $xoopsDB->queryF($sql); |
||
| 112 | //echo "{$sql}<br>"; |
||
| 113 | $t = explode(';', $lstName); |
||
| 114 | |||
| 115 | for ($h = 0, $hMax = count($t); $h < $hMax; ++$h) { |
||
| 116 | //echo "<hr>{$t[$h]}<br>"; |
||
| 117 | $tc = explode('_', $t[$h]); |
||
| 118 | //echo "<hr>{$t[$h]}-".count($tc)."-".count($tn)."<br>"; |
||
| 119 | |||
| 120 | //$tc = array_shift($tc); |
||
| 121 | $subType = $tc[count($tc) - 1]; |
||
| 122 | |||
| 123 | $cstV = $prefixV . $t[$h]; |
||
| 124 | $cstT = $prefixT . $t[$h]; |
||
| 125 | |||
| 126 | //$tc = array_shift($tc); |
||
| 127 | $tn = array_pop($tc); |
||
| 128 | $tn = $tc; |
||
| 129 | $name = implode('_', $tn); |
||
| 130 | //echo "{$t[$h]}-".count($tc)."-".count($tn)."-{$tc[0]}-{$tn[0]}-{$name}<br>"; |
||
| 131 | |||
| 132 | $value = constant($cstV); |
||
| 133 | $text = constant($cstT); |
||
| 134 | $text = str_replace("'", "\'", $text); |
||
| 135 | $text = html_entity_decode($text); |
||
| 136 | $text = str_replace('<br>', "\r\n", $text); |
||
| 137 | $text = str_replace('<br>', "\r\n", $text); |
||
| 138 | |||
| 139 | $sql = sprintf($sql0, $name, $subType, $value, $text); |
||
| 140 | // echo "{$sql}<br>"; |
||
| 141 | $xoopsDB->queryF($sql); |
||
| 142 | } |
||
| 167 |