GroupPermForm::render()   B
last analyzed

Complexity

Conditions 11
Paths 84

Size

Total Lines 55
Code Lines 41

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 11
eloc 41
nc 84
nop 0
dl 0
loc 55
rs 7.3166
c 1
b 0
f 0

How to fix   Long Method    Complexity   

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
namespace XoopsModules\Extgallery;
4
5
/**
6
 * ExtGallery Class Manager
7
 *
8
 * You may not change or alter any portion of this comment or credits
9
 * of supporting developers from this source code or any supporting source code
10
 * which is considered copyrighted (c) material of the original comment or credit authors.
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
 *
15
 * @copyright   {@link https://xoops.org/ XOOPS Project}
16
 * @license     GNU GPL 2 (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
17
 * @author      Zoullou (http://www.zoullou.net)
18
 * @package     ExtGallery
19
 */
20
21
use XoopsModules\Extgallery;
22
23
require_once XOOPS_ROOT_PATH . '/class/xoopsform/grouppermform.php';
24
25
/**
26
 * Class Extgallery\GroupPermForm
27
 */
28
class GroupPermForm extends \XoopsGroupPermForm
29
{
30
    /**
31
     * Extgallery\GroupPermForm constructor.
32
     * @param string $title
33
     * @param string $modid
34
     * @param string $permname
35
     * @param string $permdesc
36
     * @param string $url
37
     * @param bool   $anonymous
38
     */
39
    public function __construct($title, $modid, $permname, $permdesc, $url = '', $anonymous = true)
40
    {
41
        parent::__construct($title, $modid, $permname, $permdesc, $url, $anonymous);
42
    }
43
44
    /**
45
     * @return string|void
46
     */
47
    public function render()
48
    {
49
        // load all child ids for javascript codes
50
        foreach (\array_keys($this->_itemTree) as $item_id) {
51
            $this->_itemTree[$item_id]['allchild'] = [];
52
            $this->_loadAllChildItemIds($item_id, $this->_itemTree[$item_id]['allchild']);
53
        }
54
        /** @var \XoopsGroupPermHandler $grouppermHandler */
55
        $grouppermHandler = \xoops_getHandler('groupperm');
56
        /** @var \XoopsMemberHandler $memberHandler */
57
        $memberHandler = \xoops_getHandler('member');
58
        $glist         = $memberHandler->getGroupList();
59
        foreach (\array_keys($glist) as $i) {
60
            if (XOOPS_GROUP_ANONYMOUS == $i && !$this->_showAnonymous) {
61
                continue;
62
            }
63
            // get selected item id(s) for each group
64
            $selected = $grouppermHandler->getItemIds($this->_permName, $i, $this->_modid);
65
            $ele      = new Extgallery\GroupFormCheckBox($glist[$i], 'perms[' . $this->_permName . ']', $i, $selected);
66
            $ele->setOptionTree($this->_itemTree);
67
            $this->addElement($ele);
68
            unset($ele);
69
        }
70
        $tray = new \XoopsFormElementTray('');
71
        $tray->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
72
        $tray->addElement(new \XoopsFormButton('', 'reset', _CANCEL, 'reset'));
73
        $this->addElement($tray);
74
        echo '<h4>' . $this->getTitle() . '</h4>';
75
        if ($this->_permDesc) {
76
            echo $this->_permDesc . '<br><br>';
77
        }
78
        echo "<form name='" . $this->getName() . '\' id=\'' . $this->getName() . '\' action=\'' . $this->getAction() . '\' method=\'' . $this->getMethod() . '\'' . $this->getExtra() . ">\n<table width='100%' class='outer' cellspacing='1' valign='top'>\n";
79
        $elements = &$this->getElements();
80
        $hidden   = '';
81
        foreach (\array_keys($elements) as $i) {
82
            if (!\is_object($elements[$i])) {
83
                echo $elements[$i];
0 ignored issues
show
Bug introduced by
Are you sure $elements[$i] of type XoopsFormElement can be used in echo? Consider adding a __toString()-method. ( Ignorable by Annotation )

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

83
                echo /** @scrutinizer ignore-type */ $elements[$i];
Loading history...
84
            } elseif (!$elements[$i]->isHidden()) {
85
                echo "<tr valign='top' align='left'><td class='head'>" . $elements[$i]->getCaption();
86
                if ('' != $elements[$i]->getDescription()) {
87
                    echo '<br><br><span style="font-weight: normal;">' . $elements[$i]->getDescription() . '</span>';
88
                }
89
                echo "</td>\n<td class='even'>\n";
90
                if (\is_a($elements[$i], 'Extgallery\GroupFormCheckBox')) {
91
                    $elements[$i]->render();
92
                } else {
93
                    echo $elements[$i]->render();
0 ignored issues
show
Bug introduced by
Are you sure the usage of $elements[$i]->render() targeting XoopsFormElement::render() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
94
                }
95
                echo "\n</td></tr>\n";
96
            } else {
97
                $hidden .= $elements[$i]->render();
0 ignored issues
show
Bug introduced by
Are you sure the usage of $elements[$i]->render() targeting XoopsFormElement::render() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
98
            }
99
        }
100
        echo "</table>$hidden</form>";
101
        echo $this->renderValidationJS(true);
102
    }
103
}
104