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

VisitorsForm::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 74
Code Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 34
dl 0
loc 74
rs 9.376
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 XoopsFormTextDateSelect;
32
use XoopsModules\Yogurt;
33
use XoopsThemeForm;
34
35
require_once \dirname(__DIR__, 2) . '/include/common.php';
36
37
$moduleDirName = \basename(\dirname(__DIR__, 2));
38
//$helper = Yogurt\Helper::getInstance();
39
$permHelper = new Permission();
40
41
\xoops_load('XoopsFormLoader');
42
43
/**
44
 * Class VisitorsForm
45
 */
46
class VisitorsForm extends XoopsThemeForm
47
{
48
    public $targetObject;
49
50
    public $helper;
51
52
    /**
53
     * Constructor
54
     *
55
     * @param $target
56
     */
57
58
    public function __construct($target)
59
    {
60
        $this->helper = $target->helper;
61
62
        $this->targetObject = $target;
63
64
        $title = $this->targetObject->isNew() ? \sprintf(\AM_YOGURT_VISITORS_ADD) : \sprintf(\AM_YOGURT_VISITORS_EDIT);
65
66
        parent::__construct($title, 'form', \xoops_getenv('SCRIPT_NAME'), 'post', true);
67
68
        $this->setExtra('enctype="multipart/form-data"');
69
70
        //include ID field, it's needed so the module knows if it is a new form or an edited form
71
72
        $hidden = new XoopsFormHidden(
73
            'cod_visit', $this->targetObject->getVar(
74
            'cod_visit'
75
        )
76
        );
77
78
        $this->addElement($hidden);
79
80
        unset($hidden);
81
82
        // Cod_visit
83
84
        $this->addElement(
85
            new XoopsFormLabel(\AM_YOGURT_VISITORS_COD_VISIT, $this->targetObject->getVar('cod_visit'), 'cod_visit')
86
        );
87
88
        // Uid_owner
89
90
        $this->addElement(
91
            new XoopsFormSelectUser(
92
                \AM_YOGURT_VISITORS_UID_OWNER, 'uid_owner', false, $this->targetObject->getVar(
93
                'uid_owner'
94
            ), 1, false
95
            ),
96
            false
97
        );
98
99
        // Uid_visitor
100
101
        $this->addElement(
102
            new XoopsFormSelectUser(
103
                \AM_YOGURT_VISITORS_UID_VISITOR, 'uid_visitor', false, $this->targetObject->getVar(
104
                'uid_visitor'
105
            ), 1, false
106
            ),
107
            false
108
        );
109
110
        // Uname_visitor
111
112
        $this->addElement(
113
            new XoopsFormText(
114
                \AM_YOGURT_VISITORS_UNAME_VISITOR, 'uname_visitor', 50, 255, $this->targetObject->getVar(
115
                'uname_visitor'
116
            )
117
            ),
118
            false
119
        );
120
121
        // Datetime
122
123
        $this->addElement(
124
            new XoopsFormTextDateSelect(
125
                \AM_YOGURT_VISITORS_DATETIME, 'date_visited', 0, \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

125
                \AM_YOGURT_VISITORS_DATETIME, 'date_visited', 0, /** @scrutinizer ignore-type */ \formatTimestamp($this->targetObject->getVar('date_visited'), 's')
Loading history...
126
            )
127
        );
128
129
        $this->addElement(new XoopsFormHidden('op', 'save'));
130
131
        $this->addElement(new XoopsFormButton('', 'submit', \_SUBMIT, 'submit'));
132
    }
133
}
134