b_marquee_comments()   B
last analyzed

Complexity

Conditions 6
Paths 8

Size

Total Lines 67
Code Lines 55

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 55
nc 8
nop 3
dl 0
loc 67
rs 8.3595
c 0
b 0
f 0

How to fix   Long Method   

Long Method

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:

1
<?php declare(strict_types=1);
2
/**
3
 * ****************************************************************************
4
 * marquee - MODULE FOR XOOPS
5
 * Copyright (c) Hervé Thouzard (https://www.herve-thouzard.com)
6
 *
7
 * You may not change or alter any portion of this comment or credits
8
 * of supporting developers from this source code or any supporting source code
9
 * which is considered copyrighted (c) material of the original comment or credit authors.
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
 *
14
 * @copyright         Hervé Thouzard (https://www.herve-thouzard.com)
15
 * @license           GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
16
 * @author            Hervé Thouzard (https://www.herve-thouzard.com)
17
 *
18
 * Version :
19
 * ****************************************************************************
20
 *
21
 * @param $limit
22
 * @param $dateFormat
23
 * @param $itemsSize
24
 *
25
 * @return array
26
 */
27
28
// Script to list system's comments - Tested with Xoops 2.0.9.3
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');
0 ignored issues
show
Bug introduced by
The method getInfo() does not exist on XoopsObject. It seems like you code against a sub-type of XoopsObject such as XoopsModule. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

59
            /** @scrutinizer ignore-call */ 
60
            $comment_config = $module->getInfo('comments');
Loading history...
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('&amp;', '&', $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