Menus::getForm()   A
last analyzed

Complexity

Conditions 4
Paths 8

Size

Total Lines 53
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 30
nc 8
nop 1
dl 0
loc 53
rs 9.44
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 namespace XoopsModules\Mymenus;
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
 This program is distributed in the hope that it will be useful,
9
 but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 */
12
13
/**
14
 * @copyright       XOOPS Project (https://xoops.org)
15
 * @license         http://www.gnu.org/licenses/gpl-2.0.html GNU Public License
16
 * @package         Mymenus
17
 * @since           1.0
18
 * @author          trabis <[email protected]>
19
 */
20
21
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...
22
use XoopsModules\Mymenus;
23
24
defined('XOOPS_ROOT_PATH') || die('Restricted access');
25
26
//require  dirname(__DIR__) . '/include/common.php';
27
28
/**
29
 * Class Menus
30
 */
31
class Menus extends \XoopsObject
0 ignored issues
show
Bug introduced by
The type XoopsObject 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...
32
{
33
    /**
34
     * @var Menus
35
     * @access private
36
     */
37
    private $helper;
38
    private $db;
39
40
    /**
41
     * constructor
42
     */
43
    public function __construct()
44
    {
45
        /** @var \XoopsModules\Mymenus\Helper $this->helper */
46
        $this->helper = \XoopsModules\Mymenus\Helper::getInstance();
47
        $this->db      = \XoopsDatabaseFactory::getDatabaseConnection();
0 ignored issues
show
Bug introduced by
The type XoopsDatabaseFactory 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...
48
        $this->initVar('id', XOBJ_DTYPE_INT);
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Mymenus\XOBJ_DTYPE_INT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
49
        $this->initVar('title', XOBJ_DTYPE_TXTBOX);
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Mymenus\XOBJ_DTYPE_TXTBOX was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
50
        $this->initVar('css', XOBJ_DTYPE_TXTBOX);
51
    }
52
53
    /**
54
     * Get {@link XoopsThemeForm} for adding/editing items
55
     *
56
     * @param  bool|string $action
57
     * @return \XoopsThemeForm <a href='psi_element://XoopsThemeForm'>XoopsThemeForm</a>
58
     */
59
    public function getForm($action = false)
60
    {
61
        //        $grouppermHandler = xoops_getHandler('groupperm');
62
        //
63
        xoops_load('XoopsFormLoader');
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

63
        /** @scrutinizer ignore-call */ 
64
        xoops_load('XoopsFormLoader');
Loading history...
64
        //
65
        if (false === $action) {
66
            //            $action = $_SERVER['REQUEST_URI'];
67
            $action = Request::getString('REQUEST_URI', '', 'SERVER');
68
        }
69
        //
70
        //        $isAdmin = mymenusUserIsAdmin();
71
        //        $groups  = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getGroups() : array(0 => XOOPS_GROUP_ANONYMOUS);
72
        //
73
        $title = $this->isNew() ? _AM_MYMENUS_MENUS_ADD : _AM_MYMENUS_MENUS_EDIT;
74
        //
75
        $form = new \XoopsThemeForm($title, 'moneusform', $action, 'post', true);
0 ignored issues
show
Bug introduced by
The type XoopsThemeForm 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...
76
        $form->setExtra('enctype="multipart/form-data"');
77
        // menus: title
78
        $menusTitleText = new \XoopsFormText(_AM_MYMENUS_MENU_TITLE, 'title', 50, 255, $this->getVar('title', 'e'));
0 ignored issues
show
Bug introduced by
The type XoopsFormText 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...
79
        $menusTitleText->setDescription(_AM_MYMENUS_MENU_TITLE_DESC);
80
        $form->addElement($menusTitleText, true);
81
        // menus: css
82
        $menusCssText = new \XoopsFormText(_AM_MYMENUS_MENU_CSS, 'css', 50, 255, $this->getVar('css', 'e'));
83
        $menusCssText->setDescription(_AM_MYMENUS_MENU_CSS_DESC);
84
        $form->addElement($menusCssText, false);
85
        // form: button tray
86
        $buttonTray = new \XoopsFormElementTray('', '');
0 ignored issues
show
Bug introduced by
The type XoopsFormElementTray 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...
87
        $buttonTray->addElement(new \XoopsFormHidden('op', 'save'));
0 ignored issues
show
Bug introduced by
The type XoopsFormHidden 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...
88
        //
89
        $buttonSubmit = new \XoopsFormButton('', '', _SUBMIT, 'submit');
0 ignored issues
show
Bug introduced by
The type XoopsFormButton 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...
Bug introduced by
The constant XoopsModules\Mymenus\_SUBMIT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
90
        $buttonSubmit->setExtra('onclick="this.form.elements.op.value=\'save\'"');
91
        $buttonTray->addElement($buttonSubmit);
92
        if ($this->isNew()) {
93
            // NOP
94
        } else {
95
            $form->addElement(new \XoopsFormHidden('id', (int)$this->getVar('id')));
96
            //
97
            $buttonDelete = new \XoopsFormButton('', '', _DELETE, 'submit');
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Mymenus\_DELETE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
98
            $buttonDelete->setExtra('onclick="this.form.elements.op.value=\'delete\'"');
99
            $buttonTray->addElement($buttonDelete);
100
        }
101
        $buttonReset = new \XoopsFormButton('', '', _RESET, 'reset');
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Mymenus\_RESET was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
102
        $buttonTray->addElement($buttonReset);
103
        //
104
        $buttonCancel = new \XoopsFormButton('', '', _CANCEL, 'button');
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Mymenus\_CANCEL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
105
        $buttonCancel->setExtra('onclick="history.go(-1)"');
106
        $buttonTray->addElement($buttonCancel);
107
        //
108
        $form->addElement($buttonTray);
109
110
        //
111
        return $form;
112
    }
113
}
114