xtubeNotifyIteminfo()   B
last analyzed

Complexity

Conditions 8
Paths 12

Size

Total Lines 53
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 31
nc 12
nop 2
dl 0
loc 53
rs 8.1795
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * Module: XoopsTube
5
 *
6
 * You may not change or alter any portion of this comment or credits
7
 * of supporting developers from this source code or any supporting source code
8
 * which is considered copyrighted (c) material of the original comment or credit authors.
9
 *
10
 * PHP version 5
11
 *
12
 * @param $category
13
 * @param $item_id
14
 * @return bool|null
15
 * @category        Module
16
 * @package         Xoopstube
17
 * @author          XOOPS Development Team
18
 * @copyright       2001-2016 XOOPS Project (https://xoops.org)
19
 * @license         GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
20
 * @link            https://xoops.org/
21
 * @since           1.0.6
22
 *
23
 */
24
function xtubeNotifyIteminfo($category, $item_id)
25
{
26
    global $xoopsModule;
27
28
    $moduleDirName = \basename(\dirname(__DIR__));
29
    //    $modulePath = dirname(__DIR__);
30
31
    if (empty($xoopsModule) || 'xoopstube' !== $xoopsModule->getVar('dirname')) {
32
        /** @var \XoopsModuleHandler $moduleHandler */
33
        $moduleHandler = xoops_getHandler('module');
34
        $module        = $moduleHandler->getByDirname($moduleDirName);
35
        /** @var \XoopsConfigHandler $configHandler */
36
        $configHandler = xoops_getHandler('config');
37
        $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...
38
    } else {
39
        $module = $xoopsModule;
0 ignored issues
show
Unused Code introduced by
The assignment to $module is dead and can be removed.
Loading history...
40
        $config = $GLOBALS['xoopsModuleConfig'];
41
    }
42
43
    if ('global' === $category) {
44
        $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...
45
        $item['url']  = '';
46
47
        return $item;
48
    }
49
50
    if ('category' === $category) {
51
        // Assume we have a valid category id
52
        $sql = 'SELECT title FROM ' . $GLOBALS['xoopsDB']->prefix('xoopstube_cat') . ' WHERE cid=' . $item_id;
53
        if (!$result = $GLOBALS['xoopsDB']->query($sql)) {
54
            return false;
55
        }
56
        $result_array = $GLOBALS['xoopsDB']->fetchArray($result);
57
        $item['name'] = $result_array['title'];
58
        $item['url']  = XOOPS_URL . '/modules/xoopstube/viewcat.php?cid=' . $item_id;
59
60
        return $item;
61
    }
62
63
    if ('video' === $category) {
64
        // Assume we have a valid file id
65
        $sql = 'SELECT cid,title FROM ' . $GLOBALS['xoopsDB']->prefix('xoopstube_videos') . ' WHERE lid=' . $item_id;
66
        if (!$result = $GLOBALS['xoopsDB']->query($sql)) {
67
            return false;
68
        }
69
        $result_array = $GLOBALS['xoopsDB']->fetchArray($result);
70
        $item['name'] = $result_array['title'];
71
        $item['url']  = XOOPS_URL . '/modules/xoopstube/singlevideo.php?cid=' . $result_array['cid'] . '&amp;lid=' . $item_id;
72
73
        return $item;
74
    }
75
76
    return null;
77
}
78