Completed
Push — master ( 8f6f38...60a482 )
by Michael
04:32 queued 02:16
created

MymenusMenus::getForm()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 54
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 31
nc 8
nop 1
dl 0
loc 54
rs 9.0306
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
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 27 and the first side effect is on line 20.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
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       The XOOPS Project http://sourceforge.net/projects/xoops/
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]>
18
 */
19
20
defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
21
22
include_once dirname(__DIR__) . '/include/common.php';
23
24
/**
25
 * Class MymenusMenus
26
 */
27
class MymenusMenus extends XoopsObject
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
28
{
29
    /**
30
     * @var MymenusMenus
31
     * @access private
32
     */
33
    private $mymenus = null;
34
35
    /**
36
     * constructor
37
     */
38
    public function __construct()
39
    {
40
        $this->mymenus = MymenusMymenus::getInstance();
41
        $this->db      = XoopsDatabaseFactory::getDatabaseConnection();
42
        $this->initVar('id', XOBJ_DTYPE_INT);
43
        $this->initVar('title', XOBJ_DTYPE_TXTBOX);
44
        $this->initVar('css', XOBJ_DTYPE_TXTBOX);
45
    }
46
47
    /**
48
     * Get {@link XoopsThemeForm} for adding/editing items
49
     *
50
     * @param  bool|string $action
51
     * @return XoopsThemeForm {@link XoopsThemeForm}
52
     */
53
    public function getForm($action = false)
54
    {
55
        //        $grouppermHandler = xoops_gethandler('groupperm');
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
56
        //
57
        xoops_load('XoopsFormLoader');
58
        //
59
        if ($action === false) {
60
            //            $action = $_SERVER['REQUEST_URI'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
61
            $action = XoopsRequest::getString('REQUEST_URI', '', 'SERVER');
62
        }
63
        //
64
        //        $isAdmin = mymenusUserIsAdmin();
0 ignored issues
show
Unused Code Comprehensibility introduced by
45% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
65
        //        $groups  = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getGroups() : array(0 => XOOPS_GROUP_ANONYMOUS);
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
66
        //
67
        $title = $this->isNew() ? _AM_MYMENUS_MENUS_ADD : _AM_MYMENUS_MENUS_EDIT;
68
        //
69
        $form = new XoopsThemeForm($title, 'moneusform', $action, 'post', true);
70
        $form->setExtra('enctype="multipart/form-data"');
71
        // menus: title
72
        $menusTitleText = new XoopsFormText(_AM_MYMENUS_MENU_TITLE, 'title', 50, 255, $this->getVar('title', 'e'));
73
        $menusTitleText->setDescription(_AM_MYMENUS_MENU_TITLE_DESC);
74
        $form->addElement($menusTitleText, true);
75
        // menus: css
76
        $menusCssText = new XoopsFormText(_AM_MYMENUS_MENU_CSS, 'css', 50, 255, $this->getVar('css', 'e'));
77
        $menusCssText->setDescription(_AM_MYMENUS_MENU_CSS_DESC);
78
        $form->addElement($menusCssText, false);
79
        // form: button tray
80
        $buttonTray = new XoopsFormElementTray('', '');
81
        $buttonTray->addElement(new XoopsFormHidden('op', 'save'));
82
        //
83
        $buttonSubmit = new XoopsFormButton('', '', _SUBMIT, 'submit');
84
        $buttonSubmit->setExtra('onclick="this.form.elements.op.value=\'save\'"');
85
        $buttonTray->addElement($buttonSubmit);
86
        if ($this->isNew()) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
87
            // NOP
88
        } else {
89
            $form->addElement(new XoopsFormHidden('id', (int)$this->getVar('id')));
90
            //
91
            $buttonDelete = new XoopsFormButton('', '', _DELETE, 'submit');
92
            $buttonDelete->setExtra('onclick="this.form.elements.op.value=\'delete\'"');
93
            $buttonTray->addElement($buttonDelete);
94
        }
95
        $buttonReset = new XoopsFormButton('', '', _RESET, 'reset');
96
        $buttonTray->addElement($buttonReset);
97
        //
98
        $buttonCancel = new XoopsFormButton('', '', _CANCEL, 'button');
99
        $buttonCancel->setExtra('onclick="history.go(-1)"');
100
        $buttonTray->addElement($buttonCancel);
101
        //
102
        $form->addElement($buttonTray);
103
104
        //
105
        return $form;
106
    }
107
}
108
109
/**
110
 * Class MymenusMenusHandler
111
 */
112
class MymenusMenusHandler extends XoopsPersistableObjectHandler
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
113
{
114
    /**
115
     * @var MymenusMymenus
116
     * @access private
117
     */
118
    private $mymenus = null;
119
120
    /**
121
     * @param null|XoopsDatabase $db
122
     */
123
    public function __construct(XoopsDatabase $db)
124
    {
125
        parent::__construct($db, 'mymenus_menus', 'MymenusMenus', 'id', 'title', 'css');
126
        $this->mymenus = MymenusMymenus::getInstance();
127
    }
128
}
129