Conditions | 6 |
Paths | 8 |
Total Lines | 67 |
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 declare(strict_types=1); |
||
29 | function b_marquee_comments($limit, $dateFormat, $itemsSize) |
||
30 | { |
||
31 | // require_once XOOPS_ROOT_PATH . '/modules/marquee/class/Utility.php'; |
||
32 | require XOOPS_ROOT_PATH . '/include/comment_constants.php'; |
||
33 | $block = []; |
||
34 | $status = XOOPS_COMMENT_APPROVEUSER; |
||
35 | $module = 0; |
||
36 | /** @var \XoopsModuleHandler $moduleHandler */ |
||
37 | $moduleHandler = xoops_getHandler('module'); |
||
38 | /** @var \XoopsCommentHandler $commentHandler */ |
||
39 | $commentHandler = xoops_getHandler('comment'); |
||
40 | $criteria = new \CriteriaCompo(); |
||
41 | if ($status > 0) { |
||
42 | $criteria->add(new \Criteria('com_status', $status)); |
||
43 | } |
||
44 | if ($module > 0) { |
||
45 | $criteria->add(new \Criteria('com_modid', $module)); |
||
46 | } |
||
47 | $total = $commentHandler->getCount($criteria); |
||
48 | if ($total > 0) { |
||
49 | $start = 0; |
||
50 | $sort = 'com_created'; |
||
51 | $order = 'DESC'; |
||
52 | $criteria->setSort($sort); |
||
53 | $criteria->setOrder($order); |
||
54 | $criteria->setLimit($limit); |
||
55 | $criteria->setStart($start); |
||
56 | $comments = $commentHandler->getObjects($criteria, true); |
||
57 | foreach (array_keys($comments) as $i) { |
||
58 | $module = $moduleHandler->get($comments[$i]->getVar('com_modid')); |
||
59 | $comment_config = $module->getInfo('comments'); |
||
|
|||
60 | if ($itemsSize > 0) { |
||
61 | $title = xoops_substr($comments[$i]->getVar('com_title'), 0, $itemsSize + 3); |
||
62 | } else { |
||
63 | $title = $comments[$i]->getVar('com_title'); |
||
64 | } |
||
65 | $block[] = [ |
||
66 | 'date' => formatTimestamp($comments[$i]->getVar('com_created'), $dateFormat), |
||
67 | 'category' => '', |
||
68 | 'author' => $comments[$i]->getVar('com_uid'), |
||
69 | 'title' => $title, |
||
70 | 'link' => "<a href='" |
||
71 | . XOOPS_URL |
||
72 | . '/modules/' |
||
73 | . $module->getVar('dirname') |
||
74 | . '/' |
||
75 | . $comment_config['pageName'] |
||
76 | . '?' |
||
77 | . $comment_config['itemName'] |
||
78 | . '=' |
||
79 | . $comments[$i]->getVar('com_itemid') |
||
80 | . '&com_id=' |
||
81 | . $comments[$i]->getVar('com_id') |
||
82 | . '&com_rootid=' |
||
83 | . $comments[$i]->getVar('com_rootid') |
||
84 | . '&com_mode=thread&' |
||
85 | . \str_replace('&', '&', $comments[$i]->getVar('com_exparams')) |
||
86 | . '#comment' |
||
87 | . $comments[$i]->getVar('com_id') |
||
88 | . "'>" |
||
89 | . $title |
||
90 | . '</a>', |
||
91 | ]; |
||
92 | } |
||
93 | } |
||
94 | |||
95 | return $block; |
||
96 | } |
||
97 |