Passed
Push — master ( dcbd4a...4bb7b0 )
by Michael
02:37
created

b_marquee_article()   C

Complexity

Conditions 7
Paths 18

Size

Total Lines 76
Code Lines 53

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 53
c 0
b 0
f 0
nc 18
nop 3
dl 0
loc 76
rs 6.5808

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
2
/**
3
 * ****************************************************************************
4
 * marquee - MODULE FOR XOOPS
5
 * Copyright (c) Hervé Thouzard (http://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 (http://www.herve-thouzard.com)
15
 * @license           http://www.fsf.org/copyleft/gpl.html GNU public license
16
 * @package           marquee
17
 * @author            Hervé Thouzard (http://www.herve-thouzard.com)
18
 *
19
 * Version :
20
 * ****************************************************************************
21
 *
22
 * @param $limit
23
 * @param $dateFormat
24
 * @param $itemsSize
25
 *
26
 * @return array
27
 */
28
29
//  ------------------------------------------------------------------------ //
30
//  Article plugin for Marquee 2.4                                           //
31
//  written by Defkon1 [defkon1 at gmail dot com]                            //
32
//  ------------------------------------------------------------------------ //
33
34
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...
35
36
/**
37
 * @param $limit
38
 * @param $dateFormat
39
 * @param $itemsSize
40
 * @return array|false
41
 */
42
function b_marquee_article($limit, $dateFormat, $itemsSize)
43
{
44
    global $xoopsDB;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
45
//    require_once XOOPS_ROOT_PATH . '/modules/marquee/class/Utility.php';
46
    require_once XOOPS_ROOT_PATH . '/modules/article/include/functions.php';
0 ignored issues
show
Bug introduced by
The constant XOOPS_ROOT_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
47
    $block = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $block is dead and can be removed.
Loading history...
48
    $myts  = \MyTextSanitizer::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $myts is dead and can be removed.
Loading history...
Bug introduced by
The type MyTextSanitizer 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...
49
50
    static $accessCats;
51
52
    $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

52
    $artConfig = /** @scrutinizer ignore-call */ art_load_config();
Loading history...
53
    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

53
    /** @scrutinizer ignore-call */ 
54
    art_define_url_delimiter();
Loading history...
54
55
    $select  = 'art_id';
56
    $dispTag = '';
0 ignored issues
show
Unused Code introduced by
The assignment to $dispTag is dead and can be removed.
Loading history...
57
    $from    = '';
58
    $where   = '';
59
    $order   = 'art_time_publish DESC';
60
61
    $select .= ', cat_id, art_title, uid, art_time_publish';
62
63
    if (null === $accessCats) {
64
        $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...
65
        $accessCats        = $permissionHandler->getCategories('access');
66
    }
67
    $allowedCats = $accessCats;
68
69
    $query = "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

69
    $query = "SELECT $select FROM " . /** @scrutinizer ignore-call */ art_DB_prefix('article') . $from;
Loading history...
70
    $query .= ' WHERE cat_id IN (' . implode(',', $allowedCats) . ') AND art_time_publish >0 ' . $where;
71
    $query .= ' ORDER BY ' . $order;
72
    $query .= ' LIMIT 0, ' . $limit;
73
    if (!$result = $xoopsDB->query($query)) {
74
        return false;
75
    }
76
    $rows   = [];
77
    $author = [];
78
    while (false !== ($row = $xoopsDB->fetchArray($result))) {
79
        $rows[]              = $row;
80
        $author[$row['uid']] = 1;
81
    }
82
    if (count($rows) < 1) {
83
        return false;
84
    }
85
    $authorName = XoopsUser::getUnameFromId(array_keys($author));
0 ignored issues
show
Bug introduced by
The type XoopsUser 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...
86
87
    $arts           = [];
88
    $uids           = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $uids is dead and can be removed.
Loading history...
89
    $cids           = [];
90
    $articleHandler = Article\Helper::getInstance()->getHandler('Article');
91
    foreach ($rows as $row) {
92
        $article = $articleHandler->create(false);
93
        $article->assignVars($row);
94
        $_art = [];
95
        foreach ($row as $tag => $val) {
96
            $_art[$tag] = @$article->getVar($tag);
97
        }
98
        $_art['author'] = $authorName[$row['uid']];
99
100
        $_art['date'] = $article->getTime($dateFormat);
101
102
        $titlelength   = $itemsSize + 3;
103
        $_art['title'] = xoops_substr($_art['art_title'], 0, $titlelength);
0 ignored issues
show
Bug introduced by
The function xoops_substr 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

103
        $_art['title'] = /** @scrutinizer ignore-call */ xoops_substr($_art['art_title'], 0, $titlelength);
Loading history...
104
105
        $_art['category'] = '';
106
107
        $delimiter    = '/';
108
        $_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>';
0 ignored issues
show
Bug introduced by
The constant XOOPS_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
109
110
        $arts[] = $_art;
111
        unset($article, $_art);
112
        $cids[$row['cat_id']] = 1;
113
    }
114
115
    $block = $arts;
116
117
    return $block;
118
}
119