FriendrequestForm::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 66
Code Lines 43

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 43
nc 2
nop 1
dl 0
loc 66
rs 9.232
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 XoopsModules\Suico;
28
use XoopsThemeForm;
29
30
require_once \dirname(__DIR__, 2) . '/include/common.php';
31
$moduleDirName = \basename(\dirname(__DIR__, 2));
32
//$helper = Suico\Helper::getInstance();
33
$permHelper = new Permission();
34
\xoops_load('XoopsFormLoader');
35
36
/**
37
 * Class FriendrequestForm
38
 */
39
class FriendrequestForm extends XoopsThemeForm
40
{
41
    public $targetObject;
42
    public $helper;
43
44
    /**
45
     * Constructor
46
     *
47
     * @param $target
48
     */
49
    public function __construct($target)
50
    {
51
        $this->helper       = $target->helper;
52
        $this->targetObject = $target;
53
        $title              = $this->targetObject->isNew() ? \AM_SUICO_FRIENDREQUEST_ADD :
54
            \AM_SUICO_FRIENDREQUEST_EDIT;
55
        parent::__construct($title, 'form', \xoops_getenv('SCRIPT_NAME'), 'post', true);
56
        $this->setExtra('enctype="multipart/form-data"');
57
        //include ID field, it's needed so the module knows if it is a new form or an edited form
58
        $hidden = new XoopsFormHidden(
59
            'friendreq_id',
60
            $this->targetObject->getVar(
61
                'friendreq_id'
62
            )
63
        );
64
        $this->addElement($hidden);
65
        unset($hidden);
66
        // Friendpet_id
67
        $this->addElement(
68
            new XoopsFormLabel(
69
                \AM_SUICO_FRIENDREQUEST_FRIENDPET_ID,
70
                $this->targetObject->getVar(
71
                    'friendreq_id'
72
                ),
73
                'friendreq_id'
74
            )
75
        );
76
        // Inviting by Friend_uid
77
        $this->addElement(
78
            new XoopsFormSelectUser(
79
                \AM_SUICO_FRIENDREQUEST_FRIENDREQUESTER_UID,
80
                'friendrequester_uid',
81
                false,
82
                $this->targetObject->getVar(
83
                    'friendrequester_uid'
84
                ),
85
                1,
86
                false
87
            ),
88
            false
89
        );
90
        // Invited Friend_uid
91
        $this->addElement(
92
            new XoopsFormSelectUser(
93
                \AM_SUICO_FRIENDREQUEST_FRIENDREQUESTTO_UID,
94
                'friendrequestto_uid',
95
                false,
96
                $this->targetObject->getVar(
97
                    'friendrequestto_uid'
98
                ),
99
                1,
100
                false
101
            ),
102
            false
103
        );
104
        // Date_created
105
        $this->addElement(
106
            new \XoopsFormTextDateSelect(
107
                \AM_SUICO_FRIENDREQUEST_DATE_CREATED,
108
                'date_created',
109
                0,
110
                \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

110
                /** @scrutinizer ignore-type */ \formatTimestamp($this->targetObject->getVar('date_created'), 's')
Loading history...
111
            )
112
        );
113
        $this->addElement(new XoopsFormHidden('op', 'save'));
114
        $this->addElement(new XoopsFormButton('', 'submit', \_SUBMIT, 'submit'));
115
    }
116
}
117