Passed
Push — master ( 40654a...b847d6 )
by Michael
06:43 queued 10s
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
cc 2
eloc 44
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 55
rs 9.216

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
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 30 and the first side effect is on line 25.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
namespace XoopsModules\Pedigree\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
25
defined('XOOPS_ROOT_PATH') || die('Restricted access');
26
27
/**
28
 * Class Object ModuleFeedback
29
 */
30
class ModuleFeedback extends \XoopsObject
31
{
32
    public $name    = '';
33
    public $email   = '';
34
    public $site    = '';
35
    public $type    = '';
36
    public $content = '';
37
38
    /**
39
     * Constructor
40
     *
41
     * @param null
42
     */
43
    public function __construct()
44
    {
45
    }
46
47
    /**
48
     * @static function &getInstance
49
     *
50
     * @param null
51
     */
52
    public static function getInstance()
53
    {
54
        static $instance = false;
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
        $moduleDirName      = basename(dirname(dirname(__DIR__)));
72
        $moduleDirNameUpper = mb_strtoupper($moduleDirName);
73
        // Get Theme Form
74
        xoops_load('XoopsFormLoader');
75
        $form = new \XoopsThemeForm(constant('CO_' . $moduleDirNameUpper . '_' . 'FB_FORM_TITLE'), 'formfeedback', 'feedback.php', 'post', true);
76
        $form->setExtra('enctype="multipart/form-data"');
77
78
        $recipient = new \XoopsFormText(constant('CO_' . $moduleDirNameUpper . '_' . 'FB_RECIPIENT'), 'recipient', 50, 255, $GLOBALS['xoopsModule']->getInfo('author_mail'));
79
        $recipient->setExtra('disabled="disabled"');
80
        $form->addElement($recipient);
81
        $your_name = new \XoopsFormText(constant('CO_' . $moduleDirNameUpper . '_' . 'FB_NAME'), 'your_name', 50, 255, $this->name);
82
        $your_name->setExtra('placeholder="' . constant('CO_' . $moduleDirNameUpper . '_' . 'FB_NAME_PLACEHOLER') . '"');
83
        $form->addElement($your_name);
84
        $your_site = new \XoopsFormText(constant('CO_' . $moduleDirNameUpper . '_' . 'FB_SITE'), 'your_site', 50, 255, $this->site);
85
        $your_site->setExtra('placeholder="' . constant('CO_' . $moduleDirNameUpper . '_' . 'FB_SITE_PLACEHOLER') . '"');
86
        $form->addElement($your_site);
87
        $your_mail = new \XoopsFormText(constant('CO_' . $moduleDirNameUpper . '_' . 'FB_MAIL'), 'your_mail', 50, 255, $this->email);
88
        $your_mail->setExtra('placeholder="' . constant('CO_' . $moduleDirNameUpper . '_' . 'FB_MAIL_PLACEHOLER') . '"');
89
        $form->addElement($your_mail);
90
91
        $fbtypeSelect = new \XoopsFormSelect(constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE'), 'fb_type', $this->type);
92
        $fbtypeSelect->addOption('', '');
93
        $fbtypeSelect->addOption(constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_SUGGESTION'), constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_SUGGESTION'));
94
        $fbtypeSelect->addOption(constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_BUGS'), constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_BUGS'));
95
        $fbtypeSelect->addOption(constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_TESTIMONIAL'), constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_TESTIMONIAL'));
96
        $fbtypeSelect->addOption(constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_FEATURES'), constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_FEATURES'));
97
        $fbtypeSelect->addOption(constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_OTHERS'), constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_OTHERS'));
98
        $form->addElement($fbtypeSelect, true);
99
100
        $editorConfigs           = [];
101
        $editorConfigs['name']   = 'fb_content';
102
        $editorConfigs['value']  = $this->content;
103
        $editorConfigs['rows']   = 5;
104
        $editorConfigs['cols']   = 40;
105
        $editorConfigs['width']  = '100%';
106
        $editorConfigs['height'] = '400px';
107
        /** @var \XoopsModuleHandler $moduleHandler */
108
        $moduleHandler           = xoops_getHandler('module');
109
        $module                  = $moduleHandler->getByDirname('system');
110
        /** @var \XoopsConfigHandler $configHandler */
111
        $configHandler           = xoops_getHandler('config');
112
        $config                  = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
113
        $editorConfigs['editor'] = $config['general_editor'];
114
        $editor                  = new \XoopsFormEditor(constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_CONTENT'), 'fb_content', $editorConfigs);
115
        $form->addElement($editor, true);
116
117
        $form->addElement(new \XoopsFormHidden('op', 'send'));
118
        $form->addElement(new \XoopsFormButtonTray('', _SUBMIT, 'submit', '', false));
119
120
        return $form;
121
    }
122
}
123