Completed
Push — master ( 6fba47...e5fe96 )
by Michael
02:38
created

plugin.tag.php ➔ lexikon_tag_iteminfo()   C

Complexity

Conditions 7
Paths 10

Size

Total Lines 44
Code Lines 20

Duplication

Lines 44
Ratio 100 %

Importance

Changes 0
Metric Value
cc 7
eloc 20
nc 10
nop 1
dl 44
loc 44
rs 6.7272
c 0
b 0
f 0
1
<?php
2
/**
3
 * Tag info
4
 *
5
 * @copyright      XOOPS Project (http://xoops.org)
6
 * @license        http://www.fsf.org/copyleft/gpl.html GNU public license
7
 * @author         Taiwen Jiang (phppp or D.J.) <[email protected]>
8
 * @since          1.00
9
 * @package        module::tag
10
 */
11
// defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
12
/**
13
 * Get item fields:
14
 * title
15
 * content
16
 * time
17
 * link
18
 * uid
19
 * uname
20
 * tags
21
 *
22
 * @var array $items associative array of items: [modid][catid][itemid]
23
 *
24
 * @return boolean
25
 *
0 ignored issues
show
Documentation introduced by
Should the return type not be false|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
26
 */
27
28 View Code Duplication
function lexikon_tag_iteminfo(&$items)
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in 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...
29
{
30
    if (empty($items) || !is_array($items)) {
31
        return false;
32
    }
33
34
    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...
35
    $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...
36
37
    $items_id = array();
38
39
    foreach (array_keys($items) as $cat_id) {
40
        // Some handling here to build the link upon catid
41
        // If catid is not used, just skip it
42
        foreach (array_keys($items[$cat_id]) as $item_id) {
43
            // In article, the item_id is "art_id"
44
            $items_id[] = (int)$item_id;
45
        }
46
    }
47
48
    foreach (array_keys($items) as $cat_id) {
49
        foreach (array_keys($items[$cat_id]) as $item_id) {
50
            $sql = 'SELECT  l.entryID, l.categoryID, l.term AS ltitle, l.definition, l.uid, l.datesub, l.offline, c.name AS cname FROM '
51
                   . $xoopsDB->prefix('lxentries')
52
                   . ' l, '
53
                   . $xoopsDB->prefix('lxcategories')
54
                   . ' c WHERE l.entryID='
55
                   . $item_id
56
                   . ' AND l.categoryID=c.categoryID AND l.offline=0 ORDER BY l.datesub DESC';
57
            //$sql = "SELECT  l.entryID, l.categoryID, l.term as ltitle, l.definition, l.uid, l.datesub, l.offline,l.item_tag, c.name as cname FROM ".$xoopsDB->prefix('lxentries')." l, ".$xoopsDB->prefix('lxcategories')." c WHERE l.entryID=".$item_id." AND l.categoryID=c.categoryID AND l.offline=0 ORDER BY l.datesub DESC";
0 ignored issues
show
Unused Code Comprehensibility introduced by
61% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
58
            $result                   = $xoopsDB->query($sql);
59
            $row                      = $xoopsDB->fetchArray($result);
60
            $items[$cat_id][$item_id] = array(
61
                'title'   => $row['ltitle'],
62
                'uid'     => $row['uid'],
63
                'link'    => "entry.php?entryID=$item_id",
64
                'time'    => $row['datesub'],
65
                //"tags"       => $row['item_tag'], // optional
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
66
                //"content"    => $myts->displayTarea( $row['definition'], 0 ),
0 ignored issues
show
Unused Code Comprehensibility introduced by
69% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
67
                'content' => $row['definition']
68
            );
69
        }
70
    }
71
}
72
73