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