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

SuspensionsForm::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 82
Code Lines 46

Duplication

Lines 0
Ratio 0 %

Importance

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