Passed
Pull Request — master (#187)
by Michael
16:36
created

SuspensionsForm::__construct()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 101
Code Lines 69

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 69
nc 2
nop 1
dl 0
loc 101
rs 8.6763
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 declare(strict_types=1);
2
3
namespace XoopsModules\Suico\Form;
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
/**
16
 * @category        Module
17
 * @copyright       {@link https://xoops.org/ XOOPS Project}
18
 * @license         GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
19
 * @author          Marcello Brandão aka  Suico, Mamba, LioMJ  <https://xoops.org>
20
 */
21
22
use Xmf\Module\Helper\Permission;
23
use XoopsFormButton;
24
use XoopsFormHidden;
25
use XoopsFormLabel;
26
use XoopsFormText;
27
use XoopsFormTextArea;
28
use XoopsModules\Suico;
29
use XoopsThemeForm;
30
31
require_once \dirname(__DIR__, 2) . '/include/common.php';
32
$moduleDirName = \basename(\dirname(__DIR__, 2));
33
//$helper = Suico\Helper::getInstance();
34
$permHelper = new Permission();
35
\xoops_load('XoopsFormLoader');
36
37
/**
38
 * Class SuspensionsForm
39
 */
40
class SuspensionsForm extends XoopsThemeForm
41
{
42
    public $targetObject;
43
    public $helper;
44
45
    /**
46
     * Constructor
47
     *
48
     * @param $target
49
     */
50
    public function __construct($target)
51
    {
52
        $this->helper       = $target->helper;
53
        $this->targetObject = $target;
54
        $title              = $this->targetObject->isNew() ? \AM_SUICO_SUSPENSIONS_ADD :
55
            \AM_SUICO_SUSPENSIONS_EDIT;
56
        parent::__construct($title, 'form', \xoops_getenv('SCRIPT_NAME'), 'post', true);
57
        $this->setExtra('enctype="multipart/form-data"');
58
        //include ID field, it's needed so the module knows if it is a new form or an edited form
59
        $hidden = new XoopsFormHidden(
60
            'uid',
61
            $this->targetObject->getVar(
62
                'uid'
63
            )
64
        );
65
        $this->addElement($hidden);
66
        unset($hidden);
67
        // Uid
68
        $this->addElement(
69
            new XoopsFormLabel(\AM_SUICO_SUSPENSIONS_UID, $this->targetObject->getVar('uid'), 'uid')
70
        );
71
        // Old_pass
72
        $this->addElement(
73
            new XoopsFormText(
74
                \AM_SUICO_SUSPENSIONS_OLD_PASS,
75
                'old_pass',
76
                50,
77
                255,
78
                $this->targetObject->getVar(
79
                    'old_pass'
80
                )
81
            ),
82
            false
83
        );
84
        // Old_email
85
        $this->addElement(
86
            new XoopsFormText(
87
                \AM_SUICO_SUSPENSIONS_OLD_EMAIL,
88
                'old_email',
89
                50,
90
                255,
91
                $this->targetObject->getVar(
92
                    'old_email'
93
                )
94
            ),
95
            false
96
        );
97
        // Old_signature
98
        $this->addElement(
99
            new XoopsFormTextArea(
100
                \AM_SUICO_SUSPENSIONS_OLD_SIGNATURE,
101
                'old_signature',
102
                $this->targetObject->getVar(
103
                    'old_signature'
104
                ),
105
                4,
106
                47
107
            ),
108
            false
109
        );
110
        // Suspension_time
111
        $this->addElement(
112
            new XoopsFormText(
113
                \AM_SUICO_SUSPENSIONS_SUSPENSION_TIME,
114
                'suspension_time',
115
                50,
116
                255,
117
                $this->targetObject->getVar(
118
                    'suspension_time'
119
                )
120
            ),
121
            false
122
        );
123
        // Old_enc_type
124
        $this->addElement(
125
            new XoopsFormText(
126
                \AM_SUICO_SUSPENSIONS_OLD_ENC_TYPE,
127
                'old_enc_type',
128
                50,
129
                255,
130
                $this->targetObject->getVar(
131
                    'old_enc_type'
132
                )
133
            ),
134
            false
135
        );
136
        // Old_pass_expired
137
        $this->addElement(
138
            new XoopsFormText(
139
                \AM_SUICO_SUSPENSIONS_OLD_PASS_EXPIRED,
140
                'old_pass_expired',
141
                50,
142
                255,
143
                $this->targetObject->getVar(
144
                    'old_pass_expired'
145
                )
146
            ),
147
            false
148
        );
149
        $this->addElement(new XoopsFormHidden('op', 'save'));
150
        $this->addElement(new XoopsFormButton('', 'submit', \_SUBMIT, 'submit'));
151
    }
152
}
153