Conditions | 11 |
Paths | 144 |
Total Lines | 69 |
Code Lines | 54 |
Lines | 0 |
Ratio | 0 % |
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 |
||
175 | public function assignResults(\XoopsTpl $tpl) |
||
176 | { |
||
177 | $myts = \MyTextSanitizer::getInstance(); |
||
178 | $xuEndTimestamp = \xoops_getUserTimestamp($this->pollObj->getVar('end_time')); |
||
179 | $xuEndFormatted = \ucfirst(\date(_MEDIUMDATESTRING, $xuEndTimestamp)); |
||
180 | $xuStartTimestamp = \xoops_getUserTimestamp($this->pollObj->getVar('start_time')); |
||
181 | $xuStartFormatted = \ucfirst(\date(_MEDIUMDATESTRING, $xuStartTimestamp)); |
||
182 | |||
183 | // $logHandler = $this->helper->getHandler('Log'); |
||
184 | $criteria = new \CriteriaCompo(); |
||
185 | $criteria->add(new \Criteria('poll_id', $this->pollObj->getVar('poll_id'), '=')); |
||
186 | $criteria->setSort('option_id'); |
||
187 | $optObjsArray = $this->optionHandler->getAll($criteria); |
||
188 | $total = $this->pollObj->getVar('votes'); |
||
189 | $i = 0; |
||
190 | foreach ($optObjsArray as $optObj) { |
||
191 | $optionVars = $optObj->getValues(); |
||
192 | $percent = ($total > 0) ? (100 * $optionVars['option_count'] / $total) : 0; |
||
193 | if ($percent > 0) { |
||
194 | $width = (int)($percent * 2); |
||
195 | $options[$i]['image'] = "<img src='" . $GLOBALS['xoops']->url("modules/xoopspoll/assets/images/colorbars/{$optionVars['option_color']}'") . " style='height: 14px; width: {$width}px; vertical-align: middle;' alt='" . (int)$percent . "%'>"; |
||
196 | } else { |
||
197 | $options[$i]['image'] = ''; |
||
198 | } |
||
199 | |||
200 | /* setup module config handler - required since this is called by newbb too */ |
||
201 | /** @var \XoopsModuleHandler $moduleHandler */ |
||
202 | $moduleHandler = \xoops_getHandler('module'); |
||
203 | $configHandler = \xoops_getHandler('config'); |
||
204 | $xp_module = $moduleHandler->getByDirname('xoopspoll'); |
||
205 | $module_id = $xp_module->getVar('mid'); |
||
206 | $xp_config = $configHandler->getConfigsByCat(0, $module_id); |
||
207 | |||
208 | if ($xp_config['disp_vote_nums']) { |
||
209 | $options[$i]['percent'] = \sprintf(' %01.1f%% (%d)', $percent, $optionVars['option_count']); |
||
210 | } else { |
||
211 | $options[$i]['percent'] = \sprintf(' %01.1f%%', $percent); |
||
212 | } |
||
213 | $options[$i]['text'] = $optionVars['option_text']; |
||
214 | $options[$i]['total'] = $optionVars['option_count']; |
||
215 | $options[$i]['value'] = (int) $percent; |
||
216 | ++$i; |
||
217 | unset($optionVars); |
||
218 | } |
||
219 | $uid = (isset($GLOBALS['xoopsUser']) |
||
220 | && \is_object($GLOBALS['xoopsUser'])) ? $GLOBALS['xoopsUser']->getVar('uid') : 0; |
||
221 | $vote = null; |
||
222 | if (!$this->pollObj->hasExpired() && $this->pollObj->isAllowedToVote() |
||
223 | && !$this->logHandler->hasVoted($this->pollObj->getVar('poll_id'), \xoops_getenv('REMOTE_ADDR'), $uid)) { |
||
224 | $vote = "<a href='" . $GLOBALS['xoops']->url('modules/xoopspoll/index.php') . '?poll_id=' . $this->pollObj->getVar('poll_id') . "'>" . \_MD_XOOPSPOLL_VOTE_NOW . '</a>'; |
||
225 | } |
||
226 | if ($xp_config['disp_vote_nums']) { |
||
227 | $totalVotes = \sprintf(\_MD_XOOPSPOLL_TOTALVOTES, $total); |
||
228 | $totalVoters = \sprintf(\_MD_XOOPSPOLL_TOTALVOTERS, $this->pollObj->getVar('voters')); |
||
229 | } else { |
||
230 | $totalVotes = $totalVoters = ''; |
||
231 | } |
||
232 | |||
233 | $tpl->assign( |
||
234 | 'poll', |
||
235 | [ |
||
236 | 'question' => $myts->htmlSpecialChars($this->pollObj->getVar('question')), |
||
237 | 'end_text' => $xuEndFormatted, |
||
238 | 'start_text' => $xuStartFormatted, |
||
239 | 'totalVotes' => $totalVotes, |
||
240 | 'totalVoters' => $totalVoters, |
||
241 | 'vote' => $vote, |
||
242 | 'options' => $options, |
||
243 | 'description' => $this->pollObj->getVar('description'), //allow html |
||
244 | ] |
||
248 |