PreferencesForm::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 60
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 33
nc 3
nop 1
dl 0
loc 60
rs 9.392
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
namespace XoopsModules\Xoositemap\Form;
4
5
/**
6
 * Xoositemap module
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       XOOPS Project (https://xoops.org)
16
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
17
 * @package         Xoositemap
18
 * @since           2.6.0
19
 * @author          Laurent JEN (Aka DuGris)
20
21
 */
22
class PreferencesForm extends \Xoops\Form\ThemeForm
23
{
24
    private $config = [];
0 ignored issues
show
introduced by
The private property $config is not used, and could be removed.
Loading history...
25
26
    /**
27
     * @param string $config
28
     * @internal param null $obj
29
     */
30
    public function __construct($config)
31
    {
32
        extract($config);
0 ignored issues
show
Bug introduced by
$config of type string is incompatible with the type array expected by parameter $var_array of extract(). ( Ignorable by Annotation )

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

32
        extract(/** @scrutinizer ignore-type */ $config);
Loading history...
33
34
        parent::__construct('', 'form_preferences', 'preferences.php', 'post', true);
35
        $this->setExtra('enctype="multipart/form-data"');
36
37
        $tabTray = new \Xoops\Form\TabTray('', 'uniqueid');
38
39
        /**
40
         * Main page
41
         */
42
        $tab1 = new \Xoops\Form\Tab(_XOO_CONFIG_MAINPAGE, 'tabid-1');
43
        $tab1->addElement(new \Xoops\Form\RadioYesNo(_XOO_CONFIG_MAIN, 'xoositemap_main', $xoositemap_main));
44
45
        // main
46
        $tab1->addElement(new \Xoops\Form\RadioYesNo(_XOO_CONFIG_SUBCAT, 'xoositemap_subcat', $xoositemap_subcat));
47
48
        // welcome
49
        $tab1->addElement(new \Xoops\Form\TextArea(_XOO_CONFIG_WELCOME, 'xoositemap_welcome', $xoositemap_welcome, 12, 12));
50
51
        /**
52
         * Main page
53
         */
54
        $tab2 = new \Xoops\Form\Tab(_XOO_CONFIG_MODULES, 'tabid-2');
55
        $systemModule = new \SystemModule();
56
        $installed    = $systemModule->getModuleList();
57
        $modules = new \Xoops\Form\Select(_XOO_CONFIG_MODULES_SELECT, 'xoositemapModule', $xoositemapModule, count($installed) - 1, true);
58
        foreach ($installed as $module) {
59
            $plugin = \Xoops\Module\Plugin::getPlugin($module->getVar('dirname'), 'xoositemap');
60
            if (is_object($plugin)) {
61
                $modules->addOption($module->getVar('dirname'), $module->getVar('dirname'));
62
            }
63
        }
64
        $tab2->addElement($modules);
65
66
        $tabTray->addElement($tab1);
67
        $tabTray->addElement($tab2);
68
        $this->addElement($tabTray);
69
70
        /**
71
         * Buttons
72
         */
73
        $buttonTray = new \Xoops\Form\ElementTray('', '');
74
        $buttonTray->addElement(new \Xoops\Form\Hidden('op', 'save'));
75
76
        $buttonSubmit = new \Xoops\Form\Button('', 'submit', \XoopsLocale::A_SUBMIT, 'submit');
77
        $buttonSubmit->setClass('btn btn-success');
78
        $buttonTray->addElement($buttonSubmit);
79
80
        $buttonReset = new \Xoops\Form\Button('', 'reset', \XoopsLocale::A_RESET, 'reset');
81
        $buttonReset->setClass('btn btn-warning');
82
        $buttonTray->addElement($buttonReset);
83
84
        $buttonCancel = new \Xoops\Form\Button('', 'cancel', \XoopsLocale::A_CANCEL, 'button');
85
        $buttonCancel->setExtra("onclick='javascript:history.go(-1);'");
0 ignored issues
show
Deprecated Code introduced by
The function Xoops\Form\Element::setExtra() has been deprecated: please use attributes for event scripting ( Ignorable by Annotation )

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

85
        /** @scrutinizer ignore-deprecated */ $buttonCancel->setExtra("onclick='javascript:history.go(-1);'");

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
86
        $buttonCancel->setClass('btn btn-danger');
87
        $buttonTray->addElement($buttonCancel);
88
89
        $this->addElement($buttonTray);
90
    }
91
}
92