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

feeddata.inc.php ➔ mylinks_feednew()   C

Complexity

Conditions 7
Paths 40

Size

Total Lines 41
Code Lines 28

Duplication

Lines 13
Ratio 31.71 %

Importance

Changes 0
Metric Value
cc 7
eloc 28
nc 40
nop 2
dl 13
loc 41
rs 6.7272
c 0
b 0
f 0
1
<?php
2
/**
3
 * @param int $limit
4
 * @param int $offset
5
 * @return array
6
 */
7
function mylinks_feednew($limit = 0, $offset = 0)
0 ignored issues
show
Coding Style introduced by
mylinks_feednew uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
8
{
9
    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...
10
11
    $myts      = MyTextSanitizer::getInstance();
12
    $dirname   = basename(dirname(__DIR__));
13
    $moduleURL = XOOPS_URL . "/modules/{$dirname}";
14
15
    $limit  = ((int)$limit > 0) ? (int)$limit : 0;
16
    $offset = ((int)$offset > 0) ? (int)$offset : 0;
17
18
    if (isset($_GET['cid'])) {
19
        $categoryid = ((int)$_GET['cid'] && (int)($_GET['cid'] > 0)) ? (int)$_GET['cid'] : 0;
20
        $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')
21
                      . " c WHERE l.cid= {$categoryid} AND t.lid=l.lid AND l.cid=c.cid AND l.status>0 ORDER BY l.date DESC";
22
    } else {
23
        $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')
24
               . ' c WHERE t.lid=l.lid AND l.cid=c.cid AND l.status>0 ORDER BY l.date DESC';
25
    }
26
27
    $result = $xoopsDB->query($sql, $limit, $offset);
28
29
    $i   = 0;
30
    $ret = array();
31
32 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...
33
        $ret[$i]['link']     = "{$moduleURL}/singlelink.php?lid={$row['lid']}";
34
        $ret[$i]['cat_link'] = "{$moduleURL}/viewcat.php?cid={$row['cid']}";
35
        $ret[$i]['title']    = $row['ltitle'];    // link title
36
        $ret[$i]['time']     = $row['date'];       // date
37
        //        $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...
38
        $ret[$i]['id']          = $row['lid'];          // atom feed
39
        $ret[$i]['description'] = $myts->displayTarea($row['description'], 0);    //no html
40
        $ret[$i]['cat_name']    = $row['ctitle']; // category
41
        $ret[$i]['hits']        = $row['hits'];       // counter
42
        //        $ret[$i]['uid'] = $row['submitter'];   // 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...
43
        $i++;
44
    }
45
46
    return $ret;
47
}
48