| Conditions | 5 |
| Paths | 16 |
| Total Lines | 153 |
| Code Lines | 76 |
| Lines | 8 |
| Ratio | 5.23 % |
| 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 |
||
| 38 | function sendMail2member($mode, $event_id, $member_uid, $subject, $tplMessage) |
||
| 39 | { |
||
| 40 | //mode = 0 pas d'entete |
||
| 41 | //mode = 1 format text |
||
| 42 | //mode = 2: format html |
||
| 43 | |||
| 44 | global $xoopsConfig, $xoopsDB; |
||
| 45 | // $t = print_r($xoopsConfig, true); |
||
| 46 | // echo "<pre>{$t}</pre>"; |
||
| 47 | /* |
||
| 48 | $member_uid = 1; |
||
| 49 | $event_id = 393; |
||
| 50 | $message = "Bonne journée à tous"; |
||
| 51 | $newStatus = 1; |
||
| 52 | $oldStatus = 0; |
||
| 53 | |||
| 54 | */ |
||
| 55 | |||
| 56 | //l'utilisateur ne pas etre notifié par mail |
||
| 57 | //if ($mode == 0) exit; |
||
| 58 | //------------------------------------------------------- |
||
| 59 | $tblMember = $xoopsDB->prefix('extcal_eventmember'); |
||
| 60 | $tblNotMember = $xoopsDB->prefix('extcal_eventnotmember'); |
||
| 61 | $tblUsers = $xoopsDB->prefix('users'); |
||
| 62 | $tblEvent = $xoopsDB->prefix('extcal_event'); |
||
| 63 | |||
| 64 | //-------------------------------------------------------------- |
||
| 65 | //Recuperation des données event,user et member |
||
| 66 | //Recuperation des données de l'evennement |
||
| 67 | $eventHandler = xoops_getModuleHandler(_EXTCAL_CLS_EVENT, _EXTCAL_MODULE); |
||
| 68 | $obj = $eventHandler->getEvent($event_id); |
||
| 69 | $event = $eventHandler->objectToArray($obj); |
||
| 70 | $eventHandler->formatEventDate($event, _MD_EXTCAL_FORMAT_DATE); |
||
| 71 | |||
| 72 | $submiter_uid = $event['event_submitter']; |
||
| 73 | // ext_echoArray($event,'event'); |
||
| 74 | //-------------------------------------------------------------- |
||
| 75 | //Recuperation des données du user createur de l'evennement |
||
| 76 | $sql = <<<__sql__ |
||
| 77 | SELECT if(tu.name='', tu.uname, tu.name) AS name, tu.uname, tu.email |
||
| 78 | FROM {$tblUsers} tu |
||
| 79 | WHERE tu.uid = {$submiter_uid}; |
||
| 80 | __sql__; |
||
| 81 | |||
| 82 | $rst = $xoopsDB->query($sql); |
||
| 83 | $submiter = $xoopsDB->fetchArray($rst); |
||
| 84 | // echo "{$sql}<br>"; |
||
| 85 | // ext_echoArray($submiter,'submiter'); |
||
| 86 | //-------------------------------------------------------------- |
||
| 87 | //Recuperation des données du membre inscrit |
||
| 88 | $sql = <<<__sql__ |
||
| 89 | SELECT if(tu.name='', tu.uname, tu.name) AS name, tu.uname, tu.email |
||
| 90 | FROM {$tblUsers} tu |
||
| 91 | WHERE tu.uid = {$member_uid}; |
||
| 92 | __sql__; |
||
| 93 | |||
| 94 | $rst = $xoopsDB->query($sql); |
||
| 95 | $acteur = $xoopsDB->fetchArray($rst); |
||
| 96 | //echo "{$sql}<br>"; |
||
| 97 | // ext_echoArray($acteur,'acteur'); |
||
| 98 | //-------------------------------------------------------------- |
||
| 99 | //Recuperation des données des membres présents |
||
| 100 | $sql = <<<__sql__ |
||
| 101 | SELECT tu.uid, if(tu.name='', tu.uname, tu.name) AS name, tu.uname, tu.email, |
||
| 102 | tm.status |
||
| 103 | FROM {$tblMember} tm, |
||
| 104 | {$tblUsers} tu |
||
| 105 | WHERE tm.uid = tu.uid |
||
| 106 | AND tm.event_id = {$event_id} |
||
| 107 | __sql__; |
||
| 108 | |||
| 109 | $rst = $xoopsDB->query($sql); |
||
| 110 | $members = array(); |
||
| 111 | View Code Duplication | while ($row = $xoopsDB->fetchArray($rst)) { |
|
| 112 | $row['status'] = _MD_EXTCAL_PRESENT; |
||
| 113 | $members[$row['uid']] = $row; |
||
| 114 | } |
||
| 115 | |||
| 116 | //-------------------------------------------------------------- |
||
| 117 | //Recuperation des données des membres absents |
||
| 118 | $sql = <<<__sql__ |
||
| 119 | SELECT tu.uid, if(tu.name='', tu.uname, tu.name) AS name, tu.uname, tu.email, |
||
| 120 | tm.status |
||
| 121 | FROM {$tblNotMember} tm, |
||
| 122 | {$tblUsers} tu |
||
| 123 | WHERE tm.uid = tu.uid |
||
| 124 | AND tm.event_id = {$event_id} |
||
| 125 | __sql__; |
||
| 126 | |||
| 127 | $rst = $xoopsDB->query($sql); |
||
| 128 | View Code Duplication | while ($row = $xoopsDB->fetchArray($rst)) { |
|
| 129 | $row['status'] = _MD_EXTCAL_ABSENT; |
||
| 130 | $members[$row['uid']] = $row; |
||
| 131 | } |
||
| 132 | |||
| 133 | // ext_echoArray($members,'members'); |
||
| 134 | // exit; |
||
| 135 | |||
| 136 | //-------------------------------------------------------------- |
||
| 137 | //Message et sujet du mail |
||
| 138 | $action = ''; //a voir JJD |
||
| 139 | $message = sprintf($tplMessage, $acteur['name']); |
||
| 140 | //$subject .= ' (' . rand(1, 100) . ')'; |
||
| 141 | $subject .= ' - ' . $acteur['name']; |
||
| 142 | //-------------------------------------------------------------- |
||
| 143 | //Chargement du template dans le dossier de langue |
||
| 144 | //$f = _EXTCAL_PATH_LG . $xoopsConfig['language'] . '\mail_inscription.html'; |
||
| 145 | //$tpl = new tpl($f); |
||
| 146 | $tpl = new XoopsTpl(); |
||
| 147 | |||
| 148 | $tpl->assign('dateAction', date(_MD_EXTCAL_FORMAT_DATE)); |
||
| 149 | $tpl->assign('submiter', $submiter); |
||
| 150 | $tpl->assign('event', $event); |
||
| 151 | $tpl->assign('acteur', $acteur); |
||
| 152 | $tpl->assign('members', $members); |
||
| 153 | $tpl->assign('action', $action); |
||
| 154 | $tpl->assign('subject', $subject); |
||
| 155 | $tpl->assign('message', $message); |
||
| 156 | $tpl->assign('xoopsConfig', $xoopsConfig); |
||
| 157 | $tpl->assign('br', '<br>'); |
||
| 158 | |||
| 159 | //-------------------------------------------------------------- |
||
| 160 | $destinataires = array(); |
||
| 161 | $destinataires[$submiter['email']] = $submiter['email']; |
||
| 162 | $destinataires[$acteur['email']] = $acteur['email']; |
||
| 163 | // while (list($k, $row) = each($members)) { |
||
| 164 | foreach ($members as $k => $row) { |
||
| 165 | $destinataires[$row['email']] = $row['email']; |
||
| 166 | } |
||
| 167 | |||
| 168 | // ext_echoArray($destinataires); |
||
| 169 | // exit; |
||
| 170 | |||
| 171 | $mail_fromName = $xoopsConfig['sitename']; |
||
| 172 | $mail_fromemail = $xoopsConfig['adminmail']; |
||
| 173 | $mail_subject = $subject; |
||
| 174 | |||
| 175 | $bEcho = false; |
||
| 176 | $mode = _EXTCAL_HEADER_HTML; |
||
| 177 | $sep = '|'; |
||
| 178 | |||
| 179 | $template = 'extcal_mail_member_text.tpl'; |
||
| 180 | if ($mode == _EXTCAL_HEADER_HTML) { |
||
| 181 | $template = 'extcal_mail_member_html.tpl'; |
||
| 182 | } |
||
| 183 | $mail_body = $tpl->fetch('db:' . $template); |
||
| 184 | |||
| 185 | extcal_SendMail($destinataires, $mail_fromName, $mail_fromemail, $mail_subject, $mail_body, $bEcho = false, $mode = 0, $sep = '|'); |
||
| 186 | |||
| 187 | //Prépartion de l'envoi |
||
| 188 | |||
| 189 | //-------------------------------------------------------------- |
||
| 190 | } |
||
| 191 | |||
| 331 |
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.