Passed
Push — master ( 756ad9...090462 )
by Michael
28s
created

tagBar()   C

Complexity

Conditions 13
Paths 56

Size

Total Lines 56
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 13
eloc 37
nc 56
nop 3
dl 0
loc 56
rs 6.6166
c 0
b 0
f 0

How to fix   Long Method    Complexity   

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
 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
/**
13
 * XOOPS tag management module
14
 *
15
 * @package        tag
16
 * @copyright      {@link http://sourceforge.net/projects/xoops/ The XOOPS Project}
17
 * @license        {@link http://www.fsf.org/copyleft/gpl.html GNU public license}
18
 * @author         Taiwen Jiang <[email protected]>
19
 * @since          1.00
20
 */
21
(defined('XOOPS_ROOT_PATH') && ($GLOBALS['xoopsModule'] instanceof XoopsModule)) || die('Restricted access');
22
23
/**
24
 * Display tag list
25
 *
26
 * @param  int|array $tags array of tag string
27
 *                         OR
28
 * @param  int       $catid
29
 * @param  int       $modid
30
 * @return array
31
 * @internal param int $itemid
32
 */
33
function tagBar($tags, $catid = 0, $modid = 0)
34
{
35
    static $loaded, $delimiter;
36
37
    if (empty($tags)) {
38
        return [];
39
    }
40
41
    if (null === $loaded) {
42
        require_once $GLOBALS['xoops']->path('/modules/tag/include/vars.php');
43
        require_once $GLOBALS['xoops']->path('/modules/tag/include/functions.php');
44
        tag_define_url_delimiter();
45
        if (!($GLOBALS['xoopsModule'] instanceof XoopsModule)
46
            || ('tag' !== $GLOBALS['xoopsModule']->getVar('dirname'))) {
47
            xoops_loadLanguage('main', 'tag');
48
        }
49
        if (file_exists($GLOBALS['xoops']->path('/modules/tag/assets/images/delimiter.gif'))) {
50
            $delimiter = "<img src='" . $GLOBALS['xoops']->url('www/modules/tag/assets/images/delimiter.gif') . "' alt=''>";
51
        } else {
52
            $delimiter = "<img src='" . $GLOBALS['xoops']->url('www/assets/images/pointer.gif') . "' alt=''>";
53
        }
54
        $loaded = 1;
55
    }
56
57
    // itemid
58
    if (is_numeric($tags)) {
59
        if (empty($modid) && ($GLOBALS['xoopsModule'] instanceof XoopsModule)) {
60
            $modid = $GLOBALS['xoopsModule']->getVar('mid');
61
        }
62
        /** @var \XoopsModules\Tag\TagHandler $tagHandler */
63
        $tagHandler = \XoopsModules\Tag\Helper::getInstance()->getHandler('Tag'); // xoops_getModuleHandler('tag', 'tag');
64
        if (!$tags = $tagHandler->getByItem($tags, $modid, $catid)) {
65
            return [];
66
        }
67
68
        // if ready, do nothing
69
    } elseif (is_array($tags)) {
0 ignored issues
show
introduced by
The condition is_array($tags) is always true.
Loading history...
70
        // parse
71
    } elseif (!$tags = tag_parse_tag($tags)) {
72
        return [];
73
    }
74
    $tags_data = [];
75
    foreach ($tags as $tag) {
76
        $tags_data[] = "<a href='"
77
                       . $GLOBALS['xoops']->url('www/modules/' . $GLOBALS['xoopsModule']->getVar('dirname') . '/view.tag.php' . URL_DELIMITER . urlencode($tag))
78
                       . "' title='"
79
                       . htmlspecialchars($tag, ENT_QUOTES | ENT_HTML5)
80
                       . "'>"
81
                       . htmlspecialchars($tag, ENT_QUOTES | ENT_HTML5)
82
                       . '</a>';
83
    }
84
85
    return [
86
        'title'     => _MD_TAG_TAGS,
87
        'delimiter' => $delimiter,
88
        'tags'      => $tags_data,
89
    ];
90
}
91