b_marquee_article()   B
last analyzed

Complexity

Conditions 7
Paths 18

Size

Total Lines 64
Code Lines 54

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 54
c 0
b 0
f 0
nc 18
nop 3
dl 0
loc 64
rs 8.0703

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
//  ------------------------------------------------------------------------ //
29
//  Article plugin for Marquee 2.4                                           //
30
//  written by Defkon1 [defkon1 at gmail dot com]                            //
31
//  ------------------------------------------------------------------------ //
32
use XoopsModules\Article;
0 ignored issues
show
Bug introduced by
The type XoopsModules\Article was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
33
34
/**
35
 * @param $limit
36
 * @param $dateFormat
37
 * @param $itemsSize
38
 * @return array|false
39
 */
40
function b_marquee_article($limit, $dateFormat, $itemsSize)
41
{
42
    global $xoopsDB;
43
    //    require_once XOOPS_ROOT_PATH . '/modules/marquee/class/Utility.php';
44
    require_once XOOPS_ROOT_PATH . '/modules/article/include/functions.php';
45
    $block = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $block is dead and can be removed.
Loading history...
46
    $myts  = \MyTextSanitizer::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $myts is dead and can be removed.
Loading history...
47
    static $accessCats;
48
    $artConfig = art_load_config();
0 ignored issues
show
Unused Code introduced by
The assignment to $artConfig is dead and can be removed.
Loading history...
Bug introduced by
The function art_load_config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

48
    $artConfig = /** @scrutinizer ignore-call */ art_load_config();
Loading history...
49
    art_define_url_delimiter();
0 ignored issues
show
Bug introduced by
The function art_define_url_delimiter was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

49
    /** @scrutinizer ignore-call */ 
50
    art_define_url_delimiter();
Loading history...
50
    $select  = 'art_id';
51
    $dispTag = '';
0 ignored issues
show
Unused Code introduced by
The assignment to $dispTag is dead and can be removed.
Loading history...
52
    $from    = '';
53
    $where   = '';
54
    $order   = 'art_time_publish DESC';
55
    $select  .= ', cat_id, art_title, uid, art_time_publish';
56
    if (null === $accessCats) {
57
        $permissionHandler = Article\Helper::getInstance()->getHandler('Permission');
0 ignored issues
show
Bug introduced by
The type XoopsModules\Article\Helper was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
58
        $accessCats        = $permissionHandler->getCategories('access');
59
    }
60
    $allowedCats = $accessCats;
61
    $sql       = "SELECT $select FROM " . art_DB_prefix('article') . $from;
0 ignored issues
show
Bug introduced by
The function art_DB_prefix was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

61
    $sql       = "SELECT $select FROM " . /** @scrutinizer ignore-call */ art_DB_prefix('article') . $from;
Loading history...
62
    $sql       .= ' WHERE cat_id IN (' . implode(',', $allowedCats) . ') AND art_time_publish >0 ' . $where;
63
    $sql       .= ' ORDER BY ' . $order;
64
    $sql       .= ' LIMIT 0, ' . $limit;
65
    $result = $xoopsDB->query($sql);
66
    if (!$xoopsDB->isResultSet($result)) {
67
        return false;
68
    }
69
    $rows   = [];
70
    $author = [];
71
    while (false !== ($row = $xoopsDB->fetchArray($result))) {
72
        $rows[]              = $row;
73
        $author[$row['uid']] = 1;
74
    }
75
    if (count($rows) < 1) {
76
        return false;
77
    }
78
    $authorName     = \XoopsUser::getUnameFromId(array_keys($author));
0 ignored issues
show
Bug introduced by
array_keys($author) of type array is incompatible with the type integer expected by parameter $userid of XoopsUser::getUnameFromId(). ( Ignorable by Annotation )

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

78
    $authorName     = \XoopsUser::getUnameFromId(/** @scrutinizer ignore-type */ array_keys($author));
Loading history...
79
    $arts           = [];
80
    $uids           = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $uids is dead and can be removed.
Loading history...
81
    $cids           = [];
82
    $articleHandler = Article\Helper::getInstance()->getHandler('Article');
83
    foreach ($rows as $row) {
84
        $article = $articleHandler->create(false);
85
        $article->assignVars($row);
86
        $_art = [];
87
        foreach ($row as $tag => $val) {
88
            $_art[$tag] = @$article->getVar($tag);
89
        }
90
        $_art['author']   = $authorName[$row['uid']];
91
        $_art['date']     = $article->getTime($dateFormat);
92
        $titlelength      = $itemsSize + 3;
93
        $_art['title']    = xoops_substr($_art['art_title'], 0, $titlelength);
94
        $_art['category'] = '';
95
        $delimiter        = '/';
96
        $_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>';
97
        $arts[]           = $_art;
98
        unset($article, $_art);
99
        $cids[$row['cat_id']] = 1;
100
    }
101
    $block = $arts;
102
103
    return $block;
104
}
105