| Conditions | 8 |
| Paths | 16 |
| Total Lines | 55 |
| Code Lines | 41 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 82 | public function mailResults($pollObj = null) |
||
| 83 | { |
||
| 84 | $criteria = new \CriteriaCompo(); |
||
| 85 | $criteria->add(new \Criteria('end_time', \time(), '<')); // expired polls |
||
| 86 | $criteria->add(new \Criteria('mail_status', Constants::POLL_NOT_MAILED, '=')); // email not previously sent |
||
| 87 | if (!empty($pollObj) && ($pollObj instanceof Poll)) { |
||
| 88 | $criteria->add(new \Criteria('poll_id', $pollObj->getVar('poll_id'), '=')); |
||
|
|
|||
| 89 | $criteria->setLimit(1); |
||
| 90 | } |
||
| 91 | $pollObjs = &$this->getAll($criteria); |
||
| 92 | $tplFile = 'mail_results.tpl'; |
||
| 93 | $lang = 'english'; |
||
| 94 | if (\file_exists($GLOBALS['xoops']->path('modules/xoopspoll/language/' . $GLOBALS['xoopsConfig']['language'] . '/mail_template/' . $tplFile))) { |
||
| 95 | $lang = $GLOBALS['xoopsConfig']['language']; |
||
| 96 | } |
||
| 97 | \xoops_loadLanguage('main', 'xoopspoll', $lang); |
||
| 98 | |||
| 99 | $ret = []; |
||
| 100 | |||
| 101 | // setup mailer |
||
| 102 | $xoopsMailer = \xoops_getMailer(); |
||
| 103 | $xoopsMailer->useMail(); |
||
| 104 | $xoopsMailer->setTemplateDir($GLOBALS['xoops']->path('modules/xoopspoll/language/' . $lang . '/mail_template/')); |
||
| 105 | |||
| 106 | $xoopsMailer->setTemplate($tplFile); |
||
| 107 | $xoopsMailer->assign('SITENAME', $GLOBALS['xoopsConfig']['sitename']); |
||
| 108 | $xoopsMailer->assign('ADMINMAIL', $GLOBALS['xoopsConfig']['adminmail']); |
||
| 109 | $xoopsMailer->assign('SITEURL', $GLOBALS['xoops']->url('')); |
||
| 110 | $xoopsMailer->assign('MODULEURL', $GLOBALS['xoops']->url('modules/xoopspoll/')); |
||
| 111 | $xoopsMailer->setFromEmail($GLOBALS['xoopsConfig']['adminmail']); |
||
| 112 | $xoopsMailer->setFromName($GLOBALS['xoopsConfig']['sitename']); |
||
| 113 | foreach ($pollObjs as $pollObject) { |
||
| 114 | $pollValues = $pollObject->getValues(); |
||
| 115 | // get author info |
||
| 116 | $author = new \XoopsUser($pollValues['user_id']); |
||
| 117 | if (($author instanceof \XoopsUser) && ($author->uid() > 0)) { |
||
| 118 | $xoopsMailer->setToUsers($author); |
||
| 119 | // initialize variables |
||
| 120 | $xoopsMailer->assign('POLL_QUESTION', $pollValues['question']); |
||
| 121 | $xoopsMailer->assign('POLL_START', \formatTimestamp($pollValues['start_time'], 'l', $author->timezone())); |
||
| 122 | $xoopsMailer->assign('POLL_END', \formatTimestamp($pollValues['end_time'], 'l', $author->timezone())); |
||
| 123 | $xoopsMailer->assign('POLL_VOTES', $pollValues['votes']); |
||
| 124 | $xoopsMailer->assign('POLL_VOTERS', $pollValues['voters']); |
||
| 125 | $xoopsMailer->assign('POLL_ID', $pollValues['poll_id']); |
||
| 126 | $xoopsMailer->setSubject(\sprintf(\_MD_XOOPSPOLL_YOURPOLLAT, $author->uname(), $GLOBALS['xoopsConfig']['sitename'])); |
||
| 127 | if ($xoopsMailer->send(false)) { |
||
| 128 | $pollObject->setVar('mail_status', Constants::POLL_MAILED); |
||
| 129 | $ret[] = $this->insert($pollObject); |
||
| 130 | } else { |
||
| 131 | $ret[] = $xoopsMailer->getErrors(false); // return error array from mailer |
||
| 132 | } |
||
| 133 | } |
||
| 134 | } |
||
| 135 | |||
| 136 | return $ret; |
||
| 137 | } |
||
| 139 |