ModuleFeedback::getFormFeedback()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 95
Code Lines 44

Duplication

Lines 0
Ratio 0 %

Importance

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