Conditions | 7 |
Paths | 48 |
Total Lines | 62 |
Code Lines | 54 |
Lines | 21 |
Ratio | 33.87 % |
Changes | 3 | ||
Bugs | 0 | Features | 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 |
||
110 | function b_tdmdownloads_top_edit($options) |
||
111 | { |
||
112 | //appel de la class |
||
113 | $downloadscat_Handler =& xoops_getModuleHandler('tdmdownloads_cat', 'TDMDownloads'); |
||
114 | $criteria = new CriteriaCompo(); |
||
115 | $criteria = new CriteriaCompo(); |
||
116 | $criteria->setSort('cat_weight ASC, cat_title'); |
||
117 | $criteria->setOrder('ASC'); |
||
118 | $downloadscat_arr = $downloadscat_Handler->getall($criteria); |
||
119 | $form = _MB_TDMDOWNLOADS_DISP . " \n"; |
||
120 | $form .= "<input type=\"hidden\" name=\"options[0]\" value=\"" . $options[0] . "\" />\n"; |
||
121 | $form .= "<input name=\"options[1]\" size=\"5\" maxlength=\"255\" value=\"" . $options[1] . "\" type=\"text\" /> " . _MB_TDMDOWNLOADS_FILES . "<br />\n"; |
||
122 | $form .= _MB_TDMDOWNLOADS_CHARS . " : <input name=\"options[2]\" size=\"5\" maxlength=\"255\" value=\"" . $options[2] . "\" type=\"text\" /><br />\n"; |
||
123 | View Code Duplication | if ($options[3] == false) { |
|
124 | $checked_yes = ''; |
||
125 | $checked_no = 'checked="checked"'; |
||
126 | } else { |
||
127 | $checked_yes = 'checked="checked"'; |
||
128 | $checked_no = ''; |
||
129 | } |
||
130 | $form .= _MB_TDMDOWNLOADS_LOGO . " : <input name=\"options[3]\" value=\"1\" type=\"radio\" " . $checked_yes . "/>" . _YES . " \n"; |
||
131 | $form .= "<input name=\"options[3]\" value=\"0\" type=\"radio\" " . $checked_no . "/>" . _NO . "<br />\n"; |
||
132 | View Code Duplication | if ($options[4] == false) { |
|
133 | $checked_yes = ''; |
||
134 | $checked_no = 'checked="checked"'; |
||
135 | } else { |
||
136 | $checked_yes = 'checked="checked"'; |
||
137 | $checked_no = ''; |
||
138 | } |
||
139 | $form .= _MB_TDMDOWNLOADS_DESCRIPTION . " : <input name=\"options[4]\" value=\"1\" type=\"radio\" " . $checked_yes . "/>" . _YES . " \n"; |
||
140 | $form .= "<input name=\"options[4]\" value=\"0\" type=\"radio\" " . $checked_no . "/>" . _NO . "<br />\n"; |
||
141 | View Code Duplication | if ($options[5] == false) { |
|
142 | $checked_yes = ''; |
||
143 | $checked_no = 'checked="checked"'; |
||
144 | } else { |
||
145 | $checked_yes = 'checked="checked"'; |
||
146 | $checked_no = ''; |
||
147 | } |
||
148 | $form .= _MB_TDMDOWNLOADS_INFORMATIONS . " : <input name=\"options[5]\" value=\"1\" type=\"radio\" " . $checked_yes . "/>" . _YES . " \n"; |
||
149 | $form .= "<input name=\"options[5]\" value=\"0\" type=\"radio\" " . $checked_no . "/>" . _NO . "<br /><br />\n"; |
||
150 | $floatelect = new XoopsFormSelect(_MB_TDMDOWNLOADS_FLOAT, 'options[6]',$options[6]); |
||
151 | $floatelect->addOption("left", _MB_TDMDOWNLOADS_FLOAT_LEFT); |
||
152 | $floatelect->addOption("right", _MB_TDMDOWNLOADS_FLOAT_RIGHT); |
||
153 | $form .= _MB_TDMDOWNLOADS_FLOAT." : ".$floatelect->render().'<br />'; |
||
154 | $form .= _MB_TDMDOWNLOADS_WHITE . " : <input name=\"options[7]\" size=\"5\" maxlength=\"255\" value=\"" . $options[7] . "\" type=\"text\" /><br />\n"; |
||
155 | array_shift($options); |
||
156 | array_shift($options); |
||
157 | array_shift($options); |
||
158 | array_shift($options); |
||
159 | array_shift($options); |
||
160 | array_shift($options); |
||
161 | array_shift($options); |
||
162 | array_shift($options); |
||
163 | $form .= _MB_TDMDOWNLOADS_CATTODISPLAY . "<br /><select name=\"options[]\" multiple=\"multiple\" size=\"5\">\n"; |
||
164 | $form .= "<option value=\"0\" " . (array_search(0, $options) === false ? '' : 'selected="selected"') . ">" . _MB_TDMDOWNLOADS_ALLCAT . "</option>\n"; |
||
165 | foreach (array_keys($downloadscat_arr) as $i) { |
||
166 | $form .= "<option value=\"" . $downloadscat_arr[$i]->getVar('cat_cid') . "\" " . (array_search($downloadscat_arr[$i]->getVar('cat_cid'), $options) === false ? '' : 'selected="selected"') . ">".$downloadscat_arr[$i]->getVar('cat_title')."</option>\n"; |
||
167 | } |
||
168 | $form .= "</select>\n"; |
||
169 | |||
170 | return $form; |
||
171 | } |
||
172 |
Instead of relying on
global
state, we recommend one of these alternatives:1. Pass all data via parameters
2. Create a class that maintains your state