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