b_xoopsheadline_show()   B
last analyzed

Complexity

Conditions 10
Paths 11

Size

Total Lines 57
Code Lines 41

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 10
eloc 41
nc 11
nop 1
dl 0
loc 57
rs 7.6666
c 3
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 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\Xoopsheadline\{
19
    Helper,
20
    Utility
21
};
22
23
/**
24
 * @param array $options
25
 * @return array|bool
26
 */
27
function b_xoopsheadline_show(array $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

27
function b_xoopsheadline_show(/** @scrutinizer ignore-unused */ array $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...
28
{
29
    if (!class_exists(Helper::class)) {
30
        return false;
31
    }
32
33
    $helper = Helper::getInstance();
34
35
    $block = [];
36
37
    global $xoopsConfig;
38
    $hlDir = \basename(\dirname(__DIR__));
39
40
    /** @var \XoopsModuleHandler $moduleHandler */
41
    $moduleHandler = xoops_getHandler('module');
42
    $module        = $moduleHandler->getByDirname($hlDir);
43
    /** @var \XoopsConfigHandler $configHandler */
44
    $configHandler = xoops_getHandler('config');
45
    $moduleConfig  = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
46
47
    $headlineHandler = $helper->getHandler('Headline');
48
    $criteria        = new \CriteriaCompo();
49
    $criteria->add(new \Criteria('headline_asblock', 1, '='));
50
    switch ($moduleConfig['sortby']) {
51
        case 1:
52
            $criteria->setSort('headline_name');
53
            $criteria->setOrder('DESC');
54
            break;
55
        case 2:
56
            $criteria->setSort('headline_name');
57
            $criteria->setOrder('ASC');
58
            break;
59
        case 3:
60
            $criteria->setSort('headline_weight');
61
            $criteria->setOrder('DESC');
62
            break;
63
        case 4:
64
        default:
65
            $criteria->setSort('headline_weight');
66
            $criteria->setOrder('ASC');
67
            break;
68
    }
69
    if (null !== $headlineHandler) {
70
        $headlines = $headlineHandler->getObjects($criteria);
71
        foreach ($headlines as $i => $iValue) {
72
            $renderer = Utility::getRenderer($iValue);
73
            if (!$renderer->renderBlock()) {
74
                if (2 == $xoopsConfig['debug_mode']) {
75
                    $block['feeds'][] = sprintf(_MD_XOOPSHEADLINE_FAILGET, $iValue->getVar('headline_name')) . '<br>' . $renderer->getErrors();
76
                }
77
                continue;
78
            }
79
            $block['feeds'][] = &$renderer->getBlock();
80
        }
81
    }
82
83
    return $block;
84
}
85