Completed
Push — master ( 66731e...5478d6 )
by Michael
02:20
created

article.php ➔ b_marquee_article()   C

Complexity

Conditions 7
Paths 18

Size

Total Lines 77
Code Lines 55

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 55
nc 18
nop 3
dl 0
loc 77
rs 6.5755
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
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 : $Id:
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
function b_marquee_article($limit, $dateFormat, $itemsSize)
35
{
36
    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...
37
    include_once XOOPS_ROOT_PATH . '/modules/marquee/include/functions.php';
38
    require_once(XOOPS_ROOT_PATH . '/modules/article/include/functions.php');
39
    $block = array();
0 ignored issues
show
Unused Code introduced by
$block is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
40
    $myts  = MyTextSanitizer::getInstance();
0 ignored issues
show
Unused Code introduced by
$myts is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
41
42
    static $accessCats;
43
44
    $artConfig = art_load_config();
0 ignored issues
show
Unused Code introduced by
$artConfig is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
45
    art_define_url_delimiter();
46
47
    $select   = 'art_id';
48
    $dispTag = '';
0 ignored issues
show
Unused Code introduced by
$dispTag is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
49
    $from     = '';
50
    $where    = '';
51
    $order    = 'art_time_publish DESC';
52
53
    $select .= ', cat_id, art_title, uid, art_time_publish';
54
55
    if (!isset($accessCats)) {
56
        $permissionHandler = xoops_getModuleHandler('permission', 'article');
57
        $accessCats        = $permissionHandler->getCategories('access');
58
    }
59
    $allowedCats = $accessCats;
60
61
    $query = "SELECT $select FROM " . art_DB_prefix('article') . $from;
62
    $query .= ' WHERE cat_id IN (' . implode(',', $allowedCats) . ') AND art_time_publish >0 ' . $where;
63
    $query .= ' ORDER BY ' . $order;
64
    $query .= ' LIMIT 0, ' . $limit;
65
    if (!$result = $xoopsDB->query($query)) {
66
        return false;
67
    }
68
    $rows   = array();
69
    $author = array();
70
    while ($row = $xoopsDB->fetchArray($result)) {
71
        $rows[]              = $row;
72
        $author[$row['uid']] = 1;
73
    }
74
    if (count($rows) < 1) {
75
        return false;
76
    }
77
    $authorName = XoopsUser::getUnameFromId(array_keys($author));
78
79
    $arts            = array();
80
    $uids            = array();
0 ignored issues
show
Unused Code introduced by
$uids is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
81
    $cids            = array();
82
    $articleHandler = xoops_getModuleHandler('article', 'article');
83
    foreach ($rows as $row) {
84
        $article = $articleHandler->create(false);
85
        $article->assignVars($row);
86
        $_art = array();
87
        foreach ($row as $tag => $val) {
88
            $_art[$tag] = @$article->getVar($tag);
89
        }
90
        $_art['author'] = $authorName[$row['uid']];
91
92
        $_art['date'] = $article->getTime($dateFormat);
93
94
        $titlelength   = $itemsSize + 3;
95
        $_art['title'] = xoops_substr($_art['art_title'], 0, $titlelength);
96
97
        $_art['category'] = '';
98
99
        $delimiter    = '/';
100
        $_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>';
101
102
        $arts[] = $_art;
103
        unset($article, $_art);
104
        $cids[$row['cat_id']] = 1;
105
    }
106
107
    $block = $arts;
108
109
    return $block;
110
}
111