Passed
Push — master ( 5c9a79...879726 )
by Michael
02:51 queued 01:58
created

MymenusLinksUtility::mymenusAdminForm()   C

Complexity

Conditions 8
Paths 60

Size

Total Lines 118
Code Lines 72

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 72
nc 60
nop 3
dl 0
loc 118
rs 5.2676
c 0
b 0
f 0

How to fix   Long Method   

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
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       XOOPS Project (https://xoops.org)
14
 * @license         http://www.gnu.org/licenses/gpl-2.0.html GNU Public License
15
 * @package         Mymenus
16
 * @since           1.0
17
 * @author          trabis <[email protected]>, bleekk <[email protected]>
18
 */
19
20
use Xmf\Request;
0 ignored issues
show
Bug introduced by
The type Xmf\Request was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
21
use XoopsModules\Mymenus;
22
23
require __DIR__   . '/admin_header.php';
24
25
$currentFile = basename(__FILE__);
26
27
$mymenusTpl       = new \XoopsTpl(); // will be removed???
0 ignored issues
show
Bug introduced by
The type XoopsTpl was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
28
$mymenusAdminPage = 'links.php'; // will be removed???
29
30
$menusCriteria = new \CriteriaCompo();
0 ignored issues
show
Bug introduced by
The type CriteriaCompo was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
31
$menusCriteria->setSort('id');
32
$menusCriteria->setOrder('ASC');
33
$menusList = $helper->getHandler('Menus')->getList($menusCriteria);
34
if (!$menusList) {
35
    redirect_header('menus.php', 1, _AM_MYMENUS_MSG_NOMENUS);
0 ignored issues
show
Bug introduced by
The function redirect_header was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

35
    /** @scrutinizer ignore-call */ 
36
    redirect_header('menus.php', 1, _AM_MYMENUS_MSG_NOMENUS);
Loading history...
36
}
37
38
$valid_menu_ids = array_keys($menusList);
39
$mid            = Request::getInt('mid', Request::getInt('mid', '', 'POST'), 'GET');
40
if ($mid && in_array($mid, $valid_menu_ids)) {
41
    $menuTitle = $menusList[$mid];
42
} else {
43
    $keys      = array_keys($menusList);
44
    $mid       = $valid_menu_ids[0]; //force menu id to first valid menu id in the list
45
    $menuTitle = $menusList[$mid]; // and get it's title
46
}
47
$mymenusTpl->assign('mid', $mid);
48
$mymenusTpl->assign('menuTitle', $menuTitle);
49
$mymenusTpl->assign('menus_list', $menusList);
50
51
$id      = Request::getInt('id', 0);
52
$pid     = Request::getInt('pid', 0);
53
$start   = Request::getInt('start', 0);
54
$weight  = Request::getInt('weight', 0);
55
$visible = Request::getInt('visible', 0);
56
57
$op = Request::getString('op', 'list');
58
switch ($op) {
59
60
/*
61
        case 'form':
62
            xoops_cp_header();
63
            $adminObject  = \Xmf\Module\Admin::getInstance();
64
            $adminObject->displayNavigation($currentFile);
65
            //
66
            echo editLink(null, $pid, $mid);
67
            //
68
            require __DIR__   . '/admin_footer.php';
69
            break;
70
*/
71
72
    case 'edit':
73
        echo Mymenus\LinksUtility::editLink($id, null, $mid);
74
        break;
75
76
    case 'add':
77
        Mymenus\LinksUtility::addLink($mid);
78
        break;
79
80
    case 'save':
81
        Mymenus\LinksUtility::saveLink($id, $mid);
82
        break;
83
84
    case 'delete':
85
        $id       = Request::getInt('id', null);
86
        $linksObj = $helper->getHandler('Links')->get($id);
87
        if (true === Request::getBool('ok', false, 'POST')) {
88
            if (!$GLOBALS['xoopsSecurity']->check()) {
89
                redirect_header($currentFile, 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors()));
90
            }
91
            //get sub item
92
            $linksCriteria = new \CriteriaCompo();
93
            $linksCriteria->add(new \Criteria('id', $id));
0 ignored issues
show
Bug introduced by
The type Criteria was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
94
            $linksCriteria->add(new \Criteria('pid', $id), 'OR');
95
            //first delete links level 2
96
            $query  = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('mymenus_links');
97
            $query  .= ' WHERE pid = (SELECT id FROM (SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('mymenus_links') . " WHERE pid = {$id}) AS sec);";
98
            $result = $GLOBALS['xoopsDB']->queryF($query);
99
            //delete links level 0 and 1
100
            if (!$helper->getHandler('Links')->deleteAll($linksCriteria)) {
101
                xoops_cp_header();
0 ignored issues
show
Bug introduced by
The function xoops_cp_header was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

101
                /** @scrutinizer ignore-call */ 
102
                xoops_cp_header();
Loading history...
102
                xoops_error(_AM_MYMENUS_MSG_ERROR, $linksObj->getVar('id'));
0 ignored issues
show
Bug introduced by
The function xoops_error was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

102
                /** @scrutinizer ignore-call */ 
103
                xoops_error(_AM_MYMENUS_MSG_ERROR, $linksObj->getVar('id'));
Loading history...
103
                xoops_cp_footer();
0 ignored issues
show
Bug introduced by
The function xoops_cp_footer was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

103
                /** @scrutinizer ignore-call */ 
104
                xoops_cp_footer();
Loading history...
104
                exit();
105
            }
106
            redirect_header($currentFile, 3, _AM_MYMENUS_MSG_DELETE_LINK_SUCCESS);
107
        } else {
108
            xoops_cp_header();
109
            xoops_confirm(['ok' => true, 'id' => $id, 'op' => 'delete'], //                $_SERVER['REQUEST_URI'],
0 ignored issues
show
Bug introduced by
The function xoops_confirm was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

109
            /** @scrutinizer ignore-call */ 
110
            xoops_confirm(['ok' => true, 'id' => $id, 'op' => 'delete'], //                $_SERVER['REQUEST_URI'],
Loading history...
110
                          Request::getString('REQUEST_URI', '', 'SERVER'), sprintf(_AM_MYMENUS_LINKS_SUREDEL, $linksObj->getVar('title')));
111
            require __DIR__   . '/admin_footer.php';
112
        }
113
        break;
114
115
    case 'move':
116
        xoops_cp_header();
117
        $adminObject = \Xmf\Module\Admin::getInstance();
0 ignored issues
show
Bug introduced by
The type Xmf\Module\Admin was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
118
        $adminObject->displayNavigation($currentFile);
119
        //
120
        Mymenus\LinksUtility::moveLink($id, $weight);
121
        echo Mymenus\LinksUtility::listLinks($start, $mid);
122
        //
123
        require __DIR__   . '/admin_footer.php';
124
        break;
125
126
    case 'toggle':
127
        Mymenus\LinksUtility::toggleLinkVisibility($id, $visible);
128
        break;
129
130
    case 'order':
131
        $test  = [];
132
        $order = Request::getString('mod', '', 'POST');
133
        parse_str($order, $test);
134
        $i = 1;
135
        foreach ($test['mod'] as $order => $value) {
136
            $linksObj = $helper->getHandler('Links')->get($order);
137
            $linksObj->setVar('weight', ++$i);
138
            // Set submenu
139
            if (isset($value)) {
140
                $linksObj->setVar('pid', $value);
141
            } else {
142
                $linksObj->setVar('pid', 0);
143
            }
144
            $helper->getHandler('Links')->insert($linksObj);
145
            $helper->getHandler('Links')->updateWeights($linksObj);
146
        }
147
        break;
148
149
    case 'list':
150
    default:
151
        xoops_cp_header();
152
        $adminObject = \Xmf\Module\Admin::getInstance();
153
        $adminObject->displayNavigation($currentFile);
154
        // Add module stylesheet
155
        $GLOBALS['xoTheme']->addStylesheet(XOOPS_URL . '/modules/system/css/ui/' . xoops_getModuleOption('jquery_theme', 'system') . '/ui.all.css');
0 ignored issues
show
Bug introduced by
The constant XOOPS_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The function xoops_getModuleOption was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

155
        $GLOBALS['xoTheme']->addStylesheet(XOOPS_URL . '/modules/system/css/ui/' . /** @scrutinizer ignore-call */ xoops_getModuleOption('jquery_theme', 'system') . '/ui.all.css');
Loading history...
156
        $GLOBALS['xoTheme']->addStylesheet(XOOPS_URL . "/modules/{$helper->getDirname()}/assets/css/admin.css");
157
        $GLOBALS['xoTheme']->addStylesheet(XOOPS_URL . '/Frameworks/moduleclasses/moduleadmin/css/admin.css');
158
        // Define scripts
159
        $GLOBALS['xoTheme']->addScript('browse.php?Frameworks/jquery/plugins/jquery.ui.js');
160
        $GLOBALS['xoTheme']->addScript(XOOPS_URL . "/modules/{$helper->getDirname()}/assets/js/nestedSortable.js");
161
        //$GLOBALS['xoTheme']->addScript(XOOPS_URL . '/modules/{$mymenus->dirname}/assets/js/switchButton.js');
162
        $GLOBALS['xoTheme']->addScript(XOOPS_URL . "/modules/{$helper->getDirname()}/assets/js/links.js");
163
        echo Mymenus\LinksUtility::listLinks($start, $mid);
164
        // Disable xoops debugger in dialog window
165
//        require $GLOBALS['xoops']->path('/class/logger/xoopslogger.php');
166
        xoops_load('xoopslogger');
0 ignored issues
show
Bug introduced by
The function xoops_load was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

166
        /** @scrutinizer ignore-call */ 
167
        xoops_load('xoopslogger');
Loading history...
167
        $xoopsLogger            = XoopsLogger::getInstance();
0 ignored issues
show
Bug introduced by
The type XoopsLogger was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
168
        $xoopsLogger->activated = true;
169
        error_reporting(-1);
170
        //
171
        require __DIR__   . '/admin_footer.php';
172
        break;
173
}
174