mymodule_notify_iteminfo()   B
last analyzed

Complexity

Conditions 6
Paths 8

Size

Total Lines 41
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 32
nc 8
nop 2
dl 0
loc 41
rs 8.7857
c 0
b 0
f 0
1
<?php
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
*/
11
12
/**
13
 * My Module module for xoops
14
 *
15
 * @copyright     2020 XOOPS Project (https://xooops.org)
16
 * @license        GPL 2.0 or later
17
 * @package        mymodule
18
 * @since          1.0
19
 * @min_xoops      2.5.9
20
 * @author         TDM XOOPS - Email:<[email protected]> - Website:<http://xoops.org>
21
 */
22
23
/**
24
 * comment callback functions
25
 *
26
 * @param $category
27
 * @param $item_id
28
 * @return array item|null
29
 */
30
function mymodule_notify_iteminfo($category, $item_id)
31
{
32
    global $xoopsModule, $xoopsModuleConfig, $xoopsDB;
33
    //
34
    if (empty($xoopsModule) || $xoopsModule->getVar('dirname') != 'mymodule')
35
    {
36
        $moduleHandler = xoops_getHandler('module');
37
        $module = $moduleHandler->getByDirname('mymodule');
0 ignored issues
show
Bug introduced by
The method getByDirname() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsModuleHandler or XoopsPersistableObjectHandler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

37
        /** @scrutinizer ignore-call */ 
38
        $module = $moduleHandler->getByDirname('mymodule');
Loading history...
38
        $configHandler = xoops_getHandler('config');
39
        $config =& $configHandler->getConfigsByCat(0, $module->getVar('mid'));
0 ignored issues
show
Unused Code introduced by
The assignment to $config is dead and can be removed.
Loading history...
Bug introduced by
The method getConfigsByCat() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsPersistableObjectHandler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

39
        $config =& $configHandler->/** @scrutinizer ignore-call */ getConfigsByCat(0, $module->getVar('mid'));
Loading history...
40
    } else {
41
        $module = $xoopsModule;
0 ignored issues
show
Unused Code introduced by
The assignment to $module is dead and can be removed.
Loading history...
42
        $config = $xoopsModuleConfig;
43
    }
44
    //
45
    switch($category) {
46
        case 'global':
47
            $item['name'] = '';
0 ignored issues
show
Comprehensibility Best Practice introduced by
$item was never initialized. Although not strictly required by PHP, it is generally a good practice to add $item = array(); before regardless.
Loading history...
48
            $item['url'] = '';
49
            return $item;
50
        break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
51
        case 'category':
52
            // Assume we have a valid category id
53
            $sql = 'SELECT art_title FROM ' . $xoopsDB->prefix('mymodule_articles') . ' WHERE art_id = '. $item_id;
54
            $result = $xoopsDB->query($sql); // TODO: error check
55
            $result_array = $xoopsDB->fetchArray($result);
56
            $item['name'] = $result_array['art_title'];
57
            $item['url'] = MYMODULE_URL . '/articles.php?art_id=' . $item_id;
58
            return $item;
59
        break;
60
        case 'article':
61
            // Assume we have a valid link id
62
            $sql = 'SELECT art_id, art_title FROM '.$xoopsDB->prefix('mymodule_articles') . ' WHERE art_id = ' . $item_id;
63
            $result = $xoopsDB->query($sql); // TODO: error check
64
            $result_array = $xoopsDB->fetchArray($result);
65
            $item['name'] = $result_array['art_title'];
66
			$item['url'] = MYMODULE_URL . '/single.php?cid=' . $result_array['cid'] . '&amp;art_id=' . $item_id;
67
			return $item;
68
        break;
69
    }
70
    return null;
71
}