Passed
Pull Request — master (#187)
by Michael
16:36
created

VideoForm::__construct()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 98
Code Lines 65

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 65
nc 2
nop 1
dl 0
loc 98
rs 8.7636
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 XoopsFormTextArea;
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 VideoForm
40
 */
41
class VideoForm 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_VIDEO_ADD : \AM_SUICO_VIDEO_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
            'video_id',
61
            $this->targetObject->getVar(
62
                'video_id'
63
            )
64
        );
65
        $this->addElement($hidden);
66
        unset($hidden);
67
        // Video_id
68
        $this->addElement(
69
            new XoopsFormLabel(\AM_SUICO_VIDEO_VIDEO_ID, $this->targetObject->getVar('video_id'), 'video_id')
70
        );
71
        // Uid_owner
72
        $this->addElement(
73
            new XoopsFormSelectUser(
74
                \AM_SUICO_VIDEO_UID_OWNER,
75
                'uid_owner',
76
                false,
77
                $this->targetObject->getVar(
78
                    'uid_owner'
79
                ),
80
                1,
81
                false
82
            ),
83
            false
84
        );
85
        // Video Title
86
        $this->addElement(
87
            new XoopsFormText(
88
                \AM_SUICO_VIDEO_TITLE,
89
                'video_title',
90
                50,
91
                255,
92
                $this->targetObject->getVar(
93
                    'video_title'
94
                )
95
            ),
96
            false
97
        );
98
        // Video_desc
99
        $this->addElement(
100
            new XoopsFormTextArea(
101
                \AM_SUICO_VIDEO_VIDEO_DESC,
102
                'video_desc',
103
                $this->targetObject->getVar(
104
                    'video_desc'
105
                ),
106
                4,
107
                47
108
            ),
109
            false
110
        );
111
        // Youtube_code
112
        $this->addElement(
113
            new XoopsFormText(
114
                \AM_SUICO_VIDEO_YOUTUBE_CODE,
115
                'youtube_code',
116
                50,
117
                255,
118
                $this->targetObject->getVar(
119
                    'youtube_code'
120
                )
121
            ),
122
            false
123
        );
124
        // Main_video
125
        $this->addElement(
126
            new XoopsFormText(
127
                \AM_SUICO_VIDEO_MAIN_VIDEO,
128
                'featured_video',
129
                50,
130
                255,
131
                $this->targetObject->getVar(
132
                    'featured_video'
133
                )
134
            ),
135
            false
136
        );
137
        // Data_creation
138
        $this->addElement(new \XoopsFormTextDateSelect(\AM_SUICO_VIDEO_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

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