Passed
Push — master ( 7f0364...8531cc )
by Michael
11:47
created

updateBlock()   B

Complexity

Conditions 11
Paths 2

Size

Total Lines 55
Code Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 11
eloc 38
c 2
b 0
f 0
nc 2
nop 9
dl 0
loc 55
rs 7.3166

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