Passed
Push — master ( e3d02e...b8a1dc )
by Michael
03:24 queued 12s
created

headline.php ➔ b_xoopsheadline_show()   B

Complexity

Conditions 8
Paths 20

Size

Total Lines 49

Duplication

Lines 19
Ratio 38.78 %

Importance

Changes 0
Metric Value
cc 8
nc 20
nop 1
dl 19
loc 49
rs 7.8682
c 0
b 0
f 0
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
 * @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
 * @package
16
 * @since
17
 * @author       XOOPS Development Team
18
 */
19
20
use XoopsModules\Xoopsheadline\{
21
    Helper,
22
    XoopsheadlineUtility
23
};
24
25
/**
26
 * @param $options
27
 * @return array
28
 */
29
function b_xoopsheadline_show($options)
0 ignored issues
show
Unused Code introduced by
The parameter $options 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

29
function b_xoopsheadline_show(/** @scrutinizer ignore-unused */ $options)

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...
30
{
31
    if (!class_exists(Helper::class)) {
32
        return false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false returns the type false which is incompatible with the documented return type array.
Loading history...
33
    }
34
35
    $helper = Helper::getInstance();
36
37
    $block = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $block is dead and can be removed.
Loading history...
38
39
    global $xoopsConfig;
40
    $hlDir = basename(dirname(__DIR__));
41
42
    /** @var \XoopsModuleHandler $moduleHandler */
43
    $moduleHandler = xoops_getHandler('module');
44
    $module        = $moduleHandler->getByDirname($hlDir);
45
    /** @var \XoopsConfigHandler $configHandler */
46
    $configHandler = xoops_getHandler('config');
47
    $moduleConfig  = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
48
49
    $block    = [];
50
    $hlman    = $helper->getHandler('Headline');
51
    $criteria = new \CriteriaCompo();
52
    $criteria->add(new \Criteria('headline_asblock', 1, '='));
53
    switch ($moduleConfig['sortby']) {
54
        case 1:
55
            $criteria->setSort('headline_name');
56
            $criteria->setOrder('DESC');
57
            break;
58
        case 2:
59
            $criteria->setSort('headline_name');
60
            $criteria->setOrder('ASC');
61
            break;
62
        case 3:
63
            $criteria->setSort('headline_weight');
64
            $criteria->setOrder('DESC');
65
            break;
66
        case 4:
67
        default:
68
            $criteria->setSort('headline_weight');
69
            $criteria->setOrder('ASC');
70
            break;
71
    }
72
    $headlines = $hlman->getObjects($criteria);
73
    foreach ($headlines as $i => $iValue) {
74
        $renderer = XoopsheadlineUtility::getRenderer($headlines[$i]);
75
        if (!$renderer->renderBlock()) {
76
            if (2 == $xoopsConfig['debug_mode']) {
77
                $block['feeds'][] = sprintf(_MD_HEADLINES_FAILGET, $iValue->getVar('headline_name')) . '<br>' . $renderer->getErrors();
78
            }
79
            continue;
80
        }
81
        $block['feeds'][] = &$renderer->getBlock();
82
    }
83
84
    return $block;
85
}
86