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

AudioForm::__construct()   B

Complexity

Conditions 4
Paths 6

Size

Total Lines 108
Code Lines 67

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 67
c 1
b 0
f 0
dl 0
loc 108
rs 8.72
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
 * 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 XoopsFormDateTime;
32
use XoopsFormEditor;
33
use XoopsFormHidden;
34
use XoopsFormLabel;
35
use XoopsFormSelectUser;
36
use XoopsFormText;
37
use XoopsFormTextDateSelect;
38
use XoopsModules\Yogurt;
39
use XoopsThemeForm;
40
41
require_once \dirname(__DIR__, 2) . '/include/common.php';
42
43
$moduleDirName = \basename(\dirname(__DIR__, 2));
44
//$helper = Yogurt\Helper::getInstance();
45
$permHelper = new Permission();
46
47
\xoops_load('XoopsFormLoader');
48
49
/**
50
 * Class AudioForm
51
 */
52
class AudioForm extends XoopsThemeForm
53
{
54
    public $targetObject;
55
56
    public $helper;
57
58
    /**
59
     * Constructor
60
     *
61
     * @param $target
62
     */
63
    public function __construct($target)
64
    {
65
        $this->helper       = $target->helper;
66
        $this->targetObject = $target;
67
68
        $title = $this->targetObject->isNew() ? \sprintf(\AM_YOGURT_AUDIO_ADD) : \sprintf(\AM_YOGURT_AUDIO_EDIT);
69
        parent::__construct($title, 'form', \xoops_getenv('SCRIPT_NAME'), 'post', true);
70
        $this->setExtra('enctype="multipart/form-data"');
71
72
        //include ID field, it's needed so the module knows if it is a new form or an edited form
73
74
        $hidden = new XoopsFormHidden(
75
            'audio_id',
76
            $this->targetObject->getVar(
77
            'audio_id'
78
        )
79
        );
80
        $this->addElement($hidden);
81
        unset($hidden);
82
83
        // Audio_id
84
        $this->addElement(
85
            new XoopsFormLabel(\AM_YOGURT_AUDIO_AUDIO_ID, $this->targetObject->getVar('audio_id'), 'audio_id')
86
        );
87
88
        // Uid_owner
89
        $this->addElement(
90
            new XoopsFormSelectUser(
91
                \AM_YOGURT_AUDIO_UID_OWNER, 'uid_owner', false, $this->targetObject->getVar(
92
                'uid_owner'
93
            ), 1, false
94
            ),
95
            false
96
        );
97
        // Title
98
        $this->addElement(
99
            new XoopsFormText(\AM_YOGURT_AUDIO_TITLE, 'title', 50, 255, $this->targetObject->getVar('title')),
100
            false
101
        );
102
        // Author
103
        $this->addElement(
104
            new XoopsFormText(\AM_YOGURT_AUDIO_AUTHOR, 'author', 50, 255, $this->targetObject->getVar('author')),
105
            false
106
        );
107
108
        // Description
109
        if (\class_exists('XoopsFormEditor')) {
110
            $editorOptions           = [];
111
            $editorOptions['name']   = 'description';
112
            $editorOptions['value']  = $this->targetObject->getVar('description', 'e');
113
            $editorOptions['rows']   = 5;
114
            $editorOptions['cols']   = 40;
115
            $editorOptions['width']  = '100%';
116
            $editorOptions['height'] = '400px';
117
            //$editorOptions['editor'] = xoops_getModuleOption('yogurt_editor', 'yogurt');
118
            //$this->addElement( new \XoopsFormEditor(AM_YOGURT_AUDIO_DESCRIPTION, 'description', $editorOptions), false  );
119
            if ($this->helper->isUserAdmin()) {
120
                $descEditor = new XoopsFormEditor(
121
                    \AM_YOGURT_AUDIO_DESCRIPTION,
122
                    $this->helper->getConfig(
123
                        'yogurtEditorAdmin'
124
                    ),
125
                    $editorOptions,
126
                    $nohtml = false,
127
                    $onfailure = 'textarea'
128
                );
129
            } else {
130
                $descEditor = new XoopsFormEditor(
131
                    \AM_YOGURT_AUDIO_DESCRIPTION,
132
                    $this->helper->getConfig(
133
                        'yogurtEditorUser'
134
                    ),
135
                    $editorOptions,
136
                    $nohtml = false,
137
                    $onfailure = 'textarea'
138
                );
139
            }
140
        } else {
141
            $descEditor = new XoopsFormDhtmlTextArea(
0 ignored issues
show
Bug introduced by
The type XoopsModules\Yogurt\Form\XoopsFormDhtmlTextArea was not found. Did you mean XoopsFormDhtmlTextArea? If so, make sure to prefix the type with \.
Loading history...
142
                \AM_YOGURT_AUDIO_DESCRIPTION,
143
                'description',
144
                $this->targetObject->getVar(
145
                    'description',
146
                    'e'
147
                ),
148
                5,
149
                50
150
            );
151
        }
152
        $this->addElement($descEditor);
153
        // Url
154
        $this->addElement(new \XoopsFormFile(\AM_YOGURT_AUDIO_URL, 'filename', $this->helper->getConfig('maxsize')), false);
155
156
        // Data_creation
157
        $this->addElement(
158
            new XoopsFormTextDateSelect(
159
                \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

159
                \AM_YOGURT_AUDIO_DATE_CREATED, 'date_created', 0, /** @scrutinizer ignore-type */ formatTimestamp($this->targetObject->getVar('date_created'), 's')
Loading history...
160
            )
161
        );
162
163
        $this->addElement(
164
            new XoopsFormTextDateSelect(
165
                \AM_YOGURT_AUDIO_DATE_UPDATED, 'date_updated', 0, formatTimestamp($this->targetObject->getVar('date_updated'), 's')
166
            )
167
        );
168
169
        $this->addElement(new XoopsFormHidden('op', 'save'));
170
        $this->addElement(new XoopsFormButton('', 'submit', \_SUBMIT, 'submit'));
171
    }
172
}
173