Passed
Pull Request — master (#187)
by Michael
16:36
created

updateBlock()   B

Complexity

Conditions 11
Paths 18

Size

Total Lines 72
Code Lines 46

Duplication

Lines 0
Ratio 0 %

Importance

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

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