File main.php
has 591 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php declare(strict_types=1);
/*
XOOPS - PHP Content Management System
Copyright (c) 2000-2020 XOOPS.org
<https://xoops.org>
Similar blocks of code found in 3 locations. Consider refactoring. Open
$pollVars = [
'user_id' => Request::getInt('user_id', $GLOBALS['xoopsUser']->uid(), 'POST'),
'question' => Request::getString('question', null, 'POST'),
'description' => Request::getText('description', null, 'POST'),
'mail_status' => (Constants::NOTIFICATION_ENABLED === $notify) ? Constants::POLL_NOT_MAILED : Constants::POLL_MAILED,
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 256.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
The CASE body must start on the line following the statement Open
case 'quickupdate':
- Exclude checks
There must be one USE keyword per declaration Open
use XoopsModules\Xoopspoll\{
- Exclude checks
Line exceeds 120 characters; contains 122 characters Open
redirect_header($_SERVER['SCRIPT_NAME'], Constants::REDIRECT_DELAY_SHORT, _AM_XOOPSPOLL_ERROR_INVALID_POLLID);
- Exclude checks
Line exceeds 120 characters; contains 198 characters Open
echo " <tr class='{$rowClass}'><td class='center'>" . ++$i . "</td><td class='center'>{$thisOption['option_text']}</td><td class='center'>{$thisOption['option_count']}</td></tr>\n";
- Exclude checks
Line exceeds 120 characters; contains 205 characters Open
$adminObject->addInfoBoxLine(sprintf("<img src='" . $pathIcon16 . "/forum.png' alt='" . _AM_XOOPSPOLL_NEWBB_SUPPORT . "'> " . _AM_XOOPSPOLL_NEWBB_INTRO, null, null, 'information'), '');
- Exclude checks
Line exceeds 120 characters; contains 135 characters Open
$endTimestamp = empty($xuEndTimestamp) ? (time() + Constants::DEFAULT_POLL_DURATION) : userTimeToServerTime($xuEndTimestamp);
- Exclude checks
Line exceeds 120 characters; contains 135 characters Open
. " <a href='{$sorthref}{$field['order']}&orderdir=DESC'><img src='{$arrowDown}' alt=''></a>\n"
- Exclude checks
Line exceeds 120 characters; contains 286 characters Open
// echo "<div class='center' style='margin-bottom: 1em;'>[ <a href='" . $_SERVER['SCRIPT_NAME'] . "?op=list'><img src='". $pathIcon16 ."/back.png' alt='" . _AM_XOOPSPOLL_RETURNLIST . "' title='" . _AM_XOOPSPOLL_RETURNLIST . "'>" . _AM_XOOPSPOLL_RETURNLIST . "</a> ]</div>\n";
- Exclude checks
Line exceeds 120 characters; contains 148 characters Open
redirect_header($_SERVER['SCRIPT_NAME'] . "?poll_id={$cloneId}&op=edit", Constants::REDIRECT_DELAY_MEDIUM, _AM_XOOPSPOLL_CLONE_SUCCESS);
- Exclude checks
Line exceeds 120 characters; contains 148 characters Open
$startTimestamp = empty($xuStartTimestamp) ? ($endTimestamp - Constants::DEFAULT_POLL_DURATION) : userTimeToServerTime($xuStartTimestamp);
- Exclude checks
Line exceeds 120 characters; contains 122 characters Open
redirect_header($_SERVER['SCRIPT_NAME'], Constants::REDIRECT_DELAY_SHORT, _AM_XOOPSPOLL_ERROR_INVALID_POLLID);
- Exclude checks
Line exceeds 120 characters; contains 130 characters Open
redirect_header($_SERVER['SCRIPT_NAME'], Constants::REDIRECT_DELAY_SHORT, implode('<br>', $pollHandler->getErrors()));
- Exclude checks
Line exceeds 120 characters; contains 240 characters Open
echo "<table class='outer bnone width100' style='padding: 0; margin: 0;'>\n" . " <tr>\n" . " <td class='bg2'>\n" . " <table class='width100 bnone pad3 marg2'>\n" . " <thead>\n" . " <tr class='bg3'>\n";
- Exclude checks
Line exceeds 120 characters; contains 168 characters Open
// echo "<div class='center' style='margin-bottom: 1em;'>[ <a href='" . $_SERVER['SCRIPT_NAME'] . "?op=list'>" . _AM_XOOPSPOLL_RETURNLIST . "</a> ]</div>\n";
- Exclude checks
Line exceeds 120 characters; contains 129 characters Open
'mail_status' => (Constants::NOTIFICATION_ENABLED === $notify) ? Constants::POLL_NOT_MAILED : Constants::POLL_MAILED,
- Exclude checks
Line exceeds 120 characters; contains 151 characters Open
$ipLabel = (Constants::LOOK_UP_HOST === $GLOBALS['xoopsModuleConfig']['look_up_host']) ? _AM_XOOPSPOLL_HOST_NAME : _AM_XOOPSPOLL_IP;
- Exclude checks
Line exceeds 120 characters; contains 144 characters Open
redirect_header($_SERVER['SCRIPT_NAME'], Constants::REDIRECT_DELAY_MEDIUM, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
- Exclude checks
Line exceeds 120 characters; contains 144 characters Open
redirect_header($_SERVER['SCRIPT_NAME'], Constants::REDIRECT_DELAY_MEDIUM, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
- Exclude checks
Line exceeds 120 characters; contains 148 characters Open
$startTimestamp = empty($xuStartTimestamp) ? ($xuEndTimestamp - Constants::DEFAULT_POLL_DURATION) : userTimeToServerTime($xuStartTimestamp);
- Exclude checks
Line exceeds 120 characters; contains 266 characters Open
echo " <tr class='bg1'>\n" . " <td class='{$class} center'>{$logVals['log_id']}</td>\n" . " <td class='{$class}'>" . $option->getVar('option_text') . "</td>\n" . " <td class='{$class} center'>{$remoteIp}</td>\n";
- Exclude checks
Line exceeds 120 characters; contains 144 characters Open
redirect_header($_SERVER['SCRIPT_NAME'], Constants::REDIRECT_DELAY_MEDIUM, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
- Exclude checks
Line exceeds 120 characters; contains 123 characters Open
if ($display[$thisId] !== $pollObj->getVar('display') || $weight[$thisId] !== $pollObj->getVar('weight')) {
- Exclude checks
Line exceeds 120 characters; contains 281 characters Open
$startTimeText = new FormDateTimePicker("<div class='bold'>" . _AM_XOOPSPOLL_START_TIME . '<br>' . "<span class='x-small'>" . _AM_XOOPSPOLL_FORMAT . '<br>' . sprintf(_AM_XOOPSPOLL_CURRENTTIME, $xuCurrentFormatted) . '</span></div>', 'xu_start_time', 20, $xuStartTimestamp);
- Exclude checks
Line exceeds 120 characters; contains 149 characters Open
$endTimeText = new FormDateTimePicker("<div class='bold middle'>" . _AM_XOOPSPOLL_EXPIRATION . '</div>', 'xu_end_time', 20, $xuEndTimestamp);
- Exclude checks
Line exceeds 120 characters; contains 132 characters Open
. " <a href='{$sorthref}{$field['order']}&orderdir=ASC'><img src='{$arrowUp}' alt=''></a>\n"
- Exclude checks
Line exceeds 120 characters; contains 122 characters Open
$pollForm = new \XoopsThemeForm(_AM_XOOPSPOLL_RESTARTPOLL, 'poll_form', $_SERVER['SCRIPT_NAME'], 'post', true);
- Exclude checks
Line exceeds 120 characters; contains 197 characters Open
$end = "<span class='red'>" . _AM_XOOPSPOLL_EXPIRED . '</span><br>' . "<a href='" . $_SERVER['SCRIPT_NAME'] . "?op=restart&poll_id={$id}'>" . _AM_XOOPSPOLL_RESTART . '</a>';
- Exclude checks
Line exceeds 120 characters; contains 128 characters Open
'alt' => _AM_XOOPSPOLL_NEWBB_TOPIC . ' ' . htmlspecialchars($topic_title, ENT_QUOTES | ENT_HTML5),
- Exclude checks
Line exceeds 120 characters; contains 138 characters Open
$display[$thisId] = empty($display[$thisId]) ? Constants::DO_NOT_DISPLAY_POLL_IN_BLOCK : Constants::DISPLAY_POLL_IN_BLOCK;
- Exclude checks
Line exceeds 120 characters; contains 148 characters Open
$endTimestamp = empty($xuEndTimestamp) ? ($currentTimestamp + Constants::DEFAULT_POLL_DURATION) : userTimeToServerTime($xuEndTimestamp);
- Exclude checks