search.inc.php ➔ smartpartner_search()   B
last analyzed

Complexity

Conditions 5
Paths 16

Size

Total Lines 37
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 23
nc 16
nop 5
dl 0
loc 37
rs 8.439
c 0
b 0
f 0
1
<?php
2
3
/**
4
 *
5
 * Module: SmartMedia
6
 * Author: The SmartFactory <www.smartfactory.ca>
7
 * Licence: GNU
8
 * @param $queryarray
9
 * @param $andor
10
 * @param $limit
11
 * @param $offset
12
 * @param $userid
13
 * @return array
14
 */
15
// 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...
16
17
function smartpartner_search($queryarray, $andor, $limit, $offset, $userid)
18
{
19
    // This must contain the name of the folder in which reside SmartPartner
20
    if (!defined('SMARTPARTNER_DIRNAME')) {
21
        define('SMARTPARTNER_DIRNAME', 'smartpartner');
22
    }
23
    include_once XOOPS_ROOT_PATH . '/modules/' . SMARTPARTNER_DIRNAME . '/include/common.php';
24
25
    $ret = array();
26
27
    if (!isset($smartPartnerPartnerHandler)) {
0 ignored issues
show
Bug introduced by
The variable $smartPartnerPartnerHandler seems only to be defined at a later point. As such the call to isset() seems to always evaluate to false.

This check marks calls to isset(...) or empty(...) that are found before the variable itself is defined. These will always have the same result.

This is likely the result of code being shifted around. Consider removing these calls.

Loading history...
28
        $smartPartnerPartnerHandler = smartpartner_gethandler('partner');
29
    }
30
31
    // Searching the partners
32
    $partners_result = $smartPartnerPartnerHandler->getObjectsForSearch($queryarray, $andor, $limit, $offset, $userid);
33
34
    if ($queryarray == '') {
35
        $keywords       = '';
0 ignored issues
show
Unused Code introduced by
$keywords 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
        $hightlight_key = '';
37
    } else {
38
        $keywords       = implode('+', $queryarray);
39
        $hightlight_key = '&amp;keywords=' . $keywords;
40
    }
41
42
    foreach ($partners_result as $result) {
43
        $item['image'] = 'assets/images/links/partner.gif';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$item was never initialized. Although not strictly required by PHP, it is generally a good practice to add $item = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
44
        $item['link']  = 'partner.php?id=' . $result['id'] . $hightlight_key;
45
        $item['title'] = '' . $result['title'];
46
        $item['time']  = '';
47
        $item['uid']   = '';
48
        $ret[]         = $item;
49
        unset($item);
50
    }
51
52
    return $ret;
53
}
54