| Conditions | 4 |
| Paths | 6 |
| Total Lines | 69 |
| Code Lines | 60 |
| 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 declare(strict_types=1); |
||
| 100 | function mailAd($lid, $yname, $ymail, $fname, $fmail): void |
||
| 101 | { |
||
| 102 | global $xoopsConfig, $xoopsTpl, $xoopsDB, $xoopsModule, $myts; |
||
| 103 | $helper = Helper::getInstance(); |
||
| 104 | |||
| 105 | if ('1' === $helper->getConfig('adslight_use_captcha')) { |
||
| 106 | xoops_load('xoopscaptcha'); |
||
| 107 | $xoopsCaptcha = XoopsCaptcha::getInstance(); |
||
| 108 | $helper = Helper::getInstance(); |
||
| 109 | if (!$xoopsCaptcha->verify()) { |
||
| 110 | $helper->redirect('index.php', 2, $xoopsCaptcha->getMessage()); |
||
| 111 | } |
||
| 112 | } |
||
| 113 | |||
| 114 | $sql = 'SELECT lid, title, expire, type, desctext, tel, price, typeprice, date_created, email, submitter, town, country, photo FROM ' . $xoopsDB->prefix('adslight_listing') . ' WHERE lid=' . $xoopsDB->escape($lid); |
||
| 115 | $result = $xoopsDB->query($sql); |
||
| 116 | if (!$xoopsDB->isResultSet($result)) { |
||
| 117 | \trigger_error("Query Failed! SQL: $sql- Error: " . $xoopsDB->error(), E_USER_ERROR); |
||
| 118 | } |
||
| 119 | [$lid, $title, $expire, $type, $desctext, $tel, $price, $typeprice, $date_created, $email, $submitter, $town, $country, $photo] = $xoopsDB->fetchRow($result); |
||
| 120 | |||
| 121 | $title = $GLOBALS['xoopsDB']->escape($title); |
||
| 122 | $expire = $GLOBALS['xoopsDB']->escape($expire); |
||
| 123 | $type = $GLOBALS['xoopsDB']->escape($type); |
||
| 124 | $desctext = $myts->displayTarea($desctext, 1, 1, 1, 1, 1); |
||
| 125 | $tel = $GLOBALS['xoopsDB']->escape($tel); |
||
| 126 | $price = $GLOBALS['xoopsDB']->escape($price); |
||
| 127 | $typeprice = $GLOBALS['xoopsDB']->escape($typeprice); |
||
| 128 | $submitter = $GLOBALS['xoopsDB']->escape($submitter); |
||
| 129 | $town = $GLOBALS['xoopsDB']->escape($town); |
||
| 130 | $country = $GLOBALS['xoopsDB']->escape($country); |
||
| 131 | |||
| 132 | $tags = []; |
||
| 133 | $tags['YNAME'] = stripslashes($yname); |
||
| 134 | $tags['YMAIL'] = $ymail; |
||
| 135 | $tags['FNAME'] = stripslashes($fname); |
||
| 136 | $tags['FMAIL'] = $fmail; |
||
| 137 | $tags['HELLO'] = _ADSLIGHT_HELLO; |
||
| 138 | $tags['LID'] = $lid; |
||
| 139 | $tags['LISTING_NUMBER'] = _ADSLIGHT_LISTING_NUMBER; |
||
| 140 | $tags['TITLE'] = $title; |
||
| 141 | $tags['TYPE'] = Utility::getNameType($type); |
||
| 142 | $tags['DESCTEXT'] = $desctext; |
||
| 143 | $tags['PRICE'] = $price; |
||
| 144 | $tags['TYPEPRICE'] = $typeprice; |
||
| 145 | $tags['TEL'] = $tel; |
||
| 146 | $tags['TOWN'] = $town; |
||
| 147 | $tags['COUNTRY'] = $country; |
||
| 148 | $tags['OTHER'] = _ADSLIGHT_INTERESS . $xoopsConfig['sitename']; |
||
| 149 | $tags['LISTINGS'] = XOOPS_URL . '/modules/adslight/'; |
||
| 150 | $tags['LINK_URL'] = XOOPS_URL . '/modules/adslight/viewads.php?lid=' . $lid; |
||
| 151 | $tags['THINKS_INTERESTING'] = _ADSLIGHT_MESSAGE; |
||
| 152 | $tags['NO_MAIL'] = _ADSLIGHT_NOMAIL; |
||
| 153 | $tags['YOU_CAN_VIEW_BELOW'] = _ADSLIGHT_YOU_CAN_VIEW_BELOW; |
||
| 154 | $tags['WEBMASTER'] = _ADSLIGHT_WEBMASTER; |
||
| 155 | $tags['NO_REPLY'] = _ADSLIGHT_NOREPLY; |
||
| 156 | $subject = _ADSLIGHT_SUBJET . ' ' . $xoopsConfig['sitename']; |
||
| 157 | $xoopsMailer = xoops_getMailer(); |
||
| 158 | $xoopsMailer->multimailer->isHTML(true); |
||
| 159 | $xoopsMailer->useMail(); |
||
| 160 | $xoopsMailer->setTemplateDir(XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/mail_template/'); |
||
| 161 | $xoopsMailer->setTemplate('listing_send_friend.tpl'); |
||
| 162 | $xoopsMailer->setFromEmail($ymail); |
||
| 163 | $xoopsMailer->setToEmails($fmail); |
||
| 164 | $xoopsMailer->setSubject($subject); |
||
| 165 | $xoopsMailer->assign($tags); |
||
| 166 | $xoopsMailer->send(); |
||
| 167 | echo $xoopsMailer->getErrors(); |
||
| 168 | $helper->redirect('index.php', 3, _ADSLIGHT_ANNSEND); |
||
| 169 | } |
||
| 193 |