suico_iteminfo()   B
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 64
Code Lines 46

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 46
nc 5
nop 2
dl 0
loc 64
rs 8.867
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 declare(strict_types=1);
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
*/
11
/**
12
 * @category        Module
13
 * @copyright       {@link https://xoops.org/ XOOPS Project}
14
 * @license         GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
15
 * @author          Marcello Brandão aka  Suico, Mamba, LioMJ  <https://xoops.org>
16
 */
17
/**
18
 * Protection against inclusion outside the site
19
 */
20
if (!defined('XOOPS_ROOT_PATH')) {
21
    exit('XOOPS root path not defined');
22
}
23
/**
24
 * @param $category
25
 * @param $item_id
26
 * @return mixed
27
 */
28
function suico_iteminfo($category, $item_id)
29
{
30
    $moduleHandler = xoops_getHandler('module');
31
    $module        = $moduleHandler->getByDirname('suico');
0 ignored issues
show
Bug introduced by
The method getByDirname() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsModuleHandler or XoopsPersistableObjectHandler. ( Ignorable by Annotation )

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

31
    /** @scrutinizer ignore-call */ 
32
    $module        = $moduleHandler->getByDirname('suico');
Loading history...
32
    if ('global' === $category) {
33
        $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...
34
        $item['url']  = '';
35
36
        return $item;
37
    }
38
    global $xoopsDB;
39
    if ('picture' === $category) {
40
        $sql          = 'SELECT title,uid_owner,filename FROM ' . $xoopsDB->prefix(
41
                'suico_images'
42
            ) . ' WHERE uid_owner = ' . $item_id . ' LIMIT 1';
43
        $result       = $xoopsDB->query($sql);
44
        $result_array = $xoopsDB->fetchArray($result);
45
        /**
46
         * Let's get the user name of the owner of the album
47
         */
48
        $owner        = new \XoopsUser();
49
        $identifier   = $owner::getUnameFromId($result_array['uid_owner']);
50
        $item['name'] = $identifier . "'s Album";
51
        $item['url']  = XOOPS_URL . '/modules/' . $module->getVar(
52
                'dirname'
53
            ) . '/album.php?uid=' . $result_array['uid_owner'];
54
55
        return $item;
56
    }
57
    if ('video' === $category) {
58
        $sql          = 'SELECT video_id,uid_owner,video_title,video_desc,youtube_code, featuredvideo FROM ' . $xoopsDB->prefix(
59
                'suico_images'
60
            ) . ' WHERE uid_owner = ' . $item_id . ' LIMIT 1';
61
        $result       = $xoopsDB->query($sql);
62
        $result_array = $xoopsDB->fetchArray($result);
63
        /**
64
         * Let's get the user name of the owner of the album
65
         */
66
        $owner        = new \XoopsUser();
67
        $identifier   = $owner::getUnameFromId($result_array['uid_owner']);
68
        $item['name'] = $identifier . "'s Videos";
69
        $item['url']  = XOOPS_URL . '/modules/' . $module->getVar(
70
                'dirname'
71
            ) . '/videos.php?uid=' . $result_array['uid_owner'];
72
73
        return $item;
74
    }
75
    if ('Note' === $category) {
76
        $sql          = 'SELECT note_id, note_from, note_to, note_text FROM ' . $xoopsDB->prefix(
77
                'suico_notes'
78
            ) . ' WHERE note_from = ' . $item_id . ' LIMIT 1';
79
        $result       = $xoopsDB->query($sql);
80
        $result_array = $xoopsDB->fetchArray($result);
81
        /**
82
         * Let's get the user name of the owner of the album
83
         */
84
        $owner        = new \XoopsUser();
85
        $identifier   = $owner::getUnameFromId($result_array['note_from']);
86
        $item['name'] = $identifier . "'s Notes";
87
        $item['url']  = XOOPS_URL . '/modules/' . $module->getVar(
88
                'dirname'
89
            ) . '/notebook.php?uid=' . $result_array['note_from'];
90
91
        return $item;
92
    }
93
}
94