sb_notify_iteminfo()   B
last analyzed

Complexity

Conditions 6
Paths 6

Size

Total Lines 64
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 28
nc 6
nop 3
dl 0
loc 64
rs 8.8497
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: Soapbox
5
 * Version: v 1.5
6
 * Release Date: 23 August 2004
7
 * Author: hsalazar
8
 * Licence: GNU
9
 * @param        $category
10
 * @param        $item_id
11
 * @param  null  $event
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $event is correct as it would always require null to be passed?
Loading history...
12
 * @return array
13
 */
14
// defined('XOOPS_ROOT_PATH') || die('Restricted access');
15
function sb_notify_iteminfo($category, $item_id, $event = null)
0 ignored issues
show
Unused Code introduced by
The parameter $event is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

15
function sb_notify_iteminfo($category, $item_id, /** @scrutinizer ignore-unused */ $event = null)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
16
{
17
    /*
18
        global $xoopsModule, $xoopsModuleConfig, $xoopsConfig;
19
20
        if ( empty( $xoopsModule ) || $xoopsModule -> getVar( 'dirname' ) != 'soapbox' ) {
21
            $moduleHandler = xoops_getHandler( 'module' );
22
            $module =  $moduleHandler -> getByDirname( 'soapbox' );
23
            $configHandler = xoops_getHandler( 'config' );
24
            $config =  $configHandler->getConfigsByCat( 0, $module -> getVar( 'mid' ) );
25
        } else {
26
            $module =  $xoopsModule;
27
            if ( empty( $xoopsModuleConfig ) ) {
28
                $configHandler = xoops_getHandler( 'config' );
29
                $config =  $configHandler->getConfigsByCat( 0, $module -> getVar( 'mid' ) );
30
            } else {
31
                $config =  $xoopsModuleConfig;
32
            }
33
        }
34
    */
35
    //    $moduleDirName = 'soapbox';
36
    $pathparts     = explode('/', __DIR__);
37
    $moduleDirName = $pathparts[array_search('modules', $pathparts, true) + 1];
38
    $item_id       = (int)$item_id;
39
    $item          = [];
40
    if ('global' === $category) {
41
        $item['name'] = '';
42
        $item['url']  = '';
43
44
        return $item;
45
    }
46
47
    global $xoopsDB;
48
49
    if ('column' === $category) {
50
        // Assume we have a valid category id
51
52
        $sql    = 'SELECT name FROM ' . $xoopsDB->prefix('sbcolumns') . ' WHERE columnID  = ' . $item_id;
53
        $result = $xoopsDB->query($sql);
54
        if (!$result) {
55
            return $item;
56
        }
57
        $result_array = $xoopsDB->fetchArray($result);
58
        $item['name'] = $result_array['name'];
59
        $item['url']  = XOOPS_URL . '/modules/' . $moduleDirName . '/column.php?columnID=' . $item_id;
60
61
        return $item;
62
    }
63
64
    if ('article' === $category) {
65
        // Assume we have a valid story id
66
        $sql    = 'SELECT headline FROM ' . $xoopsDB->prefix('sbarticles') . ' WHERE articleID = ' . $item_id;
67
        $result = $xoopsDB->query($sql);
68
        if (!$result) {
69
            return $item;
70
        }
71
        $result_array = $xoopsDB->fetchArray($result);
72
        $item['name'] = $result_array['headline'];
73
        $item['url']  = XOOPS_URL . '/modules/' . $moduleDirName . '/article.php?articleID=' . $item_id;
74
75
        return $item;
76
    }
77
78
    return '';
0 ignored issues
show
Bug Best Practice introduced by
The expression return '' returns the type string which is incompatible with the documented return type array.
Loading history...
79
}
80