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

wfsection.php ➔ b_marquee_wfsection()   B

Complexity

Conditions 6
Paths 2

Size

Total Lines 40
Code Lines 29

Duplication

Lines 19
Ratio 47.5 %

Importance

Changes 0
Metric Value
cc 6
eloc 29
nc 2
nop 3
dl 19
loc 40
rs 8.439
c 0
b 0
f 0
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
// Script to list recent articles from wfsection 1 & 2
30
function b_marquee_wfsection($limit, $dateFormat, $itemsSize)
31
{
32
    include_once XOOPS_ROOT_PATH . '/modules/marquee/include/functions.php';
33
    $block = array();
34
35
    $myts              = MyTextSanitizer::getInstance();
36
    $moduleHandler    = xoops_getHandler('module');
37
    $wfsection         = $moduleHandler->getByDirname('wfsection');
38
    $wfsectionVersion = (int)$wfsection->getInfo('version');
39
40
    if ($wfsectionVersion >= 2) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
41
    } else { // wfsection 1
42
        include_once XOOPS_ROOT_PATH . '/modules/wfsection/include/groupaccess.php';
43
        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...
44
        $sql    = 'SELECT articleid, title, published, expired, counter, groupid, uid FROM ' . $xoopsDB->prefix('wfs_article') . ' WHERE published < ' . time() . ' AND published > 0 AND (expired = 0 OR expired > ' . time() . ') AND noshowart = 0 AND offline = 0 ORDER BY published DESC';
45
        $result = $xoopsDB->query($sql, $limit, 0);
46 View Code Duplication
        while ($myrow = $xoopsDB->fetchArray($result)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
47
            if (checkAccess($myrow['groupid'])) {
48
                $wfs   = array();
0 ignored issues
show
Unused Code introduced by
$wfs 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
                $title = $myts->htmlSpecialChars($myrow['title']);
50
                if (!XOOPS_USE_MULTIBYTES) {
51
                    if ($itemsSize > 0) {
52
                        $title = $myts->htmlSpecialChars(substr($myrow['title'], 0, $itemsSize));
53
                    } else {
54
                        $title = $myts->htmlSpecialChars($myrow['title']);
55
                    }
56
                }
57
                $block[] = array(
58
                    'date'     => formatTimestamp($myrow['published'], $dateFormat),
59
                    'category' => '',
60
                    'author'   => XoopsUser::getUnameFromId($myrow['uid']),
61
                    'title'    => $title,
62
                    'link'     => "<a href='" . XOOPS_URL . '/modules/wfsection/article.php?articleid=' . $myrow['articleid'] . "'>" . $title . '</a>'
63
                );
64
            }
65
        }
66
    } // wfsection 1 ou 2 ?
67
68
    return $block;
69
}
70