notification.inc.php ➔ presenter_notify_iteminfo()   B
last analyzed

Complexity

Conditions 6
Paths 8

Size

Total Lines 49

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
nc 8
nop 2
dl 0
loc 49
rs 8.4905
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
 * presenter module for xoops
13
 *
14
 * @copyright       XOOPS Project (https://xoops.org)
15
 * @license         GPL 2.0 or later
16
 * @package         presenter
17
 * @since           2.5.5
18
 * @author          XOOPS Development Team <[email protected]> - <https://xoops.org>
19
 * @param $category
20
 * @param $item_id
21
 * @return mixed
22
 */
23
// comment callback functions
24
function presenter_notify_iteminfo($category, $item_id)
25
{
26
    global $xoopsModule, $xoopsModuleConfig, $xoopsConfig;
27
28
    if (empty($xoopsModule) || 'presenter' != $xoopsModule->getVar('dirname')) {
29
        /** @var XoopsModuleHandler $moduleHandler */
30
        $moduleHandler = xoops_getHandler('module');
31
        $module        = $moduleHandler->getByDirname('presenter');
32
        $configHandler = xoops_getHandler('config');
33
        $config        = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
34
    } else {
35
        $module =& $xoopsModule;
36
        $config =& $xoopsModuleConfig;
37
    }
38
39
    xoops_loadLanguage('main', 'presenter');
40
41
    if ('global' === $category) {
42
        $item['name'] = '';
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...
43
        $item['url']  = '';
44
45
        return $item;
46
    }
47
48
    global $xoopsDB;
49
    if ('category' === $category) {
50
        // Assume we have a valid category id
51
        $sql          = 'SELECT slides_cid FROM ' . $xoopsDB->prefix('presenter_slides') . ' WHERE slides_cid = ' . $item_id;
52
        $result       = $xoopsDB->query($sql); // TODO: error check
53
        $result_array = $xoopsDB->fetchArray($result);
54
        $item['name'] = $result_array['slides_cid'];
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...
55
        $item['url']  = XOOPS_URL . '/modules/' . $module->getVar('dirname') . '/slides.php?slides_cid=' . $item_id;
56
57
        return $item;
58
    }
59
60
    if ('slides' === $category) {
61
        // Assume we have a valid link id
62
        $sql          = 'SELECT slides_cid, slides_cid FROM ' . $xoopsDB->prefix('slides') . ' WHERE slides_id = ' . $item_id;
63
        $result       = $xoopsDB->query($sql); // TODO: error check
64
        $result_array = $xoopsDB->fetchArray($result);
65
        $item['name'] = $result_array['title'];
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...
66
        $item['url']  = XOOPS_URL . '/modules/' . $module->getVar('dirname') . '/slides.php?slides_cid=' . $result_array['slides_cid'] . '&amp;slides_id=' . $item_id;
67
68
        return $item;
69
    }
70
71
    return '';
72
}
73