VisitorsForm::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 72
Code Lines 47

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 47
nc 2
nop 1
dl 0
loc 72
rs 9.1563
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 XoopsFormTextDateSelect;
29
use XoopsModules\Suico;
30
use XoopsThemeForm;
31
32
require_once \dirname(__DIR__, 2) . '/include/common.php';
33
$moduleDirName = \basename(\dirname(__DIR__, 2));
34
//$helper = Suico\Helper::getInstance();
35
$permHelper = new Permission();
36
\xoops_load('XoopsFormLoader');
37
38
/**
39
 * Class VisitorsForm
40
 */
41
class VisitorsForm extends XoopsThemeForm
42
{
43
    public $targetObject;
44
    public $helper;
45
46
    /**
47
     * Constructor
48
     *
49
     * @param $target
50
     */
51
    public function __construct($target)
52
    {
53
        $this->helper       = $target->helper;
54
        $this->targetObject = $target;
55
        $title              = $this->targetObject->isNew() ? \AM_SUICO_VISITORS_ADD : \AM_SUICO_VISITORS_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
            'visit_id',
61
            $this->targetObject->getVar(
62
                'visit_id'
63
            )
64
        );
65
        $this->addElement($hidden);
66
        unset($hidden);
67
        // Cod_visit
68
        $this->addElement(
69
            new XoopsFormLabel(\AM_SUICO_VISITORS_VISIT_ID, $this->targetObject->getVar('visit_id'), 'visit_id')
70
        );
71
        // Uid_owner
72
        $this->addElement(
73
            new XoopsFormSelectUser(
74
                \AM_SUICO_VISITORS_UID_OWNER,
75
                'uid_owner',
76
                false,
77
                $this->targetObject->getVar(
78
                    'uid_owner'
79
                ),
80
                1,
81
                false
82
            ),
83
            false
84
        );
85
        // Uid_visitor
86
        $this->addElement(
87
            new XoopsFormSelectUser(
88
                \AM_SUICO_VISITORS_UID_VISITOR,
89
                'uid_visitor',
90
                false,
91
                $this->targetObject->getVar(
92
                    'uid_visitor'
93
                ),
94
                1,
95
                false
96
            ),
97
            false
98
        );
99
        // Uname_visitor
100
        $this->addElement(
101
            new XoopsFormText(
102
                \AM_SUICO_VISITORS_UNAME_VISITOR,
103
                'uname_visitor',
104
                50,
105
                255,
106
                $this->targetObject->getVar(
107
                    'uname_visitor'
108
                )
109
            ),
110
            false
111
        );
112
        // Datetime
113
        $this->addElement(
114
            new XoopsFormTextDateSelect(
115
                \AM_SUICO_VISITORS_DATETIME,
116
                'date_visited',
117
                0,
118
                \formatTimestamp($this->targetObject->getVar('date_visited'), 's')
0 ignored issues
show
Bug introduced by
formatTimestamp($this->t...r('date_visited'), '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

118
                /** @scrutinizer ignore-type */ \formatTimestamp($this->targetObject->getVar('date_visited'), 's')
Loading history...
119
            )
120
        );
121
        $this->addElement(new XoopsFormHidden('op', 'save'));
122
        $this->addElement(new XoopsFormButton('', 'submit', \_SUBMIT, 'submit'));
123
    }
124
}
125