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

Complexity

Conditions 6
Paths 8

Size

Total Lines 48
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 30
nc 8
nop 2
dl 0
loc 48
rs 8.551
c 0
b 0
f 0
1
<?php
2
3
/*
4
 You may not change or alter any portion of this comment or credits
5
 of supporting developers from this source code or any supporting source code
6
 which is considered copyrighted (c) material of the original comment or credit authors.
7
8
 This program is distributed in the hope that it will be useful,
9
 but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
*/
12
13
/**
14
 * Module: Equipment
15
 *
16
 * @category        Module
17
 * @package         equipment
18
 * @author          XOOPS Development Team <[email protected]> - <http://xoops.org>
19
 * @copyright       {@link https://xoops.org/ XOOPS Project}
20
 * @license         GPL 2.0 or later
21
 * @link            https://xoops.org/
22
 * @since           1.0.0
23
 */
24
25
use Xmf\Language;
26
27
// comment callback functions
28
29
/**
30
 * @param $category
31
 * @param $item_id
32
 * @return null
33
 */
34
function equipment_notify_iteminfo($category, $item_id)
35
{
36
    $moduleDirName = basename(dirname(__DIR__));
37
38
    if (empty($GLOBALS['xoopsModule']) || $GLOBALS['xoopsModule']->getVar('dirname') !== 'equipment') {
39
        /** @var XoopsModuleHandler $moduleHandler */
40
        $moduleHandler = xoops_getHandler('module');
41
        $module        = $moduleHandler->getByDirname('equipment');
42
        /** @var XoopsConfigHandler $configHandler */
43
        $configHandler = xoops_getHandler('config');
44
        $config        =& $configHandler->getConfigsByCat(0, $module->getVar('mid'));
45
    } else {
46
        $module = $GLOBALS['xoopsModule'];
47
        $config = $GLOBALS['xoopsModuleConfig'];
48
    }
49
50
    Language::load('main', $moduleDirName);
51
52
    if ('global' === $category) {
53
        $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...
54
        $item['url']  = '';
55
56
        return $item;
57
    }
58
59
    if ('category' === $category) {
60
        // Assume we have a valid category id
61
        $sql           = 'SELECT _title FROM ' . $GLOBALS['xoopsDB']->prefix('equipment_cat') . ' WHERE _cid = ' . $item_id;
62
        $result        = $GLOBALS['xoopsDB']->query($sql); // TODO: error check
63
        $resultArrayay = $GLOBALS['xoopsDB']->fetchArray($result);
64
        $item['name']  = $resultArrayay['_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...
65
        $item['url']   = XOOPS_URL . '/modules/' . $module->getVar('dirname') . '/cat_view.php?_cid=' . $item_id;
66
67
        return $item;
68
    }
69
70
    if ('' == $category) {
71
        // Assume we have a valid link id
72
        $sql           = 'SELECT _cid, _title FROM ' . $GLOBALS['xoopsDB']->prefix('equipment_rentals') . ' WHERE _lid = ' . $item_id;
73
        $result        = $GLOBALS['xoopsDB']->query($sql); // TODO: error check
74
        $resultArrayay = $GLOBALS['xoopsDB']->fetchArray($result);
75
        $item['name']  = $resultArrayay['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...
76
        $item['url']   = XOOPS_URL . '/modules/' . $module->getVar('dirname') . '/equipment_visit.php?_cid=' . $resultArrayay['_cid'] . '&amp;_lid=' . $item_id;
77
78
        return $item;
79
    }
80
    return null;
81
}
82