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

FriendshipForm::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 88
Code Lines 51

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 51
c 1
b 0
f 0
dl 0
loc 88
rs 9.069
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
 * Module: Yogurt
19
 *
20
 * @category        Module
21
 * @package         yogurt
22
 * @author          XOOPS Development Team <https://xoops.org>
23
 * @copyright       {@link https://xoops.org/ XOOPS Project}
24
 * @license         GPL 2.0 or later
25
 * @link            https://xoops.org/
26
 * @since           1.0.0
27
 */
28
29
use Xmf\Module\Helper\Permission;
30
use XoopsFormButton;
31
use XoopsFormHidden;
32
use XoopsFormLabel;
33
use XoopsFormSelectUser;
34
use XoopsFormText;
35
use XoopsModules\Yogurt;
36
use XoopsThemeForm;
37
38
require_once \dirname(__DIR__, 2) . '/include/common.php';
39
40
$moduleDirName = \basename(\dirname(__DIR__, 2));
41
//$helper = Yogurt\Helper::getInstance();
42
$permHelper = new Permission();
43
44
\xoops_load('XoopsFormLoader');
45
46
/**
47
 * Class FriendshipForm
48
 */
49
class FriendshipForm extends XoopsThemeForm
50
{
51
    public $targetObject;
52
53
    public $helper;
54
55
    /**
56
     * Constructor
57
     *
58
     * @param $target
59
     */
60
    public function __construct($target)
61
    {
62
        $this->helper       = $target->helper;
63
        $this->targetObject = $target;
64
65
        $title = $this->targetObject->isNew() ? \sprintf(\AM_YOGURT_FRIENDSHIP_ADD) : \sprintf(
66
            \AM_YOGURT_FRIENDSHIP_EDIT
67
        );
68
        parent::__construct($title, 'form', \xoops_getenv('SCRIPT_NAME'), 'post', true);
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
        $this->addElement($hidden);
79
        unset($hidden);
80
81
        // Friendship_id
82
        $this->addElement(
83
            new XoopsFormLabel(
84
                \AM_YOGURT_FRIENDSHIP_FRIENDSHIP_ID, $this->targetObject->getVar(
85
                'friendship_id'
86
            ), 'friendship_id'
87
            )
88
        );
89
        // Friend1_uid
90
        $this->addElement(
91
            new XoopsFormSelectUser(
92
                \AM_YOGURT_FRIENDSHIP_FRIEND1_UID, 'friend1_uid', false, $this->targetObject->getVar(
93
                'friend1_uid'
94
            ), 1, false
95
            ),
96
            false
97
        );
98
        // Friend2_uid
99
        $this->addElement(
100
            new XoopsFormSelectUser(
101
                \AM_YOGURT_FRIENDSHIP_FRIEND2_UID, 'friend2_uid', false, $this->targetObject->getVar(
102
                'friend2_uid'
103
            ), 1, false
104
            ),
105
            false
106
        );
107
        // Level
108
        $this->addElement(
109
            new XoopsFormText(\AM_YOGURT_FRIENDSHIP_LEVEL, 'level', 50, 255, $this->targetObject->getVar('level')),
110
            false
111
        );
112
        // Hot
113
        $this->addElement(
114
            new XoopsFormText(\AM_YOGURT_FRIENDSHIP_HOT, 'hot', 50, 255, $this->targetObject->getVar('hot')),
115
            false
116
        );
117
        // Trust
118
        $this->addElement(
119
            new XoopsFormText(\AM_YOGURT_FRIENDSHIP_TRUST, 'trust', 50, 255, $this->targetObject->getVar('trust')),
120
            false
121
        );
122
        // Cool
123
        $this->addElement(
124
            new XoopsFormText(\AM_YOGURT_FRIENDSHIP_COOL, 'cool', 50, 255, $this->targetObject->getVar('cool')),
125
            false
126
        );
127
        // Fan
128
        $this->addElement(
129
            new XoopsFormText(\AM_YOGURT_FRIENDSHIP_FAN, 'fan', 50, 255, $this->targetObject->getVar('fan')),
130
            false
131
        );
132
133
        // Data_creation
134
        $this->addElement(
135
            new \XoopsFormTextDateSelect(
136
                \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

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