Conditions | 16 |
Paths | 80 |
Total Lines | 143 |
Code Lines | 96 |
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); |
||
207 | function xoopspollBlockSinglepollEdit(mixed $options): string |
||
208 | { |
||
209 | /** |
||
210 | * Options[] |
||
211 | * 0 = show expired polls in block |
||
212 | * 1 = poll id to show |
||
213 | * if hiding expired poll then the next non-expired poll |
||
214 | * will show if the selected poll is hidden |
||
215 | * 2 = show results button in block |
||
216 | * 3 = show options as list|select |
||
217 | */ |
||
218 | |||
219 | // find out if you want to show expired polls in block |
||
220 | // (otherwise it will hide block once it expires) |
||
221 | if (0 === $options[0]) { |
||
222 | $chk0no = ' checked'; |
||
223 | $chk0yes = ''; |
||
224 | } else { |
||
225 | $chk0no = ''; |
||
226 | $chk0yes = ' checked'; |
||
227 | } |
||
228 | $form = "<table><tr><td class='width25 middle'>" |
||
229 | . _MB_XOOPSPOLL_SHOW_EXP |
||
230 | . ':</td><td>' |
||
231 | . "<label class='middle' for='yes'>" |
||
232 | . _YES |
||
233 | . "</label>\n" |
||
234 | . "<input type='radio' name='options[0]' value='1'{$chk0yes} id='yes'>\n" |
||
235 | . "<label class='middle' style='margin-left: 2em;' for='no'> " |
||
236 | . _NO |
||
237 | . "</label>\n" |
||
238 | . "<input type='radio' name='options[0]' value='0'{$chk0no} id='no'>\n" |
||
239 | . "</td></tr>\n"; |
||
240 | |||
241 | $pollHandler = Helper::getInstance()->getHandler('Poll'); |
||
242 | $pollFields = ['poll_id', 'start_time', 'end_time', 'question', 'weight']; |
||
243 | $criteria = new \CriteriaCompo(); |
||
244 | // $criteria->add(new \Criteria('end_time', time(), '>')); |
||
245 | $criteria->setOrder('ASC'); |
||
246 | $criteria->setSort('weight'); |
||
247 | /** |
||
248 | * Note that you can select polls that have not started yet, so they will automatically show |
||
249 | * up in the block once they have started. To only allow selection of active polls uncomment |
||
250 | * the following line in the code - this could be made a module config option if desired |
||
251 | */ |
||
252 | |||
253 | // $criteria->add(new \Criteria('start_time', time(), '<=')); |
||
254 | |||
255 | /** |
||
256 | * now check to see if we want to hide polls that were created using newbb |
||
257 | */ |
||
258 | /** @var \XoopsConfigHandler $configHandler */ |
||
259 | $configHandler = xoops_getHandler('config'); |
||
260 | /** @var \XoopsModuleHandler $moduleHandler */ |
||
261 | $moduleHandler = xoops_getHandler('module'); |
||
262 | $thisModule = $moduleHandler->getByDirname('xoopspoll'); |
||
263 | $thisModuleConfig = $configHandler->getConfigsByCat(0, $thisModule->getVar('mid')); |
||
264 | |||
265 | if ($thisModuleConfig['hide_forum_polls'] && ($thisModule instanceof \XoopsModule) && $thisModule->isactive()) { |
||
266 | $newbbModule = $moduleHandler->getByDirname('newbb'); |
||
267 | if ($newbbModule instanceof \XoopsModule && $newbbModule->isactive()) { |
||
268 | /** @var Newbb\TopicHandler $topicHandler */ |
||
269 | $topicHandler = Newbb\Helper::getInstance()->getHandler('Topic'); |
||
270 | $tFields = ['topic_id', 'poll_id']; |
||
271 | $tArray = $topicHandler->getAll(new \Criteria('topic_haspoll', 0, '>'), $tFields, false); |
||
272 | if (!empty($tArray)) { |
||
273 | $tcriteria = []; |
||
274 | foreach ($tArray as $t) { |
||
275 | $tcriteria[] = $t['poll_id']; |
||
276 | } |
||
277 | if (!empty($tcriteria)) { |
||
278 | $tstring = '(' . implode(',', $tcriteria) . ')'; |
||
279 | $criteria->add(new \Criteria('poll_id', $tstring, 'NOT IN')); |
||
280 | } |
||
281 | } |
||
282 | unset($topicHandler, $tFields, $tArray); |
||
283 | } |
||
284 | unset($newbbModule); |
||
285 | } |
||
286 | |||
287 | $allPollsArray = $pollHandler->getAll($criteria, $pollFields, false); |
||
288 | |||
289 | // next get a list of all available polls for select box |
||
290 | $form .= '<tr><td>' . _MB_XOOPSPOLL_POLLS . ":</td><td style='text-align: left; margin-left: 1em;'>\n"; |
||
291 | if (empty($allPollsArray)) { |
||
292 | $form .= "<span class='errorMsg'>" . _MB_XOOPSPOLL_NONE_ACTIVE . '</span>'; |
||
293 | } else { |
||
294 | $form .= "<select name='options[1]'>\n"; |
||
295 | foreach ($allPollsArray as $thisPoll) { |
||
296 | $selected = ($thisPoll['poll_id'] === $options[1]) ? ' selected' : ''; |
||
297 | $taggedQuestion = ($thisPoll['end_time'] < time()) ? $thisPoll['question'] . '**' : $thisPoll['question']; |
||
298 | $form .= " <option value='" . $thisPoll['poll_id'] . "'{$selected}>" . $taggedQuestion . "</option>\n"; |
||
299 | } |
||
300 | $form .= "</select>\n" . ' ** - ' . _MB_XOOPSPOLL_EXPIRED_INDICATOR . "\n"; |
||
301 | } |
||
302 | if (0 === $options[2]) { |
||
303 | $chk2no = ' checked'; |
||
304 | $chk2yes = ''; |
||
305 | } else { |
||
306 | $chk2no = ''; |
||
307 | $chk2yes = ' checked'; |
||
308 | } |
||
309 | $form .= "</td></tr>\n" |
||
310 | . "<tr><td class='width25 middle'>" |
||
311 | . _MB_XOOPSPOLL_SHOW_RESULT_LINK |
||
312 | . ':</td><td>' |
||
313 | . "<label class='middle' for='yesr'>" |
||
314 | . _YES |
||
315 | . "</label>\n" |
||
316 | . "<input type='radio' name='options[2]' value='1'{$chk2yes} id='yesr'>\n" |
||
317 | . "<label class='middle' style='margin-left: 2em;' for='nor'> " |
||
318 | . _NO |
||
319 | . "</label>\n" |
||
320 | . "<input type='radio' name='options[2]' value='0'{$chk2no} id='nor'>\n" |
||
321 | . "</td></tr>\n"; |
||
322 | |||
323 | /* find out if you want to show options as a list or as a select box */ |
||
324 | if (Constants::POLL_OPTIONS_SELECT === $options[3]) { |
||
325 | $chk3select = ' checked'; |
||
326 | $chk3list = ''; |
||
327 | } else { |
||
328 | $chk3select = ''; |
||
329 | $chk3list = ' checked'; |
||
330 | } |
||
331 | $form .= "<table><tr><td class='width25 middle'>" |
||
332 | . _MB_XOOPSPOLL_SHOW_OPTIONS |
||
333 | . ':</td><td>' |
||
334 | . "<label class='middle' for='list'>" |
||
335 | . _MB_XOOPSPOLL_LIST |
||
336 | . "</label>\n" |
||
337 | . "<input type='radio' name='options[3]' value='" |
||
338 | . Constants::POLL_OPTIONS_LIST |
||
339 | . "'{$chk3list} id='list'>\n" |
||
340 | . "<label class='middle' style='margin-left: 2em;' for='select'> " |
||
341 | . _MB_XOOPSPOLL_SELECT |
||
342 | . "</label>\n" |
||
343 | . "<input type='radio' name='options[3]' value='" |
||
344 | . Constants::POLL_OPTIONS_SELECT |
||
345 | . "'{$chk3select} id='select'>\n" |
||
346 | . "</td></tr>\n" |
||
347 | . "</table>\n"; |
||
348 | |||
349 | return $form; |
||
350 | } |
||
351 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.