Passed
Push — master ( eec3d3...7b6eed )
by Michael
02:45
created

updateBlock()   B

Complexity

Conditions 11
Paths 18

Size

Total Lines 53
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 37
c 1
b 0
f 0
dl 0
loc 53
rs 7.3166
cc 11
nc 18
nop 9

How to fix   Long Method    Complexity    Many Parameters   

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:

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * You may not change or alter any portion of this comment or credits
7
 * of supporting developers from this source code or any supporting source code
8
 * which is considered copyrighted (c) material of the original comment or credit authors.
9
 *
10
 *
11
 * @category        Module
12
 * @author          XOOPS Development Team
13
 * @copyright       XOOPS Project
14
 * @link            https://xoops.org
15
 * @license         GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
16
 */
17
18
use Xmf\Module\Admin;
19
use Xmf\Request;
20
use XoopsModules\Xoopsheadline\{
21
    Common\Blocksadmin,
22
    Helper
23
};
24
25
/** @var Admin $adminObject */
26
/** @var Helper $helper */
27
28
require __DIR__ . '/admin_header.php';
29
xoops_cp_header();
30
31
$moduleDirName      = $helper->getDirname();
32
$moduleDirNameUpper = \mb_strtoupper($moduleDirName);
33
34
/** @var \XoopsMySQLDatabase $xoopsDB */
35
$xoopsDB     = \XoopsDatabaseFactory::getDatabaseConnection();
36
$blocksadmin = new Blocksadmin($xoopsDB, $helper);
37
38
$xoopsModule = XoopsModule::getByDirname($moduleDirName);
39
40
if (!is_object($GLOBALS['xoopsUser']) || !is_object($xoopsModule)
41
    || !$GLOBALS['xoopsUser']->isAdmin($xoopsModule->mid())) {
42
    exit(constant('CO_' . $moduleDirNameUpper . '_' . 'ERROR403'));
43
}
44
if ($GLOBALS['xoopsUser']->isAdmin($xoopsModule->mid())) {
45
    require_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
46
47
    $op = Request::getCmd('op', 'list');
48
    if (!empty($_POST)) {
49
        $ok             = Request::getInt('ok', 0, 'POST');
50
        $confirm_submit = Request::getCmd('confirm_submit', '', 'POST');
51
        $submit         = Request::getString('submit', '', 'POST');
52
        $bside          = Request::getString('bside', '0', 'POST');
53
        $bweight        = Request::getString('bweight', '0', 'POST');
54
        $bvisible       = Request::getString('bvisible', '0', 'POST');
55
        $bmodule        = Request::getArray('bmodule', [], 'POST');
56
        $btitle         = Request::getString('btitle', '', 'POST');
57
        $bcachetime     = Request::getString('bcachetime', '0', 'POST');
58
        $groups         = Request::getArray('groups', [], 'POST');
59
        $options        = Request::getArray('options', [], 'POST');
60
        $submitblock    = Request::getString('submitblock', '', 'POST');
61
        $fct            = Request::getString('fct', '', 'POST');
62
        $title          = Request::getString('title', '', 'POST');
63
        $side           = Request::getString('side', '0', 'POST');
64
        $weight         = Request::getString('weight', '0', 'POST');
65
        $visible        = Request::getString('visible', '0', 'POST');
66
    }
67
68
    if ('list' === $op) {
69
        //        xoops_cp_header();
70
        $blocksadmin->listBlocks();
71
        require_once __DIR__ . '/admin_footer.php';
72
        exit();
73
    }
74
75
    if (\in_array($op, ['edit', 'edit_ok', 'delete', 'delete_ok', 'clone', 'clone_ok'])) {
76
        $bid = Request::getInt('bid', 0);
77
78
        if ('clone' === $op) {
79
            $blocksadmin->cloneBlock($bid);
80
        }
81
82
        if ('delete' === $op) {
83
            if (1 === $ok) {
84
                //            if (!$GLOBALS['xoopsSecurity']->check()) {
85
                //                redirect_header($helper->url('admin/blocksadmin.php'), 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors()));
86
                //            }
87
                $blocksadmin->deleteBlock($bid);
88
            } else {
89
                //            xoops_cp_header();
90
                xoops_confirm(['ok' => 1, 'op' => 'delete', 'bid' => $bid], 'blocksadmin.php', constant('CO_' . $moduleDirNameUpper . '_' . 'DELETE_BLOCK_CONFIRM'), constant('CO_' . $moduleDirNameUpper . '_' . 'CONFIRM'), true);
91
                xoops_cp_footer();
92
            }
93
        }
94
95
        if ('edit' === $op) {
96
            $blocksadmin->editBlock($bid);
97
        }
98
99
        if ('edit_ok' === $op) {
100
            $blocksadmin->updateBlock($bid, $btitle, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options, $groups);
101
        }
102
103
        if ('clone_ok' === $op) {
104
            $blocksadmin->isBlockCloned($bid, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options, $groups);
105
        }
106
    }
107
108
    if ('order' === $op) {
109
        $bid = Request::getArray('bid', []);
110
111
        $title      = Request::getArray('title', [], 'POST');
112
        $side       = Request::getArray('side', [], 'POST');
113
        $weight     = Request::getArray('weight', [], 'POST');
114
        $visible    = Request::getArray('visible', [], 'POST');
115
        $bcachetime = Request::getArray('bcachetime', [], 'POST');
116
117
        $oldtitle      = Request::getArray('oldtitle', [], 'POST');
118
        $oldside       = Request::getArray('oldside', [], 'POST');
119
        $oldweight     = Request::getArray('oldweight', [], 'POST');
120
        $oldvisible    = Request::getArray('oldvisible', [], 'POST');
121
        $oldgroups     = Request::getArray('oldgroups', [], 'POST');
122
        $oldbcachetime = Request::getArray('oldcachetime', [], 'POST');
123
124
        $blocksadmin->orderBlock(
125
            $bid,
126
            $oldtitle,
127
            $oldside,
128
            $oldweight,
129
            $oldvisible,
130
            $oldgroups,
131
            $oldbcachetime,
132
            $title,
133
            $weight,
134
            $visible,
135
            $side,
136
            $bcachetime,
137
            $groups,
138
            $bmodule = null
139
        );
140
    }
141
} else {
142
    echo constant('CO_' . $moduleDirNameUpper . '_' . 'ERROR403');
143
}
144
145
require __DIR__ . '/admin_footer.php';
146