ModuleFeedback::getFormFeedback()   B
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 127
Code Lines 96

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
eloc 96
c 3
b 1
f 0
dl 0
loc 127
rs 8.0872
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 declare(strict_types=1);
2
3
namespace XoopsModules\Adslight\Common;
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
 * Feedback plugin for xoops modules
16
 *
17
 * @copyright      XOOPS Project  (https://xoops.org)
18
 * @license        GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
19
 * @author         Michael Beck <[email protected]>
20
 * @author         Wedega - Email:<[email protected]>
21
 * @author         Fernando Santos (topet05) <[email protected]>
22
 */
23
\defined('XOOPS_ROOT_PATH') || die('Restricted access');
24
25
/**
26
 * Class Object ModuleFeedback
27
 */
28
class ModuleFeedback extends \XoopsObject
29
{
30
    public $name    = '';
31
    public $email   = '';
32
    public $site    = '';
33
    public $type    = '';
34
    public $content = '';
35
36
    /**
37
     * Constructor
38
     *
39
     * @param null
40
     */
41
    public function __construct()
42
    {
43
    }
44
45
    /**
46
     * @static function &getInstance
47
     *
48
     * @param null
49
     */
50
    public static function getInstance(): void
51
    {
52
        static $instance = false;
53
        if (!$instance) {
54
            $instance = new self();
55
        }
56
    }
57
58
    /**
59
     * @public function getFormFeedback:
60
     * provide form for sending a feedback to module author
61
     * @param bool $action
62
     */
63
    public function getFormFeedback($action = false): \XoopsThemeForm
64
    {
65
        if (!$action) {
66
            $action = $_SERVER['REQUEST_URI'];
0 ignored issues
show
Unused Code introduced by
The assignment to $action is dead and can be removed.
Loading history...
67
        }
68
69
        $moduleDirName      = \basename(\dirname(__DIR__, 2));
70
        $moduleDirNameUpper = \mb_strtoupper($moduleDirName);
71
        // Get Theme Form
72
        \xoops_load('XoopsFormLoader');
73
        $form = new \XoopsThemeForm(
74
            \constant(
75
                'CO_' . $moduleDirNameUpper . '_' . 'FB_FORM_TITLE'
76
            ),
77
            'formfeedback',
78
            'feedback.php',
79
            'post',
80
            true
81
        );
82
        $form->setExtra('enctype="multipart/form-data"');
83
        $recipient = new \XoopsFormText(
84
            \constant(
85
                'CO_' . $moduleDirNameUpper . '_' . 'FB_RECIPIENT'
86
            ),
87
            'recipient',
88
            50,
89
            255,
90
            $GLOBALS['xoopsModule']->getInfo(
91
                'author_mail'
92
            )
93
        );
94
        $recipient->setExtra('disabled="disabled"');
95
        $form->addElement($recipient);
96
        $your_name = new \XoopsFormText(
97
            \constant(
98
                'CO_' . $moduleDirNameUpper . '_' . 'FB_NAME'
99
            ),
100
            'your_name',
101
            50,
102
            255,
103
            $this->name
104
        );
105
        $your_name->setExtra(
106
            'placeholder="' . \constant('CO_' . $moduleDirNameUpper . '_' . 'FB_NAME_PLACEHOLER') . '"'
107
        );
108
        $form->addElement($your_name);
109
        $your_site = new \XoopsFormText(
110
            \constant(
111
                'CO_' . $moduleDirNameUpper . '_' . 'FB_SITE'
112
            ),
113
            'your_site',
114
            50,
115
            255,
116
            $this->site
117
        );
118
        $your_site->setExtra(
119
            'placeholder="' . \constant('CO_' . $moduleDirNameUpper . '_' . 'FB_SITE_PLACEHOLER') . '"'
120
        );
121
        $form->addElement($your_site);
122
        $your_mail = new \XoopsFormText(
123
            \constant(
124
                'CO_' . $moduleDirNameUpper . '_' . 'FB_MAIL'
125
            ),
126
            'your_mail',
127
            50,
128
            255,
129
            $this->email
130
        );
131
        $your_mail->setExtra(
132
            'placeholder="' . \constant('CO_' . $moduleDirNameUpper . '_' . 'FB_MAIL_PLACEHOLER') . '"'
133
        );
134
        $form->addElement($your_mail);
135
        $fbtypeSelect = new \XoopsFormSelect(
136
            \constant(
137
                'CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE'
138
            ),
139
            'fb_type',
140
            $this->type
141
        );
142
        $fbtypeSelect->addOption('', '');
143
        $fbtypeSelect->addOption(
144
            \constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_SUGGESTION'),
145
            \constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_SUGGESTION')
146
        );
147
        $fbtypeSelect->addOption(
148
            \constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_BUGS'),
149
            \constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_BUGS')
150
        );
151
        $fbtypeSelect->addOption(
152
            \constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_TESTIMONIAL'),
153
            \constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_TESTIMONIAL')
154
        );
155
        $fbtypeSelect->addOption(
156
            \constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_FEATURES'),
157
            \constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_FEATURES')
158
        );
159
        $fbtypeSelect->addOption(
160
            \constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_OTHERS'),
161
            \constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_OTHERS')
162
        );
163
        $form->addElement($fbtypeSelect, true);
164
        $editorConfigs           = [];
165
        $editorConfigs['name']   = 'fb_content';
166
        $editorConfigs['value']  = $this->content;
167
        $editorConfigs['rows']   = 5;
168
        $editorConfigs['cols']   = 40;
169
        $editorConfigs['width']  = '100%';
170
        $editorConfigs['height'] = '400px';
171
        /** @var \XoopsModuleHandler $moduleHandler */
172
        $moduleHandler = \xoops_getHandler('module');
173
        $module        = $moduleHandler->getByDirname('system');
174
        /** @var \XoopsConfigHandler $configHandler */
175
        $configHandler           = \xoops_getHandler('config');
176
        $config                  = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
177
        $editorConfigs['editor'] = $config['general_editor'];
178
        $editor                  = new \XoopsFormEditor(
179
            \constant(
180
                'CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_CONTENT'
181
            ),
182
            'fb_content',
183
            $editorConfigs
184
        );
185
        $form->addElement($editor, true);
186
        $form->addElement(new \XoopsFormHidden('op', 'send'));
187
        $form->addElement(new \XoopsFormButtonTray('', \_SUBMIT, 'submit', '', false));
188
189
        return $form;
190
    }
191
}
192