lexikon_notify_iteminfo()   B
last analyzed

Complexity

Conditions 7
Paths 12

Size

Total Lines 59
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 29
nc 12
nop 2
dl 0
loc 59
rs 8.5226
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
5
defined('XOOPS_ROOT_PATH') || exit('Restricted access');
6
7
/** @var \XoopsConfigHandler $configHandler */
8
/** @var \XoopsModuleHandler $moduleHandler */
9
10
/**
11
 * @param $category
12
 * @param $item_id
13
 * @return array|void
14
 */
15
16
17
function lexikon_notify_iteminfo($category, $item_id)
18
{
19
    /*global $xoopsModule, $xoopsModuleConfig, $xoopsConfig;
20
21
    if (empty($xoopsModule) || $xoopsModule->getVar('dirname') != 'lexikon') {
22
23
    $moduleHandler = xoops_getHandler('module');
24
    $module        = $moduleHandler->getByDirname('lexikon');
25
    $configHandler = xoops_getHandler('config');
26
    $config        = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
27
}
28
29
else {
30
    $module = $xoopsModule;
31
    $config = $xoopsModuleConfig;
32
}*/
33
34
if (mb_strpos(__DIR__, '/') > 0) {
35
    $pathparts = explode('/', __DIR__);
36
} else {
37
    $pathparts = explode('\\', __DIR__);
38
}
39
$moduleDirName = $pathparts[array_search('modules', $pathparts, true) + 1]; // checken
0 ignored issues
show
Unused Code introduced by
The assignment to $moduleDirName is dead and can be removed.
Loading history...
40
41
if ('global' === $category) {
42
    $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...
43
    $item['url']  = '';
44
45
    return $item;
46
}
47
$item_id = (int)$item_id;
48
49
global $xoopsDB;
50
if ('category' === $category) {
51
    // Assume we have a valid category id
52
    $sql = 'SELECT name FROM ' . $xoopsDB->prefix('lxcategories') . ' WHERE categoryID = ' . $item_id;
53
    if (!$result = $xoopsDB->query($sql)) {
0 ignored issues
show
Unused Code introduced by
The assignment to $result is dead and can be removed.
Loading history...
54
        redirect_header('index.php', 2, _ERRORS);
55
    }
56
    $result       = $xoopsDB->query($sql);
57
    $result_array = $xoopsDB->fetchArray($result);
58
    $item['name'] = $result_array['name'];
59
    $item['url']  = XOOPS_URL . '/modules/lexikon/category.php?categoryID=' . $item_id;
60
61
    return $item;
62
}
63
64
if ('term' === $category) {
65
    // Assume we have a valid entry id
66
    $sql = 'SELECT entryID,term FROM ' . $xoopsDB->prefix('lxentries') . ' WHERE entryID = ' . $item_id;
67
    if (!$result = $xoopsDB->query($sql)) {
68
        redirect_header('index.php', 2, _ERRORS);
69
    }
70
    $result       = $xoopsDB->query($sql);
71
    $result_array = $xoopsDB->fetchArray($result);
72
    $item['name'] = $result_array['term'];
73
    $item['url']  = XOOPS_URL . '/modules/lexikon/entry.php?entryID=' . $item_id;
74
75
    return $item;
76
}
77
}
78