| Conditions | 29 |
| Paths | > 20000 |
| Total Lines | 242 |
| Code Lines | 176 |
| 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 |
||
| 148 | function modifyAd($lid): void |
||
| 149 | { |
||
| 150 | global $xoopsDB, $xoopsModule, $xoopsConfig, $myts; |
||
| 151 | $contactselect = ''; |
||
| 152 | require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||
| 153 | $helper = Helper::getInstance(); |
||
| 154 | $options = []; |
||
| 155 | $options['name'] = 'Editor'; |
||
| 156 | $options['value'] = _ADSLIGHT_DESC; |
||
| 157 | $options['rows'] = 10; |
||
| 158 | $options['cols'] = '100%'; |
||
| 159 | $options['width'] = '100%'; |
||
| 160 | $options['height'] = '200px'; |
||
| 161 | echo "<script language=\"javascript\">\nfunction CLA(CLA) { var MainWindow = window.open (CLA, \"_blank\",\"width=500,height=300,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no\");}\n</script>"; |
||
| 162 | |||
| 163 | $mytree = new Tree($xoopsDB->prefix('adslight_categories'), 'cid', 'pid'); |
||
| 164 | $sql = 'SELECT lid, cid, title, status, expire, type, desctext, tel, price, typeprice, typecondition, date_created, email, submitter, usid, town, country, contactby, premium, valid FROM ' . $xoopsDB->prefix( |
||
| 165 | 'adslight_listing' |
||
| 166 | ) . ' WHERE lid=' . $xoopsDB->escape( |
||
| 167 | $lid |
||
| 168 | ); |
||
| 169 | $result = $xoopsDB->query($sql); |
||
| 170 | [$lid, $cide, $title, $status, $expire, $type, $desctext, $tel, $price, $typeprice, $typecondition, $date_created, $email, $submitter, $usid, $town, $country, $contactby, $premium, $valid] = $xoopsDB->fetchRow( |
||
| 171 | $result |
||
| 172 | ); |
||
| 173 | $categories = Utility::getMyItemIds('adslight_submit'); |
||
| 174 | if (is_array($categories) && count($categories) > 0) { |
||
| 175 | if (!\in_array((int)$cide, $categories, true)) { |
||
| 176 | $helper->redirect('index.php', 3, _NOPERM); |
||
| 177 | } |
||
| 178 | } else { // User can't see any category |
||
| 179 | redirect_header(XOOPS_URL . '/index.php', 3, _NOPERM); |
||
| 180 | } |
||
| 181 | |||
| 182 | if ($GLOBALS['xoopsUser']) { |
||
| 183 | $calusern = $GLOBALS['xoopsUser']->uid(); |
||
| 184 | if ((int)$usid === $calusern) { |
||
| 185 | echo "<fieldset><legend style='font-weight: bold; color: #900;'>" . _ADSLIGHT_MODIFANN . '</legend><br><br>'; |
||
| 186 | $title = \htmlspecialchars($title, ENT_QUOTES | ENT_HTML5); |
||
| 187 | $status = \htmlspecialchars($status, ENT_QUOTES | ENT_HTML5); |
||
| 188 | $expire = \htmlspecialchars($expire, ENT_QUOTES | ENT_HTML5); |
||
| 189 | $type = \htmlspecialchars($type, ENT_QUOTES | ENT_HTML5); |
||
| 190 | $desctext = $myts->displayTarea($desctext, 1); |
||
| 191 | $tel = \htmlspecialchars($tel, ENT_QUOTES | ENT_HTML5); |
||
| 192 | |||
| 193 | // $price = number_format($price, 2, ',', ' '); |
||
| 194 | |||
| 195 | xoops_load('XoopsLocal'); |
||
| 196 | $tempXoopsLocal = new \XoopsLocal(); |
||
| 197 | // For US currency with 2 numbers after the decimal comment out if you don't want 2 numbers after decimal |
||
| 198 | $price = $tempXoopsLocal->number_format($price, 2, ',', ' '); |
||
|
|
|||
| 199 | // For other countries uncomment the below line and comment out the above line |
||
| 200 | // $price = $tempXoopsLocal->number_format($price); |
||
| 201 | |||
| 202 | $typeprice = \htmlspecialchars($typeprice, ENT_QUOTES | ENT_HTML5); |
||
| 203 | $typecondition = \htmlspecialchars($typecondition, ENT_QUOTES | ENT_HTML5); |
||
| 204 | $submitter = \htmlspecialchars($submitter, ENT_QUOTES | ENT_HTML5); |
||
| 205 | $town = \htmlspecialchars($town, ENT_QUOTES | ENT_HTML5); |
||
| 206 | $country = \htmlspecialchars($country, ENT_QUOTES | ENT_HTML5); |
||
| 207 | $contactby = \htmlspecialchars($contactby, ENT_QUOTES | ENT_HTML5); |
||
| 208 | $premium = \htmlspecialchars($premium, ENT_QUOTES | ENT_HTML5); |
||
| 209 | $useroffset = ''; |
||
| 210 | if ($GLOBALS['xoopsUser']) { |
||
| 211 | $timezone = $GLOBALS['xoopsUser']->timezone(); |
||
| 212 | $useroffset = empty($timezone) ? $xoopsConfig['default_TZ'] : $GLOBALS['xoopsUser']->timezone(); |
||
| 213 | } |
||
| 214 | $dates = formatTimestamp($date_created, 's'); |
||
| 215 | |||
| 216 | echo '<form action="modify.php" method=post enctype="multipart/form-data">'; |
||
| 217 | echo $GLOBALS['xoopsSecurity']->getTokenHTML(); |
||
| 218 | echo '<table><tr class="head" border="2"> |
||
| 219 | <td class="head">' . _ADSLIGHT_NUMANNN . " </td><td class=\"head\" border=\"1\">${lid} " . _ADSLIGHT_DU . " ${dates}</td> |
||
| 220 | </tr><tr>"; |
||
| 221 | if ('1' === $GLOBALS['xoopsModuleConfig']['adslight_diff_name']) { |
||
| 222 | echo '<td class="head">' . _ADSLIGHT_SENDBY . " </td><td class=\"head\"><input type=\"text\" name=\"submitter\" size=\"50\" value=\"${submitter}\" ></td>"; |
||
| 223 | } else { |
||
| 224 | echo '<td class="head">' . _ADSLIGHT_SENDBY . " </td><td class=\"head\"><input type=\"hidden\" name=\"submitter\" value=\"${submitter}\">${submitter}</td>"; |
||
| 225 | } |
||
| 226 | echo '</tr><tr>'; |
||
| 227 | if (1 === $contactby) { |
||
| 228 | $contactselect = _ADSLIGHT_CONTACT_BY_EMAIL; |
||
| 229 | } |
||
| 230 | if (2 === $contactby) { |
||
| 231 | $contactselect = _ADSLIGHT_CONTACT_BY_PM; |
||
| 232 | } |
||
| 233 | if (3 === $contactby) { |
||
| 234 | $contactselect = _ADSLIGHT_CONTACT_BY_BOTH; |
||
| 235 | } |
||
| 236 | if (4 === $contactby) { |
||
| 237 | $contactselect = _ADSLIGHT_CONTACT_BY_PHONE; |
||
| 238 | } |
||
| 239 | |||
| 240 | echo " <td class='head'>" . _ADSLIGHT_CONTACTBY . " </td><td class='head'><select name=\"contactby\"> |
||
| 241 | <option value=\"" . $contactby . '">' . $contactselect . '</option> |
||
| 242 | <option value="1">' . _ADSLIGHT_CONTACT_BY_EMAIL . '</option> |
||
| 243 | <option value="2">' . _ADSLIGHT_CONTACT_BY_PM . '</option> |
||
| 244 | <option value="3">' . _ADSLIGHT_CONTACT_BY_BOTH . '</option> |
||
| 245 | <option value="4">' . _ADSLIGHT_CONTACT_BY_PHONE . '</option></select></td></tr>'; |
||
| 246 | if ('1' === $GLOBALS['xoopsModuleConfig']['adslight_diff_email']) { |
||
| 247 | echo '<tr><td class="head">' . _ADSLIGHT_EMAIL . " </td><td class=\"head\"><input type=\"text\" name=\"email\" size=\"50\" value=\"${email}\" ></td>"; |
||
| 248 | } else { |
||
| 249 | echo '<tr><td class="head">' . _ADSLIGHT_EMAIL . " </td><td class=\"head\">${email}<input type=\"hidden\" name=\"email\" value=\"${email}\" ></td>"; |
||
| 250 | } |
||
| 251 | echo '</tr><tr> |
||
| 252 | <td class="head">' . _ADSLIGHT_TEL . " </td><td class=\"head\"><input type=\"text\" name=\"tel\" size=\"50\" value=\"${tel}\" ></td> |
||
| 253 | </tr>"; |
||
| 254 | echo '<tr> |
||
| 255 | <td class="head">' . _ADSLIGHT_TOWN . " </td><td class=\"head\"><input type=\"text\" name=\"town\" size=\"50\" value=\"${town}\" ></td> |
||
| 256 | </tr>"; |
||
| 257 | if ('1' === $GLOBALS['xoopsModuleConfig']['adslight_use_country']) { |
||
| 258 | echo '<tr> |
||
| 259 | <td class="head">' . _ADSLIGHT_COUNTRY . " </td><td class=\"head\"><input type=\"text\" name=\"country\" size=\"50\" value=\"${country}\" ></td> |
||
| 260 | </tr>"; |
||
| 261 | } else { |
||
| 262 | echo '<input type="hidden" name="country" value="">'; |
||
| 263 | } |
||
| 264 | |||
| 265 | echo "<tr><td class='head'>" . _ADSLIGHT_STATUS . "</td><td class='head'><input type=\"radio\" name=\"status\" value=\"0\""; |
||
| 266 | if (0 === (int)$status) { |
||
| 267 | echo 'checked'; |
||
| 268 | } |
||
| 269 | echo '>' . _ADSLIGHT_ACTIVE . ' <input type="radio" name="status" value="1"'; |
||
| 270 | if (1 === (int)$status) { |
||
| 271 | echo 'checked'; |
||
| 272 | } |
||
| 273 | echo '>' . _ADSLIGHT_INACTIVE . ' <input type="radio" name="status" value="2"'; |
||
| 274 | if (2 === (int)$status) { |
||
| 275 | echo 'checked'; |
||
| 276 | } |
||
| 277 | echo '>' . _ADSLIGHT_SOLD . '</td></tr>'; |
||
| 278 | echo '<tr> |
||
| 279 | <td class="head">' . _ADSLIGHT_TITLE2 . " </td><td class=\"head\"><input type=\"text\" name=\"title\" size=\"50\" value=\"${title}\" ></td> |
||
| 280 | </tr>"; |
||
| 281 | echo '<tr><td class="head">' . _ADSLIGHT_PRICE2 . " </td><td class=\"head\"><input type=\"text\" name=\"price\" size=\"20\" value=\"${price}\" > " . $GLOBALS['xoopsModuleConfig']['adslight_currency_symbol']; |
||
| 282 | |||
| 283 | $sql = 'SELECT nom_price, id_price FROM ' . $xoopsDB->prefix('adslight_price') . ' ORDER BY id_price'; |
||
| 284 | $result3 = $xoopsDB->query($sql); |
||
| 285 | echo ' <select name="typeprice">'; |
||
| 286 | while ([$nom_price, $id_price] = $xoopsDB->fetchRow($result3)) { |
||
| 287 | $sel = ''; |
||
| 288 | if ($id_price === $typeprice) { |
||
| 289 | $sel = 'selected'; |
||
| 290 | } |
||
| 291 | echo "<option value=\"${id_price}\" ${sel}>${nom_price}</option>"; |
||
| 292 | } |
||
| 293 | echo '</select></td></tr>'; |
||
| 294 | $moduleId = $xoopsModule->getVar('mid'); |
||
| 295 | $groups = $GLOBALS['xoopsUser'] instanceof \XoopsUser ? $GLOBALS['xoopsUser']->getGroups() : XOOPS_GROUP_ANONYMOUS; |
||
| 296 | /** @var \XoopsGroupPermHandler $grouppermHandler */ |
||
| 297 | $grouppermHandler = xoops_getHandler('groupperm'); |
||
| 298 | $perm_itemid = Request::getInt('item_id', 0, 'GET'); |
||
| 299 | |||
| 300 | //If no access |
||
| 301 | if ($grouppermHandler->checkRight('adslight_premium', $perm_itemid, $groups, $moduleId)) { |
||
| 302 | echo "<tr> |
||
| 303 | <td width='30%' class='head'>" . _ADSLIGHT_HOW_LONG . " </td><td class='head'><input type=\"text\" name=\"expire\" size=\"3\" maxlength=\"3\" value=\"${expire}\" > " . _ADSLIGHT_DAY . '</td> |
||
| 304 | </tr>'; |
||
| 305 | } else { |
||
| 306 | echo "<tr> |
||
| 307 | <td width='30%' class='head'>" . _ADSLIGHT_WILL_LAST . " </td><td class='head'>${expire} " . _ADSLIGHT_DAY . '</td> |
||
| 308 | </tr>'; |
||
| 309 | echo "<input type=\"hidden\" name=\"expire\" value=\"${expire}\" >"; |
||
| 310 | } |
||
| 311 | |||
| 312 | /// Type d'annonce |
||
| 313 | echo '<tr> |
||
| 314 | <td class="head">' . _ADSLIGHT_TYPE . ' </td><td class="head"><select name="type">'; |
||
| 315 | |||
| 316 | $sql = 'SELECT nom_type, id_type FROM ' . $xoopsDB->prefix('adslight_type') . ' ORDER BY nom_type'; |
||
| 317 | $result5 = $xoopsDB->query($sql); |
||
| 318 | while ([$nom_type, $id_type] = $xoopsDB->fetchRow($result5)) { |
||
| 319 | $sel = ''; |
||
| 320 | if ($id_type === $type) { |
||
| 321 | $sel = 'selected'; |
||
| 322 | } |
||
| 323 | echo "<option value=\"${id_type}\" ${sel}>${nom_type}</option>"; |
||
| 324 | } |
||
| 325 | echo '</select></td></tr>'; |
||
| 326 | |||
| 327 | /// Etat de l'objet |
||
| 328 | echo '<tr> |
||
| 329 | <td class="head">' . _ADSLIGHT_TYPE_CONDITION . ' </td><td class="head"><select name="typecondition">'; |
||
| 330 | |||
| 331 | $sql = 'SELECT nom_condition, id_condition FROM ' . $xoopsDB->prefix('adslight_condition') . ' ORDER BY nom_condition'; |
||
| 332 | $result6 = $xoopsDB->query($sql); |
||
| 333 | while ([$nom_condition, $id_condition] = $xoopsDB->fetchRow($result6)) { |
||
| 334 | $sel = ''; |
||
| 335 | if ($id_condition === $typecondition) { |
||
| 336 | $sel = 'selected'; |
||
| 337 | } |
||
| 338 | echo "<option value=\"${id_condition}\" ${sel}>${nom_condition}</option>"; |
||
| 339 | } |
||
| 340 | echo '</select></td></tr>'; |
||
| 341 | |||
| 342 | echo '<tr> |
||
| 343 | <td class="head">' . _ADSLIGHT_CAT . ' </td><td class="head">'; |
||
| 344 | $mytree->makeMySelBox('title', 'title', $cide, 0, 'cid'); |
||
| 345 | echo '</td> |
||
| 346 | </tr><tr> |
||
| 347 | <td class="head">' . _ADSLIGHT_DESC . ' </td><td class="head">'; |
||
| 348 | // $wysiwyg_text_area = Utility::getEditor(_ADSLIGHT_DESC, 'desctext', $desctext, '100%', '200px'); |
||
| 349 | |||
| 350 | // $desctext = $myts->displayTarea($desctext, 1); |
||
| 351 | |||
| 352 | $options = []; |
||
| 353 | $options['name'] = _ADSLIGHT_DESC; |
||
| 354 | $options['value'] = $desctext; |
||
| 355 | $options['rows'] = 10; |
||
| 356 | $options['cols'] = '100%'; |
||
| 357 | $options['width'] = '100%'; |
||
| 358 | $options['height'] = '400px'; |
||
| 359 | |||
| 360 | $wysiwyg_text_area = Utility::getEditor($helper, $options); |
||
| 361 | echo $wysiwyg_text_area->render(); |
||
| 362 | echo '</td></tr> |
||
| 363 | <td colspan=2><br><input type="submit" value="' . _ADSLIGHT_MODIFANN . '" ></td> |
||
| 364 | </tr></table>'; |
||
| 365 | echo '<input type="hidden" name="op" value="modads" >'; |
||
| 366 | |||
| 367 | $moduleId = $xoopsModule->getVar('mid'); |
||
| 368 | if (is_object($GLOBALS['xoopsUser'])) { |
||
| 369 | $groups = &$GLOBALS['xoopsUser']->getGroups(); |
||
| 370 | } else { |
||
| 371 | $groups = XOOPS_GROUP_ANONYMOUS; |
||
| 372 | } |
||
| 373 | /** @var \XoopsGroupPermHandler $grouppermHandler */ |
||
| 374 | $grouppermHandler = xoops_getHandler('groupperm'); |
||
| 375 | $perm_itemid = Request::getInt('item_id', 0, 'POST'); |
||
| 376 | //If no access |
||
| 377 | if ($grouppermHandler->checkRight('adslight_premium', $perm_itemid, $groups, $moduleId)) { |
||
| 378 | echo '<input type="hidden" name="valid" value="Yes" >'; |
||
| 379 | } elseif ('1' === $GLOBALS['xoopsModuleConfig']['adslight_moderated']) { |
||
| 380 | echo '<input type="hidden" name="valid" value="No" >'; |
||
| 381 | echo '<br>' . _ADSLIGHT_MODIFBEFORE . '<br>'; |
||
| 382 | } else { |
||
| 383 | echo '<input type="hidden" name="valid" value="Yes" >'; |
||
| 384 | } |
||
| 385 | echo "<input type=\"hidden\" name=\"lid\" value=\"${lid}\" >"; |
||
| 386 | echo "<input type=\"hidden\" name=\"premium\" value=\"${premium}\" >"; |
||
| 387 | echo "<input type=\"hidden\" name=\"date_created\" value=\"${date_created}\" > |
||
| 388 | " . $GLOBALS['xoopsSecurity']->getTokenHTML() . ''; |
||
| 389 | echo '</form><br></fieldset><br>'; |
||
| 390 | } |
||
| 530 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.