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

FriendshipForm::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 110
Code Lines 51

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 51
dl 0
loc 110
rs 9.069
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 XoopsFormSelectUser;
30
use XoopsFormText;
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 FriendshipForm
44
 */
45
class FriendshipForm 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_FRIENDSHIP_ADD) : \sprintf(
64
            \AM_YOGURT_FRIENDSHIP_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
            'friendship_id', $this->targetObject->getVar(
75
            'friendship_id'
76
        )
77
        );
78
79
        $this->addElement($hidden);
80
81
        unset($hidden);
82
83
        // Friendship_id
84
85
        $this->addElement(
86
            new XoopsFormLabel(
87
                \AM_YOGURT_FRIENDSHIP_FRIENDSHIP_ID, $this->targetObject->getVar(
88
                'friendship_id'
89
            ), 'friendship_id'
90
            )
91
        );
92
93
        // Friend1_uid
94
95
        $this->addElement(
96
            new XoopsFormSelectUser(
97
                \AM_YOGURT_FRIENDSHIP_FRIEND1_UID, 'friend1_uid', false, $this->targetObject->getVar(
98
                'friend1_uid'
99
            ), 1, false
100
            ),
101
            false
102
        );
103
104
        // Friend2_uid
105
106
        $this->addElement(
107
            new XoopsFormSelectUser(
108
                \AM_YOGURT_FRIENDSHIP_FRIEND2_UID, 'friend2_uid', false, $this->targetObject->getVar(
109
                'friend2_uid'
110
            ), 1, false
111
            ),
112
            false
113
        );
114
115
        // Level
116
117
        $this->addElement(
118
            new XoopsFormText(\AM_YOGURT_FRIENDSHIP_LEVEL, 'level', 50, 255, $this->targetObject->getVar('level')),
119
            false
120
        );
121
122
        // Hot
123
124
        $this->addElement(
125
            new XoopsFormText(\AM_YOGURT_FRIENDSHIP_HOT, 'hot', 50, 255, $this->targetObject->getVar('hot')),
126
            false
127
        );
128
129
        // Trust
130
131
        $this->addElement(
132
            new XoopsFormText(\AM_YOGURT_FRIENDSHIP_TRUST, 'trust', 50, 255, $this->targetObject->getVar('trust')),
133
            false
134
        );
135
136
        // Cool
137
138
        $this->addElement(
139
            new XoopsFormText(\AM_YOGURT_FRIENDSHIP_COOL, 'cool', 50, 255, $this->targetObject->getVar('cool')),
140
            false
141
        );
142
143
        // Fan
144
145
        $this->addElement(
146
            new XoopsFormText(\AM_YOGURT_FRIENDSHIP_FAN, 'fan', 50, 255, $this->targetObject->getVar('fan')),
147
            false
148
        );
149
150
        // Data_creation
151
152
        $this->addElement(
153
            new \XoopsFormTextDateSelect(
154
                \AM_YOGURT_FRIENDSHIP_DATE_CREATED, 'date_created', 0, \formatTimestamp($this->targetObject->getVar('date_created'), 's')
0 ignored issues
show
Bug introduced by
formatTimestamp($this->t...r('date_created'), 's') of type string is incompatible with the type integer expected by parameter $value of XoopsFormTextDateSelect::__construct(). ( Ignorable by Annotation )

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

154
                \AM_YOGURT_FRIENDSHIP_DATE_CREATED, 'date_created', 0, /** @scrutinizer ignore-type */ \formatTimestamp($this->targetObject->getVar('date_created'), 's')
Loading history...
155
            )
156
        );
157
158
        $this->addElement(
159
            new \XoopsFormTextDateSelect(
160
                \AM_YOGURT_FRIENDSHIP_DATE_UPDATED, 'date_updated', 0, \formatTimestamp($this->targetObject->getVar('date_updated'), 's')
161
            )
162
        );
163
164
        $this->addElement(new XoopsFormHidden('op', 'save'));
165
166
        $this->addElement(new XoopsFormButton('', 'submit', \_SUBMIT, 'submit'));
167
    }
168
}
169