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