FormTabTray::render()   B
last analyzed

Complexity

Conditions 9
Paths 30

Size

Total Lines 53
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
eloc 37
nc 30
nop 0
dl 0
loc 53
rs 7.7724
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\Tdmcreate\Form;
2
3
use XoopsModules\Tdmcreate;
4
5
/*
6
 You may not change or alter any portion of this comment or credits
7
 of supporting developers from this source code or any supporting source code
8
 which is considered copyrighted (c) material of the original comment or credit authors.
9
10
 This program is distributed in the hope that it will be useful,
11
 but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
*/
14
/**
15
 * TabTray - a form tray for tabs.
16
 *
17
 * @category  XoopsFormTabTray
18
 *
19
 * @author    trabis <[email protected]>
20
 * @copyright 2012-2014 XOOPS Project (https://xoops.org)
21
 * @license   GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
22
 *
23
 * @link      https://xoops.org
24
 * @since     2.0.0
25
 */
26
\XoopsLoad::load('XoopsFormElementTray');
27
28
/**
29
 * Class Tdmcreate\FormTabTray.
30
 */
31
class FormTabTray extends \XoopsFormElementTray
32
{
33
    /**
34
     * Theme to use for jquery UI.
35
     *
36
     * @var string
37
     */
38
    private $uiTheme = '';
39
    private $delimiter;
40
41
    /**
42
     * __construct.
43
     *
44
     * @param string $caption   tray caption
45
     * @param string $name      Unique identifier for this tray
46
     * @param string $uiTheme   Theme to use for jquery UI (remove? now set by theme)
47
     * @param string $delimiter delimiter
48
     */
49
    public function __construct($caption, $name, $uiTheme = 'base', $delimiter = '&nbsp;')
50
    {
51
        $this->setName($name);
52
        $this->setCaption($caption);
53
        $this->delimiter = $delimiter;
54
        $this->uiTheme = $uiTheme;
55
    }
56
57
    /**
58
     * create HTML to output the form as a table.
59
     *
60
     * @return string
61
     */
62
    public function render()
63
    {
64
        $GLOBALS['xoTheme']->addScript('browse.php?Frameworks/jquery/jquery.js');
65
        $GLOBALS['xoTheme']->addScript('browse.php?Frameworks/jquery/plugins/jquery.ui.js');
66
        $GLOBALS['xoTheme']->addStylesheet(XOOPS_URL.'/modules/system/css/ui/'.$this->uiTheme.'/ui.all.css');
67
        $GLOBALS['xoTheme']->addScript('', ['type' => 'text/javascript'], '$(function() { $("#tabs_' . $this->getName() . '").tabs(); });');
68
69
        $ret = '<div id="tabs_'.$this->getName().'">'.NWLINE;
70
        $ret .= '<ul>'.NWLINE;
71
        foreach ($this->getElements() as $ele) {
72
            if ($ele instanceof Tdmcreate\Form\FormTab) {
73
                $ret .= '<li><a href="#tab_'.$ele->getName().'"><span>'
74
                    .$ele->getCaption().'</span></a></li>'.NWLINE;
75
            }
76
        }
77
        $ret .= '</ul>'.NWLINE;
78
79
        $hidden = '';
80
        $extras = [];
81
82
        foreach ($this->getElements() as $ele) {
83
            /* @var $ele \XoopsFormElement */
84
            if (!$ele->isHidden()) {
85
                if (!$ele instanceof Tdmcreate\Form\FormRaw) {
86
                    if ($ele instanceof Tdmcreate\Form\FormTab) {
87
                        $ret .= '<div id="tab_'.$ele->getName().'">'.NWLINE;
88
                        $ret .= '<table class="outer" cellspacing="1">'.NWLINE;
89
                        $ret .= $ele->render();
90
                        $ret .= '</table>'.NWLINE;
91
                        $ret .= '</div>'.NWLINE;
92
                    } else {
93
                        $extras[] = $ele;
94
                    }
95
                } else {
96
                    $ret .= $ele->render();
97
                }
98
            } else {
99
                $hidden .= $ele->render();
0 ignored issues
show
Bug introduced by
Are you sure the usage of $ele->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...
100
            }
101
        }
102
        if (!empty($extras)) {
103
            $tray = new \XoopsFormElementTray('', $this->delimiter);
104
            foreach ($extras as $extra) {
105
                $tray->addElement($extra);
106
            }
107
            $ret .= $tray->render();
108
            $ret .= NWLINE;
109
        }
110
111
        $ret .= $hidden.NWLINE;
112
        $ret .= '</div>'.NWLINE;
113
114
        return $ret;
115
    }
116
}
117