b_news_topics_onthefly()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
c 0
b 0
f 0
dl 0
loc 8
rs 10
cc 1
nc 1
nop 1
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
/**
13
 * @copyright      {@link https://xoops.org/ XOOPS Project}
14
 * @license        {@link https://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later}
15
 * @author         XOOPS Development Team
16
 */
17
18
use XoopsModules\News\{
19
    Helper,
20
    NewsTopic,
21
    ObjectTree,
22
    Utility
23
};
24
25
/**
26
 * @return mixed
27
 */
28
function b_news_topics_show()
29
{
30
    global $storytopic; // Don't know why this is used and where it's coming from ....
31
    //    require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newstopic.php';
32
    //    require_once XOOPS_ROOT_PATH . '/modules/news/class/tree.php';
33
34
    $moduleDirName = \basename(\dirname(__DIR__));
0 ignored issues
show
Unused Code introduced by
The assignment to $moduleDirName is dead and can be removed.
Loading history...
35
36
    /** @var Helper $helper */
37
    if (!class_exists(Helper::class)) {
38
        return false;
39
    }
40
41
    $helper = Helper::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $helper is dead and can be removed.
Loading history...
42
43
    $jump       = XOOPS_URL . '/modules/news/index.php?storytopic=';
44
    $storytopic = !empty($storytopic) ? $storytopic : 0;
45
    $restricted = Utility::getModuleOption('restrictindex');
46
47
    $xt         = new NewsTopic();
48
    $allTopics  = $xt->getAllTopics($restricted);
49
    $topic_tree = new ObjectTree($allTopics, 'topic_id', 'topic_pid');
50
    $additional = " onchange='location=\"" . $jump . "\"+this.options[this.selectedIndex].value'";
51
52
    if (Utility::checkVerXoops($GLOBALS['xoopsModule'], '2.5.9')) {
53
        //                $block['selectbox'] = $topic_tree->makeSelBox('storytopic', 'topic_title', '-- ', '', true, 0, $additional);
54
        $topicSelect        = $topic_tree->makeSelectElement('storytopic', 'topic_title', '--', '', true, 0, $additional);
55
        $block['selectbox'] = $topicSelect->render();
0 ignored issues
show
Comprehensibility Best Practice introduced by
$block was never initialized. Although not strictly required by PHP, it is generally a good practice to add $block = array(); before regardless.
Loading history...
56
    } else {
57
        $block['selectbox'] = $topic_tree->makeSelBox('storytopic', 'topic_title', '-- ', '', true, 0, $additional);
0 ignored issues
show
Deprecated Code introduced by
The function XoopsModules\News\ObjectTree::makeSelBox() has been deprecated: since 2.5.9, please use makeSelectElement() ( Ignorable by Annotation )

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

57
        $block['selectbox'] = /** @scrutinizer ignore-deprecated */ $topic_tree->makeSelBox('storytopic', 'topic_title', '-- ', '', true, 0, $additional);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
58
    }
59
60
    return $block;
61
}
62
63
/**
64
 * @param $options
65
 */
66
function b_news_topics_onthefly($options): void
67
{
68
    $options = explode('|', $options);
69
    $block   = b_news_topics_show($options);
0 ignored issues
show
Unused Code introduced by
The call to b_news_topics_show() has too many arguments starting with $options. ( Ignorable by Annotation )

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

69
    $block   = /** @scrutinizer ignore-call */ b_news_topics_show($options);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
70
71
    $tpl = new \XoopsTpl();
72
    $tpl->assign('block', $block);
73
    $tpl->display('db:news_block_topics.tpl');
74
}
75