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

VideoForm::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 75
Code Lines 42

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 42
c 1
b 0
f 0
dl 0
loc 75
rs 9.248
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 XoopsFormTextArea;
36
use XoopsModules\Yogurt;
37
use XoopsThemeForm;
38
39
require_once \dirname(__DIR__, 2) . '/include/common.php';
40
41
$moduleDirName = \basename(\dirname(__DIR__, 2));
42
//$helper = Yogurt\Helper::getInstance();
43
$permHelper = new Permission();
44
45
\xoops_load('XoopsFormLoader');
46
47
/**
48
 * Class VideoForm
49
 */
50
class VideoForm extends XoopsThemeForm
51
{
52
    public $targetObject;
53
54
    public $helper;
55
56
    /**
57
     * Constructor
58
     *
59
     * @param $target
60
     */
61
    public function __construct($target)
62
    {
63
        $this->helper       = $target->helper;
64
        $this->targetObject = $target;
65
66
        $title = $this->targetObject->isNew() ? \sprintf(\AM_YOGURT_VIDEO_ADD) : \sprintf(\AM_YOGURT_VIDEO_EDIT);
67
        parent::__construct($title, 'form', \xoops_getenv('SCRIPT_NAME'), 'post', true);
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
            'video_id', $this->targetObject->getVar(
74
            'video_id'
75
        )
76
        );
77
        $this->addElement($hidden);
78
        unset($hidden);
79
80
        // Video_id
81
        $this->addElement(
82
            new XoopsFormLabel(\AM_YOGURT_VIDEO_VIDEO_ID, $this->targetObject->getVar('video_id'), 'video_id')
83
        );
84
        // Uid_owner
85
        $this->addElement(
86
            new XoopsFormSelectUser(
87
                \AM_YOGURT_VIDEO_UID_OWNER, 'uid_owner', false, $this->targetObject->getVar(
88
                'uid_owner'
89
            ), 1, false
90
            ),
91
            false
92
        );
93
        // Video_desc
94
        $this->addElement(
95
            new XoopsFormTextArea(
96
                \AM_YOGURT_VIDEO_VIDEO_DESC, 'video_desc', $this->targetObject->getVar(
97
                'video_desc'
98
            ), 4, 47
99
            ),
100
            false
101
        );
102
        // Youtube_code
103
        $this->addElement(
104
            new XoopsFormText(
105
                \AM_YOGURT_VIDEO_YOUTUBE_CODE, 'youtube_code', 50, 255, $this->targetObject->getVar(
106
                'youtube_code'
107
            )
108
            ),
109
            false
110
        );
111
        // Main_video
112
        $this->addElement(
113
            new XoopsFormText(
114
                \AM_YOGURT_VIDEO_MAIN_VIDEO, 'main_video', 50, 255, $this->targetObject->getVar(
115
                'main_video'
116
            )
117
            ),
118
            false
119
        );
120
121
        // Data_creation
122
        $this->addElement(
123
            new \XoopsFormTextDateSelect(
124
                \AM_YOGURT_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

124
                \AM_YOGURT_VIDEO_DATE_CREATED, 'date_created', 0, /** @scrutinizer ignore-type */ formatTimestamp($this->targetObject->getVar('date_created'), 's')
Loading history...
125
            )
126
        );
127
128
        $this->addElement(
129
            new \XoopsFormTextDateSelect(
130
                \AM_YOGURT_VIDEO_DATE_UPDATED, 'date_updated', 0, formatTimestamp($this->targetObject->getVar('date_updated'), 's')
131
            )
132
        );
133
134
        $this->addElement(new XoopsFormHidden('op', 'save'));
135
        $this->addElement(new XoopsFormButton('', 'submit', \_SUBMIT, 'submit'));
136
    }
137
}
138