| Conditions | 7 |
| Paths | 18 |
| Total Lines | 77 |
| Code Lines | 55 |
| 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 |
||
| 34 | function b_marquee_article($limit, $dateFormat, $itemsSize) |
||
| 35 | { |
||
| 36 | global $xoopsDB; |
||
|
|
|||
| 37 | include_once XOOPS_ROOT_PATH . '/modules/marquee/include/functions.php'; |
||
| 38 | require_once(XOOPS_ROOT_PATH . '/modules/article/include/functions.php'); |
||
| 39 | $block = array(); |
||
| 40 | $myts = MyTextSanitizer::getInstance(); |
||
| 41 | |||
| 42 | static $accessCats; |
||
| 43 | |||
| 44 | $artConfig = art_load_config(); |
||
| 45 | art_define_url_delimiter(); |
||
| 46 | |||
| 47 | $select = 'art_id'; |
||
| 48 | $dispTag = ''; |
||
| 49 | $from = ''; |
||
| 50 | $where = ''; |
||
| 51 | $order = 'art_time_publish DESC'; |
||
| 52 | |||
| 53 | $select .= ', cat_id, art_title, uid, art_time_publish'; |
||
| 54 | |||
| 55 | if (!isset($accessCats)) { |
||
| 56 | $permissionHandler = xoops_getModuleHandler('permission', 'article'); |
||
| 57 | $accessCats = $permissionHandler->getCategories('access'); |
||
| 58 | } |
||
| 59 | $allowedCats = $accessCats; |
||
| 60 | |||
| 61 | $query = "SELECT $select FROM " . art_DB_prefix('article') . $from; |
||
| 62 | $query .= ' WHERE cat_id IN (' . implode(',', $allowedCats) . ') AND art_time_publish >0 ' . $where; |
||
| 63 | $query .= ' ORDER BY ' . $order; |
||
| 64 | $query .= ' LIMIT 0, ' . $limit; |
||
| 65 | if (!$result = $xoopsDB->query($query)) { |
||
| 66 | return false; |
||
| 67 | } |
||
| 68 | $rows = array(); |
||
| 69 | $author = array(); |
||
| 70 | while ($row = $xoopsDB->fetchArray($result)) { |
||
| 71 | $rows[] = $row; |
||
| 72 | $author[$row['uid']] = 1; |
||
| 73 | } |
||
| 74 | if (count($rows) < 1) { |
||
| 75 | return false; |
||
| 76 | } |
||
| 77 | $authorName = XoopsUser::getUnameFromId(array_keys($author)); |
||
| 78 | |||
| 79 | $arts = array(); |
||
| 80 | $uids = array(); |
||
| 81 | $cids = array(); |
||
| 82 | $articleHandler = xoops_getModuleHandler('article', 'article'); |
||
| 83 | foreach ($rows as $row) { |
||
| 84 | $article = $articleHandler->create(false); |
||
| 85 | $article->assignVars($row); |
||
| 86 | $_art = array(); |
||
| 87 | foreach ($row as $tag => $val) { |
||
| 88 | $_art[$tag] = @$article->getVar($tag); |
||
| 89 | } |
||
| 90 | $_art['author'] = $authorName[$row['uid']]; |
||
| 91 | |||
| 92 | $_art['date'] = $article->getTime($dateFormat); |
||
| 93 | |||
| 94 | $titlelength = $itemsSize + 3; |
||
| 95 | $_art['title'] = xoops_substr($_art['art_title'], 0, $titlelength); |
||
| 96 | |||
| 97 | $_art['category'] = ''; |
||
| 98 | |||
| 99 | $delimiter = '/'; |
||
| 100 | $_art['link'] = "<a href=\"" . XOOPS_URL . "modules/article/view.article.php$delimiter" . $_art['art_id'] . '/c' . $_art['cat_id'] . "\"><strong>" . $_art['art_title'] . '</strong></a>'; |
||
| 101 | |||
| 102 | $arts[] = $_art; |
||
| 103 | unset($article, $_art); |
||
| 104 | $cids[$row['cat_id']] = 1; |
||
| 105 | } |
||
| 106 | |||
| 107 | $block = $arts; |
||
| 108 | |||
| 109 | return $block; |
||
| 110 | } |
||
| 111 |
Instead of relying on
globalstate, we recommend one of these alternatives:1. Pass all data via parameters
2. Create a class that maintains your state