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

AudioForm::__construct()   B

Complexity

Conditions 4
Paths 6

Size

Total Lines 121
Code Lines 58

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 58
dl 0
loc 121
rs 8.9163
c 1
b 0
f 0
cc 4
nc 6
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 XoopsFormEditor;
28
use XoopsFormHidden;
29
use XoopsFormLabel;
30
use XoopsFormSelectUser;
31
use XoopsFormText;
32
use XoopsFormTextDateSelect;
33
use XoopsModules\Yogurt;
34
use XoopsThemeForm;
35
36
require_once \dirname(__DIR__, 2) . '/include/common.php';
37
38
$moduleDirName = \basename(\dirname(__DIR__, 2));
39
//$helper = Yogurt\Helper::getInstance();
40
$permHelper = new Permission();
41
42
\xoops_load('XoopsFormLoader');
43
44
/**
45
 * Class AudioForm
46
 */
47
class AudioForm extends XoopsThemeForm
48
{
49
    public $targetObject;
50
51
    public $helper;
52
53
    /**
54
     * Constructor
55
     *
56
     * @param $target
57
     */
58
59
    public function __construct($target)
60
    {
61
        $this->helper = $target->helper;
62
63
        $this->targetObject = $target;
64
65
        $title = $this->targetObject->isNew() ? \sprintf(\AM_YOGURT_AUDIO_ADD) : \sprintf(\AM_YOGURT_AUDIO_EDIT);
66
67
        parent::__construct($title, 'form', \xoops_getenv('SCRIPT_NAME'), 'post', true);
68
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
            'audio_id', $this->targetObject->getVar(
75
            'audio_id'
76
        )
77
        );
78
79
        $this->addElement($hidden);
80
81
        unset($hidden);
82
83
        // Audio_id
84
85
        $this->addElement(
86
            new XoopsFormLabel(\AM_YOGURT_AUDIO_AUDIO_ID, $this->targetObject->getVar('audio_id'), 'audio_id')
87
        );
88
89
        // Uid_owner
90
91
        $this->addElement(
92
            new XoopsFormSelectUser(
93
                \AM_YOGURT_AUDIO_UID_OWNER, 'uid_owner', false, $this->targetObject->getVar(
94
                'uid_owner'
95
            ), 1, false
96
            ),
97
            false
98
        );
99
100
        // Title
101
102
        $this->addElement(
103
            new XoopsFormText(\AM_YOGURT_AUDIO_TITLE, 'title', 50, 255, $this->targetObject->getVar('title')),
104
            false
105
        );
106
107
        // Author
108
109
        $this->addElement(
110
            new XoopsFormText(\AM_YOGURT_AUDIO_AUTHOR, 'author', 50, 255, $this->targetObject->getVar('author')),
111
            false
112
        );
113
114
        // Description
115
116
        if (\class_exists('XoopsFormEditor')) {
117
            $editorOptions = [];
118
119
            $editorOptions['name'] = 'description';
120
121
            $editorOptions['value'] = $this->targetObject->getVar('description', 'e');
122
123
            $editorOptions['rows'] = 5;
124
125
            $editorOptions['cols'] = 40;
126
127
            $editorOptions['width'] = '100%';
128
129
            $editorOptions['height'] = '400px';
130
131
            //$editorOptions['editor'] = xoops_getModuleOption('yogurt_editor', 'yogurt');
132
133
            //$this->addElement( new \XoopsFormEditor(AM_YOGURT_AUDIO_DESCRIPTION, 'description', $editorOptions), false  );
134
135
            if ($this->helper->isUserAdmin()) {
136
                $descEditor = new XoopsFormEditor(
137
                    \AM_YOGURT_AUDIO_DESCRIPTION, $this->helper->getConfig(
138
                    'yogurtEditorAdmin'
139
                ), $editorOptions, $nohtml = false, $onfailure = 'textarea'
140
                );
141
            } else {
142
                $descEditor = new XoopsFormEditor(
143
                    \AM_YOGURT_AUDIO_DESCRIPTION, $this->helper->getConfig(
144
                    'yogurtEditorUser'
145
                ), $editorOptions, $nohtml = false, $onfailure = 'textarea'
146
                );
147
            }
148
        } else {
149
            $descEditor = new \XoopsFormDhtmlTextArea(
150
                \AM_YOGURT_AUDIO_DESCRIPTION, 'description', $this->targetObject->getVar(
151
                'description',
152
                'e'
153
            ), 5, 50
154
            );
155
        }
156
157
        $this->addElement($descEditor);
158
159
        // Url
160
161
        $this->addElement(new \XoopsFormFile(\AM_YOGURT_AUDIO_URL, 'filename', $this->helper->getConfig('maxsize')), false);
162
163
        // Data_creation
164
165
        $this->addElement(
166
            new XoopsFormTextDateSelect(
167
                \AM_YOGURT_AUDIO_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

167
                \AM_YOGURT_AUDIO_DATE_CREATED, 'date_created', 0, /** @scrutinizer ignore-type */ \formatTimestamp($this->targetObject->getVar('date_created'), 's')
Loading history...
168
            )
169
        );
170
171
        $this->addElement(
172
            new XoopsFormTextDateSelect(
173
                \AM_YOGURT_AUDIO_DATE_UPDATED, 'date_updated', 0, \formatTimestamp($this->targetObject->getVar('date_updated'), 's')
174
            )
175
        );
176
177
        $this->addElement(new XoopsFormHidden('op', 'save'));
178
179
        $this->addElement(new XoopsFormButton('', 'submit', \_SUBMIT, 'submit'));
180
    }
181
}
182