Completed
Branch master (c92e39)
by Michael
02:32
created

include/notification.inc.php (2 issues)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/**
4
 * Module: SmartFAQ
5
 * Author: The SmartFactory <www.smartfactory.ca>
6
 * Licence: GNU
7
 * @param $category
8
 * @param $item_id
9
 * @return mixed
10
 */
11
12
function smartfaq_notify_iteminfo($category, $item_id)
13
{
14
    global $xoopsModule, $xoopsModuleConfig, $xoopsConfig;
15
16
    if (empty($xoopsModule) || $xoopsModule->getVar('dirname') !== 'smartfaq') {
17
        /** @var XoopsModuleHandler $moduleHandler */
18
        $moduleHandler = xoops_getHandler('module');
19
        $module        = $moduleHandler->getByDirname('smartfaq');
20
        $configHandler = xoops_getHandler('config');
21
        $config        = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
0 ignored issues
show
$config 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...
22
    } else {
23
        $module = $xoopsModule;
24
        $config = $xoopsModuleConfig;
0 ignored issues
show
$config 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...
25
    }
26
27
    if ($category === 'global') {
28
        $item['name'] = '';
29
        $item['url']  = '';
30
31
        return $item;
32
    }
33
34
    global $xoopsDB;
35
36 View Code Duplication
    if ($category === 'category') {
37
        // Assume we have a valid category id
38
        $sql          = 'SELECT name FROM ' . $xoopsDB->prefix('smartfaq_categories') . ' WHERE categoryid  = ' . $item_id;
39
        $result       = $xoopsDB->query($sql); // TODO: error check
40
        $result_array = $xoopsDB->fetchArray($result);
41
        $item['name'] = $result_array['name'];
42
        $item['url']  = XOOPS_URL . '/modules/' . $module->getVar('dirname') . '/category.php?categoryid=' . $item_id;
43
44
        return $item;
45
    }
46
47 View Code Duplication
    if ($category === 'faq') {
48
        // Assume we have a valid story id
49
        $sql          = 'SELECT question FROM ' . $xoopsDB->prefix('smartfaq_faq') . ' WHERE faqid = ' . $item_id;
50
        $result       = $xoopsDB->query($sql); // TODO: error check
51
        $result_array = $xoopsDB->fetchArray($result);
52
        $item['name'] = $result_array['question'];
53
        $item['url']  = XOOPS_URL . '/modules/' . $module->getVar('dirname') . '/faq.php?faqid=' . $item_id;
54
55
        return $item;
56
    }
57
}
58