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