| Conditions | 8 |
| Paths | 14 |
| Total Lines | 140 |
| Lines | 4 |
| Ratio | 2.86 % |
| 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 namespace Xoopsmodules\Smallworld; |
||
| 50 | public function sendMails($fromUserID, $toUserID, $event, $link = null, array $data) |
||
| 51 | { |
||
| 52 | global $xoopsConfig, $xoopsUser; |
||
| 53 | $date = date('m-d-Y H:i:s', time()); |
||
| 54 | $mail = new \XoopsMultiMailer; |
||
| 55 | $wall = new WallUpdates; |
||
| 56 | $tpl = new \XoopsTpl(); |
||
|
|
|||
| 57 | $message = ''; |
||
| 58 | |||
| 59 | // From and To user ids |
||
| 60 | $FromUser = new \XoopsUser($fromUserID); |
||
| 61 | $from_avatar = $wall->Gravatar($fromUserID); |
||
| 62 | $from_avatarlink = "<img class='left' src='" . smallworld_getAvatarLink($fromUserID, $from_avatar) . "' height='90px' width='90px'>"; |
||
| 63 | |||
| 64 | $ToUser = new \XoopsUser($toUserID); |
||
| 65 | $To_avatar = $wall->Gravatar($toUserID); |
||
| 66 | $To_avatarlink = "<img class='left' src='" . smallworld_getAvatarLink($toUserID, $To_avatar) . "' height='90px' width='90px'>"; |
||
| 67 | // Senders username |
||
| 68 | $SendName = $FromUser->getVar('uname'); |
||
| 69 | $SendNameUrl = "<a href='" . XOOPS_URL . '/modules/smallworld/userprofile.php?username=' . $SendName . "'>" . $SendName . '</a>'; |
||
| 70 | |||
| 71 | // Recievers username and email |
||
| 72 | $RecieveName = $ToUser->getVar('uname'); |
||
| 73 | $RecieveNameUrl = "<a href='" . XOOPS_URL . '/modules/smallworld/userprofile.php?username=' . $RecieveName . "'>" . $RecieveName . '</a>'; |
||
| 74 | |||
| 75 | // Checking content of 'event' to send right message |
||
| 76 | if ('register' === $event) { |
||
| 77 | $subject = _SMALLWORLD_MAIL_REGISTERSUBJECT . $xoopsConfig['sitename']; |
||
| 78 | |||
| 79 | $registername = $SendName; |
||
| 80 | $To_avatarlink = "<img class='left' src='" . smallworld_getAvatarLink($fromUserID, $To_avatar) . "' height='90px' width='90px'>"; |
||
| 81 | |||
| 82 | $tpl = new \XoopsTpl(); |
||
| 83 | $tpl->assign('registername', $registername); |
||
| 84 | $tpl->assign('sitename', $xoopsConfig['sitename']); |
||
| 85 | $tpl->assign('registerurl', $SendNameUrl); |
||
| 86 | $tpl->assign('registerlink', $To_avatarlink); |
||
| 87 | |||
| 88 | $lnk = XOOPS_ROOT_PATH . '/modules/smallworld/language/' . $xoopsConfig['language'] . '/mailTpl/mail_register.tpl'; |
||
| 89 | $message = $tpl->fetch($lnk); |
||
| 90 | $mail->Body = $message; |
||
| 91 | $toMail = $xoopsConfig['adminmail']; |
||
| 92 | |||
| 93 | // Send email to admin if red/yellow card has been pressed indicating a "bad" thread has been found. |
||
| 94 | } elseif ('complaint' === $event) { |
||
| 95 | $subject = _SMALLWORLD_MAIL_COMPLAINT . $xoopsConfig['sitename']; |
||
| 96 | |||
| 97 | $senders_id = $fromUserID; |
||
| 98 | $senders_name = stripslashes($data['byuser']); |
||
| 99 | $against_user = stripslashes($data['a_user']); |
||
| 100 | $time = date('d-m-Y H:i:s', $data['time']); |
||
| 101 | $link = stripslashes($data['link']); |
||
| 102 | |||
| 103 | $tpl = new \XoopsTpl(); |
||
| 104 | $tpl->assign('sendername', $senders_name); |
||
| 105 | $tpl->assign('against', $against_user); |
||
| 106 | $tpl->assign('time', $time); |
||
| 107 | $tpl->assign('link', $link); |
||
| 108 | $tpl->assign('sitename', $xoopsConfig['sitename']); |
||
| 109 | |||
| 110 | $lnk = XOOPS_ROOT_PATH . '/modules/smallworld/language/' . $xoopsConfig['language'] . '/mailTpl/mail_complaint.tpl'; |
||
| 111 | $message = $tpl->fetch($lnk); |
||
| 112 | $mail->Body = $message; |
||
| 113 | $toMail = $xoopsConfig['adminmail']; |
||
| 114 | } elseif ('commentToWM' === $event) { |
||
| 115 | $subject = _SMALLWORLD_MAIL_NEWCOMMENT . $xoopsConfig['sitename']; |
||
| 116 | |||
| 117 | $ownermessage = stripslashes($this->getOwnerUpdateFromMsgID($data['msg_id_fk'])); |
||
| 118 | View Code Duplication | if (preg_match('/UPLIMAGE/', $ownermessage)) { |
|
| 119 | $ownmsg = str_replace('UPLIMAGE ', '', $ownermessage); |
||
| 120 | $ownermessage = "<img width='300px' src='" . $ownmsg . "' style='margin: 5px 0px;' >"; |
||
| 121 | } |
||
| 122 | |||
| 123 | $owner = Smallworld_getOwnerFromComment($data['msg_id_fk']); |
||
| 124 | $OwnerUser = new \XoopsUser($owner); |
||
| 125 | $Owner_avatar = $wall->Gravatar($owner); |
||
| 126 | $Owner_avatarlink = "<img class='left' src='" . smallworld_getAvatarLink($owner, $Owner_avatar) . "' height='90px' width='90px'>"; |
||
| 127 | $OwnerName = $OwnerUser->getVar('uname'); |
||
| 128 | $OwnerNameUrl = "<a href='" . XOOPS_URL . '/modules/smallworld/userprofile.php?username=' . $OwnerName . "'>" . $OwnerName . '</a>'; |
||
| 129 | |||
| 130 | $replylink = "<a href='" . XOOPS_URL . '/modules/smallworld/permalink.php?ownerid=' . $owner . '&updid=' . $data['msg_id_fk'] . "'>"; |
||
| 131 | $replylink .= _SMALLWORLD_SEEANDREPLYHERE . '</a>'; |
||
| 132 | |||
| 133 | $tpl = new \XoopsTpl(); |
||
| 134 | $tpl->assign('recievename', $RecieveName); |
||
| 135 | $tpl->assign('ownername', $OwnerName); |
||
| 136 | $tpl->assign('ownernameurl', $OwnerNameUrl); |
||
| 137 | $tpl->assign('sendname', $SendName); |
||
| 138 | $tpl->assign('sendnameurl', $SendNameUrl); |
||
| 139 | $tpl->assign('sitename', $xoopsConfig['sitename']); |
||
| 140 | $tpl->assign('ownermessage', $ownermessage); |
||
| 141 | $tpl->assign('from_avatarlink', $from_avatarlink); |
||
| 142 | $tpl->assign('to_avatarlink', $Owner_avatarlink); |
||
| 143 | $tpl->assign('itemtext', stripslashes($data['comment'])); |
||
| 144 | $tpl->assign('itemtextdate', $date); |
||
| 145 | $tpl->assign('replylink', $replylink); |
||
| 146 | $lnk = XOOPS_ROOT_PATH . '/modules/smallworld/language/' . $xoopsConfig['language'] . '/mailTpl/mail_newcomment.tpl'; |
||
| 147 | $message = $tpl->fetch($lnk); |
||
| 148 | $mail->Body = $message; |
||
| 149 | |||
| 150 | $toMail = $ToUser->getVar('email'); |
||
| 151 | } elseif ('friendshipfollow' === $event) { |
||
| 152 | $subject = _SMALLWORLD_MAIL_NEWFRIENDFOLLOWER . $xoopsConfig['sitename']; |
||
| 153 | $link = "<a href='" . XOOPS_URL . "/modules/smallworld/index.php'>"; |
||
| 154 | $link .= _SMALLWORLD_GOTOSMALLWORLDHERE . '</a>'; |
||
| 155 | |||
| 156 | $tpl = new \XoopsTpl(); |
||
| 157 | $tpl->assign('toUser', $RecieveName); |
||
| 158 | $tpl->assign('date', $date); |
||
| 159 | $tpl->assign('link', $link); |
||
| 160 | $tpl->assign('sitename', $xoopsConfig['sitename']); |
||
| 161 | |||
| 162 | $lnk = XOOPS_ROOT_PATH . '/modules/smallworld/language/' . $xoopsConfig['language'] . '/mailTpl/mail_attencionneeded.tpl'; |
||
| 163 | $message = $tpl->fetch($lnk); |
||
| 164 | $mail->Body = $message; |
||
| 165 | $toMail = $ToUser->getVar('email'); |
||
| 166 | } elseif ('tag' === $event) { |
||
| 167 | $subject = _SMALLWORLD_MAIL_FRIENDTAGGEDYOU . $xoopsConfig['sitename']; |
||
| 168 | $tpl = new \XoopsTpl(); |
||
| 169 | $tpl->assign('toUser', $RecieveName); |
||
| 170 | $tpl->assign('fromUser', $SendName); |
||
| 171 | $tpl->assign('date', $date); |
||
| 172 | $tpl->assign('link', $link); |
||
| 173 | $tpl->assign('sitename', $xoopsConfig['sitename']); |
||
| 174 | |||
| 175 | $lnk = XOOPS_ROOT_PATH . '/modules/smallworld/language/' . $xoopsConfig['language'] . '/mailTpl/mail_tag.tpl'; |
||
| 176 | $message = $tpl->fetch($lnk); |
||
| 177 | $mail->Body = $message; |
||
| 178 | $toMail = $ToUser->getVar('email'); |
||
| 179 | } |
||
| 180 | |||
| 181 | $mail->isMail(); |
||
| 182 | $mail->isHTML(true); |
||
| 183 | $mail->addAddress($toMail); |
||
| 184 | $mail->Subject = $subject; |
||
| 185 | |||
| 186 | if (!$mail->send()) { |
||
| 187 | } else { |
||
| 188 | } |
||
| 189 | } |
||
| 190 | |||
| 225 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.