Conditions | 13 |
Paths | 26 |
Total Lines | 88 |
Code Lines | 64 |
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 |
||
29 | function b_marquee_newbb($limit, $dateFormat, $itemsSize) |
||
30 | { |
||
31 | include_once XOOPS_ROOT_PATH . '/modules/marquee/include/functions.php'; |
||
32 | $block = array(); |
||
33 | |||
34 | $moduleHandler = xoops_getHandler('module'); |
||
35 | $newbb = $moduleHandler->getByDirname('newbb'); |
||
36 | $newbbVersion = (int)$newbb->getInfo('version'); |
||
37 | |||
38 | if ($newbbVersion >= 2) { |
||
39 | $order = 't.topic_time'; |
||
40 | $forumHandler = xoops_getModuleHandler('forum', 'newbb'); |
||
41 | $moduleHandler = xoops_getHandler('module'); |
||
42 | $newbb = $moduleHandler->getByDirname('newbb'); |
||
43 | |||
44 | if (!isset($newbbConfig)) { |
||
|
|||
45 | $configHandler = xoops_getHandler('config'); |
||
46 | $newbbConfig = &$configHandler->getConfigsByCat(0, $newbb->getVar('mid')); |
||
47 | } |
||
48 | |||
49 | if (!isset($access_forums)) { |
||
50 | $access_forums = $forumHandler->getForums(0, 'access'); // get all accessible forums |
||
51 | } |
||
52 | $validForums = array_keys($access_forums); |
||
53 | $forumCriteria = ' AND t.forum_id IN (' . implode(',', $validForums) . ')'; |
||
54 | unset($access_forums); |
||
55 | $approveCriteria = ' AND t.approved = 1 AND p.approved = 1'; |
||
56 | $db = XoopsDatabaseFactory::getDatabaseConnection(); |
||
57 | $query = 'SELECT t.*, f.forum_name, f.allow_subject_prefix, p.post_id, p.icon, p.uid, p.poster_name, u.uname, u.name FROM ' . $db->prefix('bb_topics') . ' t, ' . $db->prefix('bb_forums') . ' f, ' . $db->prefix('bb_posts') . ' p LEFT JOIN ' . $db->prefix('users') . ' u ON u.uid = p.uid WHERE f.forum_id=t.forum_id ' . $forumCriteria . $approveCriteria . ' AND t.topic_last_post_id=p.post_id ORDER BY ' . $order . ' DESC'; |
||
58 | $result = $db->query($query, $limit, 0); |
||
59 | if (!$result) { |
||
60 | return ''; |
||
61 | } |
||
62 | $rows = array(); |
||
63 | while ($row = $db->fetchArray($result)) { |
||
64 | $rows[] = $row; |
||
65 | } |
||
66 | if (count($rows) < 1) { |
||
67 | return false; |
||
68 | } |
||
69 | $myts = MyTextSanitizer::getInstance(); |
||
70 | |||
71 | foreach ($rows as $arr) { |
||
72 | $title = $myts->htmlSpecialChars($arr['topic_title']); |
||
73 | if ($itemsSize > 0) { |
||
74 | $title = xoops_substr($title, 0, $itemsSize + 3); |
||
75 | } |
||
76 | |||
77 | $block[] = array( |
||
78 | 'date' => formatTimestamp($arr['topic_time'], $dateFormat), |
||
79 | 'category' => $arr['forum_name'], |
||
80 | 'author' => $arr['uid'], |
||
81 | 'title' => $title, |
||
82 | 'link' => "<a href='" . XOOPS_URL . '/modules/newbb/viewtopic.php?topic_id=' . $arr['topic_id'] . '&post_id=' . $arr['post_id'] . '#forumpost' . $arr['post_id'] . "'>" . $title . '</a>' |
||
83 | ); |
||
84 | } |
||
85 | } else { // Newbb 1 |
||
86 | $db = XoopsDatabaseFactory::getDatabaseConnection(); |
||
87 | $myts = MyTextSanitizer::getInstance(); |
||
88 | $order = 't.topic_time'; |
||
89 | $time = $tmpuser = ''; |
||
90 | $query = 'SELECT t.topic_id, t.topic_title, t.topic_last_post_id, t.topic_time, t.topic_views, t.topic_replies, t.forum_id, f.forum_name FROM ' . $db->prefix('bb_topics') . ' t, ' . $db->prefix('bb_forums') . ' f WHERE f.forum_id=t.forum_id AND f.forum_type <> 1 ORDER BY ' . $order . ' DESC'; |
||
91 | if (!$result = $db->query($query, $limit, 0)) { |
||
92 | return ''; |
||
93 | } |
||
94 | while ($arr = $db->fetchArray($result)) { |
||
95 | $lastpostername = $db->query('SELECT post_id, uid FROM ' . $db->prefix('bb_posts') . ' WHERE post_id = ' . $arr['topic_last_post_id']); |
||
96 | while ($tmpdb = $db->fetchArray($lastpostername)) { |
||
97 | $tmpuser = XoopsUser::getUnameFromId($tmpdb['uid']); |
||
98 | $time = formatTimestamp($arr['topic_time'], $dateFormat); |
||
99 | } |
||
100 | $title = $myts->htmlSpecialChars($arr['topic_title']); |
||
101 | if ($itemsSize > 0) { |
||
102 | $title = xoops_substr($title, 0, $itemsSize + 3); |
||
103 | } |
||
104 | |||
105 | $block[] = array( |
||
106 | 'date' => $time, |
||
107 | 'category' => $arr['forum_name'], |
||
108 | 'author' => $tmpuser, |
||
109 | 'title' => $title, |
||
110 | 'link' => "<a href='" . XOOPS_URL . '/modules/newbb/viewtopic.php?topic_id=' . $arr['topic_id'] . '&forum=' . $arr['forum_id'] . '&post_id=' . $arr['topic_last_post_id'] . '#forumpost' . $arr['topic_last_post_id'] . "'>" . $title . '</a>' |
||
111 | ); |
||
112 | } |
||
113 | } |
||
114 | |||
115 | return $block; |
||
116 | } |
||
117 |
This check marks calls to
isset(...)
orempty(...)
that are found before the variable itself is defined. These will always have the same result.This is likely the result of code being shifted around. Consider removing these calls.