wflinks_notify_iteminfo()   B
last analyzed

Complexity

Conditions 8
Paths 12

Size

Total Lines 53
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 32
nc 12
nop 2
dl 0
loc 53
rs 8.1635
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
 * Module: WF-Links
4
 * Version: v1.0.3
5
 * Release Date: 21 June 2005
6
 * Developer: John N
7
 * Team: WF-Projects
8
 * Licence: GNU
9
 */
10
11
/**
12
 * @param $category
13
 * @param $item_id
14
 *
15
 * @return bool|null
16
 */
17
function wflinks_notify_iteminfo($category, $item_id)
18
{
19
    $moduleDirName = basename(dirname(__DIR__));
20
    global $xoopsModule, $xoopsModuleConfig, $xoopsConfig;
21
22
    if (empty($xoopsModule) || $xoopsModule->getVar('dirname') != $moduleDirName) {
23
        /** @var \XoopsModuleHandler $moduleHandler */
24
        $moduleHandler = xoops_getHandler('module');
25
        $module        = $moduleHandler->getByDirname($moduleDirName);
26
        /* @var \XoopsConfigHandler $configHandler */
27
        /** @var \XoopsConfigHandler $configHandler */
28
        $configHandler = xoops_getHandler('config');
29
        $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...
30
    } else {
31
        $module = $xoopsModule;
0 ignored issues
show
Unused Code introduced by
The assignment to $module is dead and can be removed.
Loading history...
32
        $config = $xoopsModuleConfig;
33
    }
34
35
    if ('global' === $category) {
36
        $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...
37
        $item['url']  = '';
38
39
        return $item;
40
    }
41
42
    global $xoopsDB;
43
    if ('category' === $category) {
44
        // Assume we have a valid category id
45
        $sql = 'SELECT title FROM ' . $xoopsDB->prefix('wflinks_cat') . ' WHERE cid=' . $item_id;
46
        if (!$result = $xoopsDB->query($sql)) {
47
            return false;
48
        }
49
        $result_array = $xoopsDB->fetchArray($result);
50
        $item['name'] = $result_array['title'];
51
        $item['url']  = XOOPS_URL . '/modules/' . $moduleDirName . '/viewcat.php?cid=' . $item_id;
52
53
        return $item;
54
    }
55
56
    if ('link' === $category) {
57
        // Assume we have a valid file id
58
        $sql = 'SELECT cid,title FROM ' . $xoopsDB->prefix('wflinks_links') . ' WHERE lid=' . $item_id;
59
        if (!$result = $xoopsDB->query($sql)) {
60
            return false;
61
        }
62
        $result_array = $xoopsDB->fetchArray($result);
63
        $item['name'] = $result_array['title'];
64
        $item['url']  = XOOPS_URL . '/modules/' . $moduleDirName . '/singlelink.php?cid=' . $result_array['cid'] . '&amp;lid=' . $item_id;
65
66
        return $item;
67
    }
68
69
    return null;
70
}
71