| Conditions | 22 |
| Paths | 6913 |
| Total Lines | 253 |
| Code Lines | 183 |
| 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 declare(strict_types=1); |
||
| 66 | public function listBlocks() |
||
| 67 | : void |
||
| 68 | { |
||
| 69 | global $xoopsModule, $pathIcon16; |
||
| 70 | require_once XOOPS_ROOT_PATH . '/class/xoopslists.php'; |
||
| 71 | // xoops_loadLanguage('admin', 'system'); |
||
| 72 | // xoops_loadLanguage('admin/blocksadmin', 'system'); |
||
| 73 | // xoops_loadLanguage('admin/groups', 'system'); |
||
| 74 | // xoops_loadLanguage('common', $moduleDirName); |
||
| 75 | // xoops_loadLanguage('blocks', $moduleDirName); |
||
| 76 | |||
| 77 | /** @var \XoopsModuleHandler $moduleHandler */ |
||
| 78 | $moduleHandler = \xoops_getHandler('module'); |
||
| 79 | /** @var \XoopsMemberHandler $memberHandler */ |
||
| 80 | $memberHandler = \xoops_getHandler('member'); |
||
| 81 | /** @var \XoopsGroupPermHandler $grouppermHandler */ |
||
| 82 | $grouppermHandler = \xoops_getHandler('groupperm'); |
||
| 83 | $groups = $memberHandler->getGroups(); |
||
| 84 | $criteria = new \CriteriaCompo(new \Criteria('hasmain', '1')); |
||
| 85 | $criteria->add(new \Criteria('isactive', '1')); |
||
| 86 | $moduleList = $moduleHandler->getList($criteria); |
||
| 87 | $moduleList[-1] = \_AM_SYSTEM_BLOCKS_TOPPAGE; |
||
| 88 | $moduleList[0] = \_AM_SYSTEM_BLOCKS_ALLPAGES; |
||
| 89 | \ksort($moduleList); |
||
| 90 | echo " |
||
| 91 | <h4 style='text-align:left;'>" . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'BADMIN') . '</h4>'; |
||
| 92 | echo "<form action='" . $_SERVER['SCRIPT_NAME'] . "' name='blockadmin' method='post'>"; |
||
| 93 | echo $GLOBALS['xoopsSecurity']->getTokenHTML(); |
||
| 94 | echo "<table width='100%' class='outer' cellpadding='4' cellspacing='1'> |
||
| 95 | <tr valign='middle'><th align='center'>" |
||
| 96 | . \_AM_SYSTEM_BLOCKS_TITLE |
||
| 97 | . "</th><th align='center' nowrap='nowrap'>" |
||
| 98 | . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'SIDE') |
||
| 99 | . '<br>' |
||
| 100 | . _LEFT |
||
| 101 | . '-' |
||
| 102 | . _CENTER |
||
| 103 | . '-' |
||
| 104 | . _RIGHT |
||
| 105 | . "</th><th align='center'>" |
||
| 106 | . \constant( |
||
| 107 | 'CO_' . $this->moduleDirNameUpper . '_' . 'WEIGHT' |
||
| 108 | ) |
||
| 109 | . "</th><th align='center'>" |
||
| 110 | . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'VISIBLE') |
||
| 111 | . "</th><th align='center'>" |
||
| 112 | . \_AM_SYSTEM_BLOCKS_VISIBLEIN |
||
| 113 | . "</th><th align='center'>" |
||
| 114 | . \_AM_SYSTEM_ADGS |
||
| 115 | . "</th><th align='center'>" |
||
| 116 | . \_AM_SYSTEM_BLOCKS_BCACHETIME |
||
| 117 | . "</th><th align='center'>" |
||
| 118 | . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'ACTION') |
||
| 119 | . '</th></tr> |
||
| 120 | '; |
||
| 121 | $blockArray = \XoopsBlock::getByModule($xoopsModule->mid()); |
||
| 122 | $blockCount = \count($blockArray); |
||
| 123 | $class = 'even'; |
||
| 124 | $cachetimes = [ |
||
| 125 | 0 => _NOCACHE, |
||
| 126 | 30 => \sprintf(_SECONDS, 30), |
||
| 127 | 60 => _MINUTE, |
||
| 128 | 300 => \sprintf(_MINUTES, 5), |
||
| 129 | 1800 => \sprintf(_MINUTES, 30), |
||
| 130 | 3600 => _HOUR, |
||
| 131 | 18000 => \sprintf(_HOURS, 5), |
||
| 132 | 86400 => _DAY, |
||
| 133 | 259200 => \sprintf(_DAYS, 3), |
||
| 134 | 604800 => _WEEK, |
||
| 135 | 2592000 => _MONTH, |
||
| 136 | ]; |
||
| 137 | foreach ($blockArray as $i) { |
||
| 138 | $groupsPermissions = $grouppermHandler->getGroupIds('block_read', $i->getVar('bid')); |
||
| 139 | $sql = 'SELECT module_id FROM ' . $this->db->prefix('block_module_link') . ' WHERE block_id=' . $i->getVar('bid'); |
||
| 140 | $result = $this->db->query($sql); |
||
| 141 | $modules = []; |
||
| 142 | if (!$result instanceof \mysqli_result) { |
||
| 143 | \trigger_error("Query Failed! SQL: $sql Error: " . $this->db->error(), \E_USER_ERROR); |
||
| 144 | } |
||
| 145 | while (false !== ($row = $this->db->fetchArray($result))) { |
||
| 146 | $modules[] = (int)$row['module_id']; |
||
| 147 | } |
||
| 148 | |||
| 149 | $cachetimeOptions = ''; |
||
| 150 | foreach ($cachetimes as $cachetime => $cachetimeName) { |
||
| 151 | if ($i->getVar('bcachetime') == $cachetime) { |
||
| 152 | $cachetimeOptions .= "<option value='$cachetime' selected='selected'>$cachetimeName</option>\n"; |
||
| 153 | } |
||
| 154 | else { |
||
| 155 | $cachetimeOptions .= "<option value='$cachetime'>$cachetimeName</option>\n"; |
||
| 156 | } |
||
| 157 | } |
||
| 158 | |||
| 159 | $ssel7 = ''; |
||
| 160 | $ssel6 = $ssel7; |
||
| 161 | $ssel5 = $ssel6; |
||
| 162 | $ssel4 = $ssel5; |
||
| 163 | $ssel3 = $ssel4; |
||
| 164 | $ssel2 = $ssel3; |
||
| 165 | $ssel1 = $ssel2; |
||
| 166 | $ssel0 = $ssel1; |
||
| 167 | $sel1 = $ssel0; |
||
| 168 | $sel0 = $sel1; |
||
| 169 | if (1 === $i->getVar('visible')) { |
||
| 170 | $sel1 = ' checked'; |
||
| 171 | } |
||
| 172 | else { |
||
| 173 | $sel0 = ' checked'; |
||
| 174 | } |
||
| 175 | if (\XOOPS_SIDEBLOCK_LEFT === $i->getVar('side')) { |
||
| 176 | $ssel0 = ' checked'; |
||
| 177 | } |
||
| 178 | elseif (\XOOPS_SIDEBLOCK_RIGHT === $i->getVar('side')) { |
||
| 179 | $ssel1 = ' checked'; |
||
| 180 | } |
||
| 181 | elseif (\XOOPS_CENTERBLOCK_LEFT === $i->getVar('side')) { |
||
| 182 | $ssel2 = ' checked'; |
||
| 183 | } |
||
| 184 | elseif (\XOOPS_CENTERBLOCK_RIGHT === $i->getVar('side')) { |
||
| 185 | $ssel4 = ' checked'; |
||
| 186 | } |
||
| 187 | elseif (\XOOPS_CENTERBLOCK_CENTER === $i->getVar('side')) { |
||
| 188 | $ssel3 = ' checked'; |
||
| 189 | } |
||
| 190 | elseif (\XOOPS_CENTERBLOCK_BOTTOMLEFT === $i->getVar('side')) { |
||
| 191 | $ssel5 = ' checked'; |
||
| 192 | } |
||
| 193 | elseif (\XOOPS_CENTERBLOCK_BOTTOMRIGHT === $i->getVar('side')) { |
||
| 194 | $ssel6 = ' checked'; |
||
| 195 | } |
||
| 196 | elseif (\XOOPS_CENTERBLOCK_BOTTOM === $i->getVar('side')) { |
||
| 197 | $ssel7 = ' checked'; |
||
| 198 | } |
||
| 199 | if ('' === $i->getVar('title')) { |
||
| 200 | $title = ' '; |
||
| 201 | } |
||
| 202 | else { |
||
| 203 | $title = $i->getVar('title'); |
||
| 204 | } |
||
| 205 | $name = $i->getVar('name'); |
||
| 206 | echo "<tr valign='top'><td class='$class' align='center'><input type='text' name='title[" |
||
| 207 | . $i->getVar('bid') |
||
| 208 | . "]' value='" |
||
| 209 | . $title |
||
| 210 | . "'></td><td class='$class' align='center' nowrap='nowrap'> |
||
| 211 | <div align='center' > |
||
| 212 | <input type='radio' name='side[" |
||
| 213 | . $i->getVar('bid') |
||
| 214 | . "]' value='" |
||
| 215 | . \XOOPS_CENTERBLOCK_LEFT |
||
| 216 | . "'$ssel2> |
||
| 217 | <input type='radio' name='side[" |
||
| 218 | . $i->getVar('bid') |
||
| 219 | . "]' value='" |
||
| 220 | . \XOOPS_CENTERBLOCK_CENTER |
||
| 221 | . "'$ssel3> |
||
| 222 | <input type='radio' name='side[" |
||
| 223 | . $i->getVar('bid') |
||
| 224 | . "]' value='" |
||
| 225 | . \XOOPS_CENTERBLOCK_RIGHT |
||
| 226 | . "'$ssel4> |
||
| 227 | </div> |
||
| 228 | <div> |
||
| 229 | <span style='float:right;'><input type='radio' name='side[" |
||
| 230 | . $i->getVar('bid') |
||
| 231 | . "]' value='" |
||
| 232 | . \XOOPS_SIDEBLOCK_RIGHT |
||
| 233 | . "'$ssel1></span> |
||
| 234 | <div align='left'><input type='radio' name='side[" |
||
| 235 | . $i->getVar('bid') |
||
| 236 | . "]' value='" |
||
| 237 | . \XOOPS_SIDEBLOCK_LEFT |
||
| 238 | . "'$ssel0></div> |
||
| 239 | </div> |
||
| 240 | <div align='center'> |
||
| 241 | <input type='radio' name='side[" |
||
| 242 | . $i->getVar('bid') |
||
| 243 | . "]' value='" |
||
| 244 | . \XOOPS_CENTERBLOCK_BOTTOMLEFT |
||
| 245 | . "'$ssel5> |
||
| 246 | <input type='radio' name='side[" |
||
| 247 | . $i->getVar('bid') |
||
| 248 | . "]' value='" |
||
| 249 | . \XOOPS_CENTERBLOCK_BOTTOM |
||
| 250 | . "'$ssel7> |
||
| 251 | <input type='radio' name='side[" |
||
| 252 | . $i->getVar('bid') |
||
| 253 | . "]' value='" |
||
| 254 | . \XOOPS_CENTERBLOCK_BOTTOMRIGHT |
||
| 255 | . "'$ssel6> |
||
| 256 | </div> |
||
| 257 | </td><td class='$class' align='center'><input type='text' name='weight[" |
||
| 258 | . $i->getVar('bid') |
||
| 259 | . "]' value='" |
||
| 260 | . $i->getVar('weight') |
||
| 261 | . "' size='5' maxlength='5'></td><td class='$class' align='center' nowrap><input type='radio' name='visible[" |
||
| 262 | . $i->getVar('bid') |
||
| 263 | . "]' value='1'$sel1>" |
||
| 264 | . _YES |
||
| 265 | . " <input type='radio' name='visible[" |
||
| 266 | . $i->getVar('bid') |
||
| 267 | . "]' value='0'$sel0>" |
||
| 268 | . _NO |
||
| 269 | . '</td>'; |
||
| 270 | |||
| 271 | echo "<td class='$class' align='center'><select size='5' name='bmodule[" . $i->getVar('bid') . "][]' id='bmodule[" . $i->getVar('bid') . "][]' multiple='multiple'>"; |
||
| 272 | foreach ($moduleList as $k => $v) { |
||
| 273 | echo "<option value='$k'" . (\in_array($k, $modules) ? " selected='selected'" : '') . ">$v</option>"; |
||
| 274 | } |
||
| 275 | echo '</select></td>'; |
||
| 276 | |||
| 277 | echo "<td class='$class' align='center'><select size='5' name='groups[" . $i->getVar('bid') . "][]' id='groups[" . $i->getVar('bid') . "][]' multiple='multiple'>"; |
||
| 278 | foreach ($groups as $grp) { |
||
| 279 | echo "<option value='" . $grp->getVar('groupid') . "' " . (\in_array($grp->getVar('groupid'), $groupsPermissions) ? " selected='selected'" : '') . '>' . $grp->getVar('name') . '</option>'; |
||
| 280 | } |
||
| 281 | echo '</select></td>'; |
||
| 282 | |||
| 283 | // Cache lifetime |
||
| 284 | echo '<td class="' . $class . '" align="center"> <select name="bcachetime[' . $i->getVar('bid') . ']" size="1">' . $cachetimeOptions . '</select> |
||
| 285 | </td>'; |
||
| 286 | |||
| 287 | // Actions |
||
| 288 | |||
| 289 | echo "<td class='$class' align='center'> |
||
| 290 | <a href='blocksadmin.php?op=edit&bid=" . $i->getVar('bid') . "'><img src=" . $pathIcon16 . '/edit.png' . " alt='" . _EDIT . "' title='" . _EDIT . "'></a> |
||
| 291 | <a href='blocksadmin.php?op=clone&bid=" . $i->getVar('bid') . "'><img src=" . $pathIcon16 . '/editcopy.png' . " alt='" . _CLONE . "' title='" . _CLONE . "'></a>"; |
||
| 292 | // if ('S' !== $i->getVar('block_type') && 'M' !== $i->getVar('block_type')) { |
||
| 293 | // echo " <a href='" . XOOPS_URL . '/modules/system/admin.php?fct=blocksadmin&op=delete&bid=' . $i->getVar('bid') . "'><img src=" . $pathIcon16 . '/delete.png' . " alt='" . _DELETE . "' title='" . _DELETE . "'> |
||
| 294 | // </a>"; |
||
| 295 | // } |
||
| 296 | |||
| 297 | // if ('S' !== $i->getVar('block_type') && 'M' !== $i->getVar('block_type')) { |
||
| 298 | if (!\in_array($i->getVar('block_type'), ['M', 'S'])) { |
||
| 299 | echo " |
||
| 300 | <a href='blocksadmin.php?op=delete&bid=" . $i->getVar('bid') . "'><img src=" . $pathIcon16 . '/delete.png' . " alt='" . _DELETE . "' title='" . _DELETE . "'> |
||
| 301 | </a>"; |
||
| 302 | } |
||
| 303 | echo " |
||
| 304 | <input type='hidden' name='oldtitle[" . $i->getVar('bid') . "]' value='" . $i->getVar('title') . "'> |
||
| 305 | <input type='hidden' name='oldside[" . $i->getVar('bid') . "]' value='" . $i->getVar('side') . "'> |
||
| 306 | <input type='hidden' name='oldweight[" . $i->getVar('bid') . "]' value='" . $i->getVar('weight') . "'> |
||
| 307 | <input type='hidden' name='oldvisible[" . $i->getVar('bid') . "]' value='" . $i->getVar('visible') . "'> |
||
| 308 | <input type='hidden' name='oldgroups[" . $i->getVar('groups') . "]' value='" . $i->getVar('groups') . "'> |
||
| 309 | <input type='hidden' name='oldbcachetime[" . $i->getVar('bid') . "]' value='" . $i->getVar('bcachetime') . "'> |
||
| 310 | <input type='hidden' name='bid[" . $i->getVar('bid') . "]' value='" . $i->getVar('bid') . "'> |
||
| 311 | </td></tr> |
||
| 312 | "; |
||
| 313 | $class = ('even' === $class) ? 'odd' : 'even'; |
||
| 314 | } |
||
| 315 | echo "<tr><td class='foot' align='center' colspan='8'> |
||
| 316 | <input type='hidden' name='op' value='order'> |
||
| 317 | " . $GLOBALS['xoopsSecurity']->getTokenHTML() . " |
||
| 318 | <input type='submit' name='submit' value='" . _SUBMIT . "'> |
||
| 319 | </td></tr></table> |
||
| 731 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..