Test Setup Failed
Push — master ( 7fc67e...984264 )
by Lio
10:31 queued 17s
created

FriendshipForm::__construct()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 95
Code Lines 61

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 61
nc 2
nop 1
dl 0
loc 95
rs 8.8509
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 XoopsFormSelectUser;
27
use XoopsFormText;
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 FriendshipForm
39
 */
40
class FriendshipForm 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_FRIENDSHIP_ADD :
55
            \AM_SUICO_FRIENDSHIP_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
            'friendship_id',
61
            $this->targetObject->getVar(
62
                'friendship_id'
63
            )
64
        );
65
        $this->addElement($hidden);
66
        unset($hidden);
67
        // Friendship_id
68
        $this->addElement(
69
            new XoopsFormLabel(
70
                \AM_SUICO_FRIENDSHIP_FRIENDSHIP_ID,
71
                $this->targetObject->getVar(
72
                    'friendship_id'
73
                ),
74
                'friendship_id'
75
            )
76
        );
77
        // Friend1_uid
78
        $this->addElement(
79
            new XoopsFormSelectUser(
80
                \AM_SUICO_FRIENDSHIP_FRIEND1_UID,
81
                'friend1_uid',
82
                false,
83
                $this->targetObject->getVar('friend1_uid'),
84
                1,
85
                false
86
            ),
87
            false
88
        );
89
        // Friend2_uid
90
        $this->addElement(
91
            new XoopsFormSelectUser(
92
                \AM_SUICO_FRIENDSHIP_FRIEND2_UID,
93
                'friend2_uid',
94
                false,
95
                $this->targetObject->getVar('friend2_uid'),
96
                1,
97
                false
98
            ),
99
            false
100
        );
101
        // Level
102
        $this->addElement(
103
            new XoopsFormText(\AM_SUICO_FRIENDSHIP_LEVEL, 'level', 50, 255, $this->targetObject->getVar('level')),
104
            false
105
        );
106
        // Hot
107
        $this->addElement(
108
            new XoopsFormText(\AM_SUICO_FRIENDSHIP_HOT, 'hot', 50, 255, $this->targetObject->getVar('hot')),
109
            false
110
        );
111
        // Trust
112
        $this->addElement(
113
            new XoopsFormText(\AM_SUICO_FRIENDSHIP_TRUST, 'trust', 50, 255, $this->targetObject->getVar('trust')),
114
            false
115
        );
116
        // Cool
117
        $this->addElement(
118
            new XoopsFormText(\AM_SUICO_FRIENDSHIP_COOL, 'cool', 50, 255, $this->targetObject->getVar('cool')),
119
            false
120
        );
121
        // Fan
122
        $this->addElement(
123
            new XoopsFormText(\AM_SUICO_FRIENDSHIP_FAN, 'fan', 50, 255, $this->targetObject->getVar('fan')),
124
            false
125
        );
126
        // Data_creation
127
        $this->addElement(
128
            new \XoopsFormTextDateSelect(
129
                \AM_SUICO_FRIENDSHIP_DATE_CREATED,
130
                'date_created',
131
                0,
132
                \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

132
                /** @scrutinizer ignore-type */ \formatTimestamp($this->targetObject->getVar('date_created'), 's')
Loading history...
133
            )
134
        );
135
        $this->addElement(
136
            new \XoopsFormTextDateSelect(
137
                \AM_SUICO_FRIENDSHIP_DATE_UPDATED,
138
                'date_updated',
139
                0,
140
                \formatTimestamp($this->targetObject->getVar('date_updated'), 's')
141
            )
142
        );
143
        $this->addElement(new XoopsFormHidden('op', 'save'));
144
        $this->addElement(new XoopsFormButton('', 'submit', \_SUBMIT, 'submit'));
145
    }
146
}
147