Passed
Push — master ( 410bf5...5bae2d )
by Michael
04:30 queued 02:13
created

ModuleFeedback::getFormFeedback()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 55
Code Lines 44

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 44
c 1
b 0
f 0
dl 0
loc 55
rs 9.216
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
namespace XoopsModules\Groupmanager\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 Object 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
        if (!$instance) {
55
            $instance = new self();
56
        }
57
    }
58
59
    /**
60
     * @public function getFormFeedback:
61
     * provide form for sending a feedback to module author
62
     * @param bool $action
63
     * @return \XoopsThemeForm
64
     */
65
    public function getFormFeedback($action = false)
66
    {
67
        if (false === $action) {
68
            $action = $_SERVER['REQUEST_URI'];
0 ignored issues
show
Unused Code introduced by
The assignment to $action is dead and can be removed.
Loading history...
69
        }
70
        $moduleDirName      = basename(dirname(dirname(__DIR__)));
71
        $moduleDirNameUpper = mb_strtoupper($moduleDirName);
72
        // Get Theme Form
73
        xoops_load('XoopsFormLoader');
74
        $form = new \XoopsThemeForm(constant('CO_' . $moduleDirNameUpper . '_' . 'FB_FORM_TITLE'), 'formfeedback', 'feedback.php', 'post', true);
75
        $form->setExtra('enctype="multipart/form-data"');
76
77
        $recipient = new \XoopsFormText(constant('CO_' . $moduleDirNameUpper . '_' . 'FB_RECIPIENT'), 'recipient', 50, 255, $GLOBALS['xoopsModule']->getInfo('author_mail'));
78
        $recipient->setExtra('disabled="disabled"');
79
        $form->addElement($recipient);
80
        $your_name = new \XoopsFormText(constant('CO_' . $moduleDirNameUpper . '_' . 'FB_NAME'), 'your_name', 50, 255, $this->name);
81
        $your_name->setExtra('placeholder="' . constant('CO_' . $moduleDirNameUpper . '_' . 'FB_NAME_PLACEHOLER') . '"');
82
        $form->addElement($your_name);
83
        $your_site = new \XoopsFormText(constant('CO_' . $moduleDirNameUpper . '_' . 'FB_SITE'), 'your_site', 50, 255, $this->site);
84
        $your_site->setExtra('placeholder="' . constant('CO_' . $moduleDirNameUpper . '_' . 'FB_SITE_PLACEHOLER') . '"');
85
        $form->addElement($your_site);
86
        $your_mail = new \XoopsFormText(constant('CO_' . $moduleDirNameUpper . '_' . 'FB_MAIL'), 'your_mail', 50, 255, $this->email);
87
        $your_mail->setExtra('placeholder="' . constant('CO_' . $moduleDirNameUpper . '_' . 'FB_MAIL_PLACEHOLER') . '"');
88
        $form->addElement($your_mail);
89
90
        $fbtypeSelect = new \XoopsFormSelect(constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE'), 'fb_type', $this->type);
91
        $fbtypeSelect->addOption('', '');
92
        $fbtypeSelect->addOption(constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_SUGGESTION'), constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_SUGGESTION'));
93
        $fbtypeSelect->addOption(constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_BUGS'), constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_BUGS'));
94
        $fbtypeSelect->addOption(constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_TESTIMONIAL'), constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_TESTIMONIAL'));
95
        $fbtypeSelect->addOption(constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_FEATURES'), constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_FEATURES'));
96
        $fbtypeSelect->addOption(constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_OTHERS'), constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_OTHERS'));
97
        $form->addElement($fbtypeSelect, true);
98
99
        $editorConfigs           = [];
100
        $editorConfigs['name']   = 'fb_content';
101
        $editorConfigs['value']  = $this->content;
102
        $editorConfigs['rows']   = 5;
103
        $editorConfigs['cols']   = 40;
104
        $editorConfigs['width']  = '100%';
105
        $editorConfigs['height'] = '400px';
106
        /** @var \XoopsModuleHandler $moduleHandler */
107
        $moduleHandler = xoops_getHandler('module');
108
        $module        = $moduleHandler->getByDirname('system');
109
        /** @var \XoopsConfigHandler $configHandler */
110
        $configHandler           = xoops_getHandler('config');
111
        $config                  = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
112
        $editorConfigs['editor'] = $config['general_editor'];
113
        $editor                  = new \XoopsFormEditor(constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_CONTENT'), 'fb_content', $editorConfigs);
114
        $form->addElement($editor, true);
115
116
        $form->addElement(new \XoopsFormHidden('op', 'send'));
117
        $form->addElement(new \XoopsFormButtonTray('', _SUBMIT, 'submit', '', false));
118
119
        return $form;
120
    }
121
}
122