Conditions | 15 |
Paths | 3457 |
Total Lines | 171 |
Code Lines | 109 |
Lines | 171 |
Ratio | 100 % |
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 |
||
122 | View Code Duplication | function modifyAds($lid) |
|
1 ignored issue
–
show
|
|||
123 | { |
||
124 | global $xoopsDB, $xoopsModule, $xoopsConfig, $myts, $desctext, $moduleDirName, $admin_lang; |
||
1 ignored issue
–
show
|
|||
125 | |||
126 | $mytree = new ClassifiedsTree($xoopsDB->prefix('adslight_categories'), 'cid', 'pid'); |
||
127 | |||
128 | include_once __DIR__ . '/header.php'; |
||
129 | xoops_cp_header(); |
||
130 | // loadModuleAdminMenu(0, ""); |
||
131 | $id_price = ''; |
||
132 | $nom_price = ''; |
||
133 | $lid = (int)$lid; |
||
134 | |||
135 | echo "<fieldset><legend style='font-weight: bold; color: #900;'>" . _AM_ADSLIGHT_MODANN . '</legend>'; |
||
136 | |||
137 | $result = $xoopsDB->query('SELECT lid, cid, title, status, expire, type, desctext, tel, price, typeprice, typeusure, date, email, submitter, town, country, contactby, premium, valid, photo FROM ' |
||
138 | . $xoopsDB->prefix('adslight_listing') |
||
139 | . " WHERE lid=$lid"); |
||
140 | |||
141 | while (list($lid, $cid, $title, $status, $expire, $type, $desctext, $tel, $price, $typeprice, $typeusure, $date, $email, $submitter, $town, $country, $contactby, $premium, $valid, $photo) = $xoopsDB->fetchRow($result)) { |
||
142 | $title = $myts->htmlSpecialChars($title); |
||
143 | $status = $myts->htmlSpecialChars($status); |
||
144 | $expire = $myts->htmlSpecialChars($expire); |
||
145 | $type = $myts->htmlSpecialChars($type); |
||
146 | $desctext = $myts->displayTarea($desctext, 1, 1, 1); |
||
147 | $tel = $myts->htmlSpecialChars($tel); |
||
148 | $price = number_format($price, 2, ',', ' '); |
||
149 | $typeprice = $myts->htmlSpecialChars($typeprice); |
||
150 | $typeusure = $myts->htmlSpecialChars($typeusure); |
||
151 | $submitter = $myts->htmlSpecialChars($submitter); |
||
152 | $town = $myts->htmlSpecialChars($town); |
||
153 | $country = $myts->htmlSpecialChars($country); |
||
154 | $contactby = $myts->htmlSpecialChars($contactby); |
||
155 | $premium = $myts->htmlSpecialChars($premium); |
||
156 | |||
157 | $date2 = formatTimestamp($date, 's'); |
||
158 | |||
159 | echo "<form action=\"modify_ads.php\" method=post> |
||
160 | <table border=0><tr class='head' border='1'> |
||
161 | <td>" . _AM_ADSLIGHT_NUMANN . " </td><td>$lid " . _AM_ADSLIGHT_ADDED_ON . " $date2</td> |
||
162 | </tr><tr class='head' border='1'> |
||
163 | <td>" . _AM_ADSLIGHT_SENDBY . " </td><td>$submitter</td> |
||
164 | </tr><tr class='head' border='1'> |
||
165 | <td>" . _AM_ADSLIGHT_EMAIL . " </td><td><input type=\"text\" name=\"email\" size=\"40\" value=\"$email\"></td> |
||
166 | </tr><tr class='head' border='1'> |
||
167 | <td>" . _AM_ADSLIGHT_TEL . " </td><td><input type=\"text\" name=\"tel\" size=\"50\" value=\"$tel\"></td> |
||
168 | </tr><tr class='head' border='1'> |
||
169 | <td>" . _AM_ADSLIGHT_TOWN . " </td><td><input type=\"text\" name=\"town\" size=\"40\" value=\"$town\"></td> |
||
170 | </tr><tr class='head' border='1'> |
||
171 | <td>" . _AM_ADSLIGHT_COUNTRY . " </td><td><input type=\"text\" name=\"country\" size=\"40\" value=\"$country\"></td> |
||
172 | </tr></tr><tr class='head' border='1'>"; |
||
173 | |||
174 | if ($contactby == 1) { |
||
175 | $contactselect = _AM_ADSLIGHT_CONTACT_BY_EMAIL; |
||
176 | } |
||
177 | if ($contactby == 2) { |
||
178 | $contactselect = _AM_ADSLIGHT_CONTACT_BY_PM; |
||
179 | } |
||
180 | if ($contactby == 3) { |
||
181 | $contactselect = _AM_ADSLIGHT_CONTACT_BY_BOTH; |
||
182 | } |
||
183 | if ($contactby == 4) { |
||
184 | $contactselect = _AM_ADSLIGHT_CONTACT_BY_PHONE; |
||
185 | } |
||
186 | |||
187 | echo " <td class='head'>" . _AM_ADSLIGHT_CONTACTBY . " </td><td class='head'><select name=\"contactby\"> |
||
188 | <option value=\"" . $contactby . "\">" . $contactselect . "</option> |
||
189 | <option value=\"1\">" . _AM_ADSLIGHT_CONTACT_BY_EMAIL . "</option> |
||
190 | <option value=\"2\">" . _AM_ADSLIGHT_CONTACT_BY_PM . "</option> |
||
191 | <option value=\"3\">" . _AM_ADSLIGHT_CONTACT_BY_BOTH . "</option> |
||
192 | <option value=\"4\">" . _AM_ADSLIGHT_CONTACT_BY_PHONE . '</option></select></td></tr>'; |
||
193 | |||
194 | echo "<tr><td class='head'>" . _AM_ADSLIGHT_STATUS . "</td><td class='head'><input type=\"radio\" name=\"status\" value=\"0\""; |
||
195 | if ($status == '0') { |
||
196 | echo 'checked'; |
||
197 | } |
||
198 | echo '>' . _AM_ADSLIGHT_ACTIVE . " <input type=\"radio\" name=\"status\" value=\"1\""; |
||
199 | if ($status == '1') { |
||
200 | echo 'checked'; |
||
201 | } |
||
202 | echo '>' . _AM_ADSLIGHT_INACTIVE . " <input type=\"radio\" name=\"status\" value=\"2\""; |
||
203 | if ($status == '2') { |
||
204 | echo 'checked'; |
||
205 | } |
||
206 | echo '>' . _AM_ADSLIGHT_SOLD . '</td></tr>'; |
||
207 | |||
208 | echo "<tr class='head' border='1'> |
||
209 | <td>" . _AM_ADSLIGHT_TITLE2 . " </td><td><input type=\"text\" name=\"title\" size=\"40\" value=\"$title\"></td> |
||
210 | </tr><tr class='head' border='1'> |
||
211 | <td>" . _AM_ADSLIGHT_PREMIUM . " </td><td><input type=\"text\" name=\"premium\" size=\"3\" value=\"$premium\"></td> |
||
212 | </tr><tr class='head' border='1'> |
||
213 | <td>" . _AM_ADSLIGHT_EXPIRE . " </td><td><input type=\"text\" name=\"expire\" size=\"40\" value=\"$expire\"></td> |
||
214 | </tr>"; |
||
215 | ////// Type d'annonce |
||
216 | echo "<tr class='head' border='1'> |
||
217 | <td>" . _AM_ADSLIGHT_TYPE . " </td><td><select name=\"type\">"; |
||
218 | |||
219 | $result5 = $xoopsDB->query('SELECT nom_type, id_type FROM ' . $xoopsDB->prefix('adslight_type') . ' ORDER BY nom_type'); |
||
220 | while (list($nom_type, $id_type) = $xoopsDB->fetchRow($result5)) { |
||
221 | $sel = ''; |
||
222 | if ($id_type == $type) { |
||
223 | $sel = 'selected'; |
||
224 | } |
||
225 | echo "<option value=\"{$id_type}\"{$sel}>{$nom_type}</option>"; |
||
226 | } |
||
227 | echo '</select></td></tr>'; |
||
228 | |||
229 | ////// Etat d'usure |
||
230 | echo "<tr class='head' border='1'> |
||
231 | <td>" . _AM_ADSLIGHT_TYPE_USURE . " </td><td><select name=\"typeusure\">"; |
||
232 | |||
233 | $result6 = $xoopsDB->query('SELECT nom_usure, id_usure FROM ' . $xoopsDB->prefix('adslight_usure') . ' ORDER BY nom_usure'); |
||
234 | while (list($nom_usure, $id_usure) = $xoopsDB->fetchRow($result6)) { |
||
235 | $sel = ''; |
||
236 | if ($id_usure == $typeusure) { |
||
237 | $sel = 'selected'; |
||
238 | } |
||
239 | echo "<option value=\"{$id_usure}\"{$sel}>{$nom_usure}</option>"; |
||
240 | } |
||
241 | echo '</select></td></tr>'; |
||
242 | |||
243 | /////// Price |
||
244 | echo "<tr class='head' border='1'><td>" . _AM_ADSLIGHT_PRICE2 . " </td><td><input type=\"text\" name=\"price\" size=\"20\" value=\"$price\"> " . $GLOBALS['xoopsModuleConfig']['adslight_money'] . ''; |
||
245 | |||
246 | //////// Price type |
||
247 | |||
248 | $resultx = $xoopsDB->query('SELECT nom_price, id_price FROM ' . $xoopsDB->prefix('adslight_price') . ' ORDER BY nom_price'); |
||
249 | |||
250 | echo " <select name=\"typeprice\"><option value=\"$id_price\">$nom_price</option>"; |
||
251 | while (list($nom_price, $id_price) = $xoopsDB->fetchRow($resultx)) { |
||
252 | $sel = ''; |
||
253 | if ($id_price == $typeprice) { |
||
254 | $sel = 'selected'; |
||
255 | } |
||
256 | echo "<option value=\"{$id_price}\"{$sel}>{$nom_price}</option>"; |
||
257 | } |
||
258 | echo '</select></td>'; |
||
259 | |||
260 | /////// Category |
||
261 | |||
262 | echo "<tr class='head' border='1'> |
||
263 | <td>" . _AM_ADSLIGHT_CAT2 . ' </td><td>'; |
||
264 | $mytree->makeMySelBox('title', 'title', $cid); |
||
265 | echo "</td> |
||
266 | </tr><tr class='head' border='1'> |
||
267 | <td>" . _AM_ADSLIGHT_DESC . ' </td><td>'; |
||
268 | |||
269 | $wysiwyg_text_area = AdslightUtilities::getEditor('', 'desctext', $desctext, '100%', '200px', 'small'); |
||
270 | echo $wysiwyg_text_area->render(); |
||
271 | |||
272 | echo '</td></tr>'; |
||
273 | |||
274 | echo "<tr class='head' border='1'> |
||
275 | <td>" . _AM_ADSLIGHT_PHOTO1 . " </td><td><input type=\"text\" name=\"photo\" size=\"50\" value=\"$photo\"></td> |
||
276 | </tr><tr>"; |
||
277 | $time = time(); |
||
278 | echo "</tr><tr class='head' border='1'> |
||
279 | <td> </td><td><select name=\"op\"> |
||
280 | <option value=\"ModifyAdsS\"> " . _AM_ADSLIGHT_MODIF . " |
||
281 | <option value=\"ListingDel\"> " . _AM_ADSLIGHT_DEL . " |
||
282 | </select><input type=\"submit\" value=\"" . _AM_ADSLIGHT_GO . "\"></td> |
||
283 | </tr></table>"; |
||
284 | echo "<input type=\"hidden\" name=\"valid\" value=\"Yes\">"; |
||
285 | echo "<input type=\"hidden\" name=\"lid\" value=\"$lid\">"; |
||
286 | echo "<input type=\"hidden\" name=\"date\" value=\"$time\">"; |
||
287 | echo "<input type=\"hidden\" name=\"submitter\" value=\"$submitter\"> |
||
288 | </form><br>"; |
||
289 | echo '</fieldset><br>'; |
||
290 | xoops_cp_footer(); |
||
291 | } |
||
292 | } |
||
293 | |||
443 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.