Completed
Pull Request — master (#8)
by Michael
02:48
created

data.inc.php ➔ mylinks_num()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 8
nc 2
nop 0
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
1
<?php
2
// $Id: data.inc.php 8112 2011-11-06 13:41:14Z beckmi $
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% 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...
3
4
// 2005-10-01 K.OHWADA
5
// category, counter
6
7
// 2005-03-28 K.OHWADA
8
// bug fix: forget to declare $myts
9
10
// 2004/08/20 K.OHWADA
11
// atom feed
12
13
//================================================================
14
// What's New Module
15
// get links from module
16
// for mylinks 1.10 <http://www.xoops.org/>
17
// 2003.12.20 K.OHWADA
18
//================================================================
19
20
/**
21
 * @param int $limit
22
 * @param int $offset
23
 * @return array
24
 */
25
function mylinks_new($limit = 0, $offset = 0)
26
{
27
    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...
28
29
    $myts      = MyTextSanitizer::getInstance();
30
    $dirname   = basename(dirname(__DIR__));
31
    $moduleURL = XOOPS_URL . "/modules/{$dirname}";
32
33
    $limit  = ((int)$limit > 0) ? (int)$limit : 0;
34
    $offset = ((int)$offset > 0) ? (int)$offset : 0;
35
36
    $sql    = 'SELECT l.lid, l.title as ltitle, l.date, l.cid, l.submitter, l.hits, t.description, c.title as ctitle FROM ' . $xoopsDB->prefix('mylinks_links') . ' l, ' . $xoopsDB->prefix('mylinks_text') . ' t, ' . $xoopsDB->prefix('mylinks_cat')
37
              . ' c WHERE t.lid=l.lid AND l.cid=c.cid AND l.status>0 ORDER BY l.date DESC';
38
    $result = $xoopsDB->query($sql, $limit, $offset);
39
40
    $i   = 0;
41
    $ret = array();
42
43 View Code Duplication
    while ($row = $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...
44
        $ret[$i]['link']     = "{$moduleURL}/singlelink.php?lid={$row['lid']}";
45
        $ret[$i]['cat_link'] = "{$moduleURL}/viewcat.php?cid={$row['cid']}";
46
        $ret[$i]['title']    = $row['ltitle'];
47
        $ret[$i]['time']     = $row['date'];
48
        //        $ret[$i]['description'] = $row['description'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% 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...
49
50
        // atom feed
51
        $ret[$i]['id']          = $row['lid'];
52
        $ret[$i]['description'] = $myts->displayTarea($row['description'], 0);    //no html
53
        $ret[$i]['cat_name']    = $row['ctitle'];   // category
54
        $ret[$i]['hits']        = $row['hits'];         // counter
55
        //        $ret[$i]['uid'] = $row['submitter'];   // show user name
0 ignored issues
show
Unused Code Comprehensibility introduced by
71% 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...
56
        $i++;
57
    }
58
59
    return $ret;
60
}
61
62
/**
63
 * @return int
64
 */
65
function mylinks_num()
66
{
67
    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...
68
69
    $sql   = 'SELECT COUNT(*) FROM ' . $xoopsDB->prefix('mylinks_links') . ' WHERE status>0 ORDER BY lid';
70
    $array = $xoopsDB->fetchRow($xoopsDB->query($sql));
71
    $num   = $array[0];
72
    if (empty($num)) {
73
        $num = 0;
74
    }
75
76
    return $num;
77
}
78
79
/**
80
 * @param int $limit
81
 * @param int $offset
82
 * @return array
83
 */
84
function mylinks_data($limit = 0, $offset = 0)
85
{
86
    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...
87
    $dirname = basename(dirname(__DIR__));
88
89
    $limit  = ((int)$limit > 0) ? (int)$limit : 0;
90
    $offset = ((int)$offset > 0) ? (int)$offset : 0;
91
92
    $sql    = 'SELECT lid, title, date FROM ' . $xoopsDB->prefix('mylinks_links') . ' WHERE status>0 ORDER BY lid';
93
    $result = $xoopsDB->query($sql, $limit, $offset);
94
95
    $i   = 0;
96
    $ret = array();
97
98
    while ($row = $xoopsDB->fetchArray($result)) {
99
        $id               = $row['lid'];
100
        $ret[$i]['id']    = $id;
101
        $ret[$i]['link']  = XOOPS_URL . "/modules/{$dirname}/singlelink.php?lid={$id}";
102
        $ret[$i]['title'] = $row['title'];
103
        $ret[$i]['time']  = $row['date'];
104
        $i++;
105
    }
106
107
    return $ret;
108
}
109