| Total Complexity | 90 |
| Total Lines | 459 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like Utility often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Utility, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 25 | class Utility extends Common\SysUtility |
||
| 26 | { |
||
| 27 | //--------------- Custom module methods ----------------------------- |
||
| 28 | /** |
||
| 29 | * Sanitize input variables |
||
| 30 | * @param string $global the input array ($_REQUEST, $_GET, $_POST) |
||
| 31 | * @param unknown_type $key the array key for variable to clean |
||
|
|
|||
| 32 | * @param string|unknown_type $default the default value to use if filter fails |
||
| 33 | * @param string $type the variable type (string, email, url, int) |
||
| 34 | * @param array $limit 'min' 'max' keys - the lower/upper limit for integer values |
||
| 35 | * @return Ambigous|number <boolean, unknown> |
||
| 36 | */ |
||
| 37 | public static function cleanVars($global, $key, $default = '', $type = 'int', $limit = null) |
||
| 38 | { |
||
| 39 | switch ($type) { |
||
| 40 | case 'string': |
||
| 41 | if (defined('FILTER_SANITIZE_ADD_SLASHES')) { |
||
| 42 | $ret = isset($global[$key]) ? filter_var($global[$key], FILTER_SANITIZE_ADD_SLASHES) : $default; |
||
| 43 | } else { |
||
| 44 | $ret = isset($global[$key]) ? filter_var($global[$key], FILTER_SANITIZE_MAGIC_QUOTES) : $default; |
||
| 45 | } |
||
| 46 | break; |
||
| 47 | case 'email': |
||
| 48 | $ret = isset($global[$key]) ? filter_var($global[$key], FILTER_SANITIZE_EMAIL) : $default; |
||
| 49 | break; |
||
| 50 | case 'url': |
||
| 51 | $ret = isset($global[$key]) ? filter_var($global[$key], FILTER_SANITIZE_URL) : $default; |
||
| 52 | break; |
||
| 53 | case 'int': |
||
| 54 | default: |
||
| 55 | $default = (int)$default; |
||
| 56 | $ret = isset($global[$key]) ? filter_var($global[$key], FILTER_SANITIZE_NUMBER_INT) : false; |
||
| 57 | if (isset($limit) && is_array($limit) && (false !== $ret)) { |
||
| 58 | if (array_key_exists('min', $limit)) { |
||
| 59 | $ret = ($ret >= $limit['min']) ? $ret : false; |
||
| 60 | } |
||
| 61 | if (array_key_exists('max', $limit)) { |
||
| 62 | $ret = ($ret <= $limit['max']) ? $ret : false; |
||
| 63 | } |
||
| 64 | } |
||
| 65 | break; |
||
| 66 | } |
||
| 67 | $ret = (false === $ret) ? $default : $ret; |
||
| 68 | |||
| 69 | return $ret; |
||
| 70 | } |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Temporary patch for error_handler processing |
||
| 74 | * @param string $msg message to display |
||
| 75 | * @param int $pages number of pages to jump back for link |
||
| 76 | * @param string $type error||info to add errorMsg CSS to display |
||
| 77 | * @deprecated |
||
| 78 | */ |
||
| 79 | public static function show_message($msg, $pages = 1, $type = 'error') |
||
| 80 | { |
||
| 81 | switch (mb_strtolower($type)) { |
||
| 82 | case 'error': |
||
| 83 | $div_class = "class='errorMsg'"; |
||
| 84 | break; |
||
| 85 | case 'info': |
||
| 86 | $div_class = ''; |
||
| 87 | break; |
||
| 88 | } |
||
| 89 | require_once XOOPS_ROOT_PATH . '/header.php'; |
||
| 90 | echo "<div{$div_class}><strong>{$xoopsConfig['sitename']} Error</strong><br><br>\n" . "Error Code: {$e_code}<br><br><br>\n" . "<strong>ERROR:</strong> {$msg}<br>\n"; |
||
| 91 | $pages = (int)$pages; |
||
| 92 | if (0 != $pages) { |
||
| 93 | $pages = '-' . abs($pages); |
||
| 94 | echo "<br><br>\n" . "[ <a href='javascript:history.go({$pages})'>" . _BACK . '</a> ]</div>'; |
||
| 95 | } |
||
| 96 | require_once XOOPS_ROOT_PATH . '/footer.php'; |
||
| 97 | } |
||
| 98 | |||
| 99 | |||
| 100 | /** |
||
| 101 | * @param $time |
||
| 102 | * @param $status |
||
| 103 | * @return string |
||
| 104 | */ |
||
| 105 | public static function newLinkGraphic($time, $status) |
||
| 106 | { |
||
| 107 | $count = 7; |
||
| 108 | $new = ''; |
||
| 109 | $startdate = (time() - (86400 * $count)); |
||
| 110 | |||
| 111 | if ($startdate < $time) { |
||
| 112 | if (1 == $status) { |
||
| 113 | $new = " <img src='" . self::getIconURL('newred.gif') . "' alt='" . _MD_MYLINKS_NEWTHISWEEK . "'>"; |
||
| 114 | } elseif (2 == $status) { |
||
| 115 | $new = " <img src='" . self::getIconURL('update.gif') . "' alt='" . _MD_MYLINKS_UPTHISWEEK . "'>"; |
||
| 116 | } |
||
| 117 | } |
||
| 118 | |||
| 119 | return $new; |
||
| 120 | } |
||
| 121 | |||
| 122 | /** |
||
| 123 | * @param $hits |
||
| 124 | * @return string |
||
| 125 | */ |
||
| 126 | public static function popGraphic($hits) |
||
| 127 | { |
||
| 128 | /** @var Mylinks\Helper $helper */ |
||
| 129 | $helper = Mylinks\Helper::getInstance(); |
||
| 130 | $retVal = ''; |
||
| 131 | |||
| 132 | if (isset($hits) && ($hits >= $helper->getConfig('popular'))) { |
||
| 133 | $retVal = " <img src='" . self::getIconURL('pop.gif') . "' alt='" . _MD_MYLINKS_POPULAR . "'>"; |
||
| 134 | } |
||
| 135 | |||
| 136 | return $retVal; |
||
| 137 | } |
||
| 138 | |||
| 139 | /* |
||
| 140 | * Reusable Link Sorting Functions |
||
| 141 | * |
||
| 142 | * @param string orderby is a shortened string for sorting |
||
| 143 | * @return string returns a dB 'ready' ORDER BY string for dB query |
||
| 144 | */ |
||
| 145 | /** |
||
| 146 | * @param $orderby |
||
| 147 | * @return string |
||
| 148 | */ |
||
| 149 | public static function convertorderbyin($orderby) |
||
| 150 | { |
||
| 151 | $orderby = (isset($orderby) && ('' != trim($orderby))) ? trim($orderby) : ''; |
||
| 152 | switch ($orderby) { |
||
| 153 | case 'titleA': |
||
| 154 | $orderby = 'title ASC'; |
||
| 155 | break; |
||
| 156 | case 'hitsA': |
||
| 157 | $orderby = 'hits ASC'; |
||
| 158 | break; |
||
| 159 | case 'ratingA': |
||
| 160 | $orderby = 'rating ASC'; |
||
| 161 | break; |
||
| 162 | case 'dateA': |
||
| 163 | $orderby = 'date ASC'; |
||
| 164 | break; |
||
| 165 | case 'titleD': |
||
| 166 | $orderby = 'title DESC'; |
||
| 167 | break; |
||
| 168 | case 'hitsD': |
||
| 169 | $orderby = 'hits DESC'; |
||
| 170 | break; |
||
| 171 | case 'ratingD': |
||
| 172 | $orderby = 'rating DESC'; |
||
| 173 | break; |
||
| 174 | case 'dateD': |
||
| 175 | default: |
||
| 176 | $orderby = 'date DESC'; |
||
| 177 | break; |
||
| 178 | } |
||
| 179 | |||
| 180 | return $orderby; |
||
| 181 | } |
||
| 182 | |||
| 183 | /** |
||
| 184 | * @param $orderby |
||
| 185 | * @return string |
||
| 186 | */ |
||
| 187 | public static function convertorderbytrans($orderby) |
||
| 188 | { |
||
| 189 | $orderby = (isset($orderby) && ('' != trim($orderby))) ? trim($orderby) : ''; |
||
| 190 | switch ($orderby) { |
||
| 191 | case 'title ASC': |
||
| 192 | $orderbyTrans = '' . _MD_MYLINKS_TITLEATOZ . ''; |
||
| 193 | break; |
||
| 194 | case 'hits ASC': |
||
| 195 | $orderbyTrans = '' . _MD_MYLINKS_POPULARITYLTOM . ''; |
||
| 196 | break; |
||
| 197 | case 'rating ASC': |
||
| 198 | $orderbyTrans = '' . _MD_MYLINKS_RATINGLTOH . ''; |
||
| 199 | break; |
||
| 200 | case 'date ASC': |
||
| 201 | $orderbyTrans = '' . _MD_MYLINKS_DATEOLD . ''; |
||
| 202 | break; |
||
| 203 | case 'title DESC': |
||
| 204 | $orderbyTrans = '' . _MD_MYLINKS_TITLEZTOA . ''; |
||
| 205 | break; |
||
| 206 | case 'hits DESC': |
||
| 207 | $orderbyTrans = '' . _MD_MYLINKS_POPULARITYMTOL . ''; |
||
| 208 | break; |
||
| 209 | case 'rating DESC': |
||
| 210 | $orderbyTrans = '' . _MD_MYLINKS_RATINGHTOL . ''; |
||
| 211 | break; |
||
| 212 | case 'date DESC': |
||
| 213 | default: |
||
| 214 | $orderbyTrans = '' . _MD_MYLINKS_DATENEW . ''; |
||
| 215 | break; |
||
| 216 | } |
||
| 217 | |||
| 218 | return $orderbyTrans; |
||
| 219 | } |
||
| 220 | |||
| 221 | /** |
||
| 222 | * @param $orderby |
||
| 223 | * @return string |
||
| 224 | */ |
||
| 225 | public static function convertorderbyout($orderby) |
||
| 226 | { |
||
| 227 | $orderby = (isset($orderby) && ('' != trim($orderby))) ? trim($orderby) : ''; |
||
| 228 | switch ($orderby) { |
||
| 229 | case 'title ASC': |
||
| 230 | $orderby = 'titleA'; |
||
| 231 | break; |
||
| 232 | case 'hits ASC': |
||
| 233 | $orderby = 'hitsA'; |
||
| 234 | break; |
||
| 235 | case 'rating ASC': |
||
| 236 | $orderby = 'ratingA'; |
||
| 237 | break; |
||
| 238 | case 'date ASC': |
||
| 239 | $orderby = 'dateA'; |
||
| 240 | break; |
||
| 241 | case 'title DESC': |
||
| 242 | $orderby = 'titleD'; |
||
| 243 | break; |
||
| 244 | case 'hits DESC': |
||
| 245 | $orderby = 'hitsD'; |
||
| 246 | break; |
||
| 247 | case 'rating DESC': |
||
| 248 | $orderby = 'ratingD'; |
||
| 249 | break; |
||
| 250 | case 'date DESC': |
||
| 251 | default: |
||
| 252 | $orderby = 'dateD'; |
||
| 253 | break; |
||
| 254 | } |
||
| 255 | |||
| 256 | return $orderby; |
||
| 257 | } |
||
| 258 | |||
| 259 | /** |
||
| 260 | * Update rating data for a link in dB link table to keep in sync |
||
| 261 | * with the vote dB table contents |
||
| 262 | * @param int $sel_id Listing ID to update |
||
| 263 | */ |
||
| 264 | public static function updaterating($sel_id) |
||
| 285 | } |
||
| 286 | } |
||
| 287 | |||
| 288 | //returns the total number of items in items table that are accociated with a given table $table id |
||
| 289 | /** |
||
| 290 | * @param null $sel_id |
||
| 291 | * @param string $status |
||
| 292 | * @param string $oper |
||
| 293 | * @return mixed |
||
| 294 | */ |
||
| 295 | public static function getTotalItems($sel_id = null, $status = '', $oper = '>') |
||
| 336 | } |
||
| 337 | |||
| 338 | /* |
||
| 339 | public static function getTotalItems($sel_id=NULL, $status='', $oper='>') |
||
| 340 | { |
||
| 341 | global $xoopsDB, $xoopsModule; |
||
| 342 | |||
| 343 | $sel_id = filter_var($sel_id, FILTER_VALIDATE_INT, array( 'options' => array( 'default' => 0, 'min_range' => 0))); |
||
| 344 | $count = 0; |
||
| 345 | $arr = []; |
||
| 346 | |||
| 347 | // get XoopsObjectTree for categories |
||
| 348 | $categoryHandler = $helper->getHandler('category', $xoopsModule->getVar('dirname')); |
||
| 349 | $catObjs = $categoryHandler->getAll(); |
||
| 350 | $myCatTree = new \XoopsObjectTree($catObjs, 'cid', 'pid'); |
||
| 351 | |||
| 352 | // new count routine |
||
| 353 | $childObjArray = $myCatTree->getAllChild($sel_id); |
||
| 354 | $catIds = "({$sel_id}"; |
||
| 355 | foreach ($childObjArray as $childObj) { |
||
| 356 | $catIds .= ',' . $childObj->getVar('cid'); |
||
| 357 | } |
||
| 358 | $catIds .= ')'; |
||
| 359 | $query = "SELECT COUNT(*) FROM " . $xoopsDB->prefix("mylinks_links") . " WHERE `cid` IN {$catIds}"; |
||
| 360 | if ('' !== $status) { |
||
| 361 | $status = (int)($status); |
||
| 362 | if ( preg_match($oper, "~^[!]?[<=>]{1}[=>]*$~", $match) ) { |
||
| 363 | $oper = $match[0]; |
||
| 364 | } else { |
||
| 365 | $oper = '>'; |
||
| 366 | } |
||
| 367 | // $oper = (0 == (int)($status)) ? '=': '>'; |
||
| 368 | $query .= " AND status{$oper}{$status}"; |
||
| 369 | } |
||
| 370 | $result = $xoopsDB->query($query); |
||
| 371 | list($linkCount) = $xoopsDB->fetchRow($result); |
||
| 372 | |||
| 373 | return $linkCount; |
||
| 374 | } |
||
| 375 | */ |
||
| 376 | //wanikoo |
||
| 377 | /** |
||
| 378 | * @param $aFile |
||
| 379 | * @return string |
||
| 380 | */ |
||
| 381 | public static function getStyleURL($aFile) |
||
| 382 | { |
||
| 383 | global $mylinks_theme; |
||
| 384 | $StyleURL = XOOPSMYLINKINCURL . "/{$mylinks_theme}/icons/{$aFile}"; |
||
| 385 | |||
| 386 | if (file_exists(XOOPSMYLINKINCPATH . "/{$mylinks_theme}/icons/{$aFile}")) { |
||
| 387 | return $StyleURL; |
||
| 388 | } |
||
| 389 | |||
| 390 | return XOOPSMYLINKINCURL . "/icons/{$aFile}"; |
||
| 391 | } |
||
| 392 | |||
| 393 | /** |
||
| 394 | * @param $aFile |
||
| 395 | * @return string |
||
| 396 | */ |
||
| 397 | public static function getIconURL($aFile) |
||
| 398 | { |
||
| 399 | global $mylinks_theme; |
||
| 400 | |||
| 401 | if (file_exists(XOOPSMYLINKIMGPATH . "/{$mylinks_theme}/icons/{$aFile}")) { |
||
| 402 | return XOOPSMYLINKIMGURL . "/{$mylinks_theme}/icons/{$aFile}"; |
||
| 403 | } |
||
| 404 | |||
| 405 | return XOOPSMYLINKIMGURL . "/icons/{$aFile}"; |
||
| 406 | } |
||
| 407 | |||
| 408 | /** |
||
| 409 | * @param $aFile |
||
| 410 | * @param string $subPath |
||
| 411 | * @param bool $relPath |
||
| 412 | * @return string |
||
| 413 | */ |
||
| 414 | public static function getStylePath($aFile, $subPath = '', $relPath = true) |
||
| 426 | } |
||
| 427 | |||
| 428 | /** |
||
| 429 | * @return string |
||
| 430 | */ |
||
| 431 | public static function letters() |
||
| 466 | } |
||
| 467 | |||
| 468 | /** |
||
| 469 | * @return string |
||
| 470 | */ |
||
| 471 | public static function toolbar() |
||
| 472 | { |
||
| 487 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths