Passed
Pull Request — master (#81)
by Michael
02:55
created

SuspensionsForm::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 101
Code Lines 46

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 46
dl 0
loc 101
rs 9.1781
c 1
b 0
f 0
cc 2
nc 2
nop 1

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
declare(strict_types=1);
4
5
namespace XoopsModules\Yogurt\Form;
6
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
12
 This program is distributed in the hope that it will be useful,
13
 but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
*/
16
17
/**
18
 * @category        Module
19
 * @package         yogurt
20
 * @copyright       {@link https://xoops.org/ XOOPS Project}
21
 * @license         GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
22
 * @author          Marcello Brandão aka  Suico, Mamba, LioMJ  <https://xoops.org>
23
 */
24
25
use Xmf\Module\Helper\Permission;
26
use XoopsFormButton;
27
use XoopsFormHidden;
28
use XoopsFormLabel;
29
use XoopsFormText;
30
use XoopsFormTextArea;
31
use XoopsModules\Yogurt;
32
use XoopsThemeForm;
33
34
require_once \dirname(__DIR__, 2) . '/include/common.php';
35
36
$moduleDirName = \basename(\dirname(__DIR__, 2));
37
//$helper = Yogurt\Helper::getInstance();
38
$permHelper = new Permission();
39
40
\xoops_load('XoopsFormLoader');
41
42
/**
43
 * Class SuspensionsForm
44
 */
45
class SuspensionsForm extends XoopsThemeForm
46
{
47
    public $targetObject;
48
49
    public $helper;
50
51
    /**
52
     * Constructor
53
     *
54
     * @param $target
55
     */
56
57
    public function __construct($target)
58
    {
59
        $this->helper = $target->helper;
60
61
        $this->targetObject = $target;
62
63
        $title = $this->targetObject->isNew() ? \sprintf(\AM_YOGURT_SUSPENSIONS_ADD) : \sprintf(
64
            \AM_YOGURT_SUSPENSIONS_EDIT
65
        );
66
67
        parent::__construct($title, 'form', \xoops_getenv('SCRIPT_NAME'), 'post', true);
68
69
        $this->setExtra('enctype="multipart/form-data"');
70
71
        //include ID field, it's needed so the module knows if it is a new form or an edited form
72
73
        $hidden = new XoopsFormHidden(
74
            'uid', $this->targetObject->getVar(
75
            'uid'
76
        )
77
        );
78
79
        $this->addElement($hidden);
80
81
        unset($hidden);
82
83
        // Uid
84
85
        $this->addElement(
86
            new XoopsFormLabel(\AM_YOGURT_SUSPENSIONS_UID, $this->targetObject->getVar('uid'), 'uid')
87
        );
88
89
        // Old_pass
90
91
        $this->addElement(
92
            new XoopsFormText(
93
                \AM_YOGURT_SUSPENSIONS_OLD_PASS, 'old_pass', 50, 255, $this->targetObject->getVar(
94
                'old_pass'
95
            )
96
            ),
97
            false
98
        );
99
100
        // Old_email
101
102
        $this->addElement(
103
            new XoopsFormText(
104
                \AM_YOGURT_SUSPENSIONS_OLD_EMAIL, 'old_email', 50, 255, $this->targetObject->getVar(
105
                'old_email'
106
            )
107
            ),
108
            false
109
        );
110
111
        // Old_signature
112
113
        $this->addElement(
114
            new XoopsFormTextArea(
115
                \AM_YOGURT_SUSPENSIONS_OLD_SIGNATURE, 'old_signature', $this->targetObject->getVar(
116
                'old_signature'
117
            ), 4, 47
118
            ),
119
            false
120
        );
121
122
        // Suspension_time
123
124
        $this->addElement(
125
            new XoopsFormText(
126
                \AM_YOGURT_SUSPENSIONS_SUSPENSION_TIME, 'suspension_time', 50, 255, $this->targetObject->getVar(
127
                'suspension_time'
128
            )
129
            ),
130
            false
131
        );
132
133
        // Old_enc_type
134
135
        $this->addElement(
136
            new XoopsFormText(
137
                \AM_YOGURT_SUSPENSIONS_OLD_ENC_TYPE, 'old_enc_type', 50, 255, $this->targetObject->getVar(
138
                'old_enc_type'
139
            )
140
            ),
141
            false
142
        );
143
144
        // Old_pass_expired
145
146
        $this->addElement(
147
            new XoopsFormText(
148
                \AM_YOGURT_SUSPENSIONS_OLD_PASS_EXPIRED, 'old_pass_expired', 50, 255, $this->targetObject->getVar(
149
                'old_pass_expired'
150
            )
151
            ),
152
            false
153
        );
154
155
        $this->addElement(new XoopsFormHidden('op', 'save'));
156
157
        $this->addElement(new XoopsFormButton('', 'submit', \_SUBMIT, 'submit'));
158
    }
159
}
160