NotesForm::__construct()   B
last analyzed

Complexity

Conditions 6
Paths 24

Size

Total Lines 82
Code Lines 58

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 58
nc 24
nop 1
dl 0
loc 82
rs 8.2941
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 declare(strict_types=1);
2
3
namespace XoopsModules\Suico\Form;
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
 * @category        Module
17
 * @copyright       {@link https://xoops.org/ XOOPS Project}
18
 * @license         GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
19
 * @author          Marcello Brandão aka  Suico, Mamba, LioMJ  <https://xoops.org>
20
 */
21
22
use Xmf\Module\Helper\Permission;
23
use XoopsFormButton;
24
use XoopsFormCheckBox;
25
use XoopsFormDhtmlTextArea;
26
use XoopsFormEditor;
27
use XoopsFormHidden;
28
use XoopsFormLabel;
29
use XoopsFormSelectUser;
30
use XoopsFormTextDateSelect;
31
use XoopsModules\Suico;
32
use XoopsThemeForm;
33
34
require_once \dirname(__DIR__, 2) . '/include/common.php';
35
$moduleDirName = \basename(\dirname(__DIR__, 2));
36
//$helper = Suico\Helper::getInstance();
37
$permHelper = new Permission();
38
\xoops_load('XoopsFormLoader');
39
40
/**
41
 * Class NotesForm
42
 */
43
class NotesForm extends XoopsThemeForm
44
{
45
    public $targetObject;
46
    public $helper;
47
48
    /**
49
     * Constructor
50
     *
51
     * @param $target
52
     */
53
    public function __construct($target)
54
    {
55
        $this->helper       = $target->helper;
56
        $this->targetObject = $target;
57
        $title              = $this->targetObject->isNew() ? \AM_SUICO_NOTES_ADD : \AM_SUICO_NOTES_EDIT;
58
        parent::__construct($title, 'form', \xoops_getenv('SCRIPT_NAME'), 'post', true);
59
        $this->setExtra('enctype="multipart/form-data"');
60
        //include ID field, it's needed so the module knows if it is a new form or an edited form
61
        $hidden = new XoopsFormHidden(
62
            'note_id',
63
            $this->targetObject->getVar(
64
                'note_id'
65
            )
66
        );
67
        $this->addElement($hidden);
68
        unset($hidden);
69
        // Note_id
70
        $this->addElement(
71
            new XoopsFormLabel(\AM_SUICO_NOTES_NOTE_ID, $this->targetObject->getVar('note_id'), 'note_id')
72
        );
73
        // Note_text
74
        if (\class_exists('XoopsFormEditor')) {
75
            $editorOptions           = [];
76
            $editorOptions['name']   = 'note_text';
77
            $editorOptions['value']  = $this->targetObject->getVar('note_text', 'e');
78
            $editorOptions['rows']   = 5;
79
            $editorOptions['cols']   = 40;
80
            $editorOptions['width']  = '100%';
81
            $editorOptions['height'] = '400px';
82
            //$editorOptions['editor'] = xoops_getModuleOption('suico_editor', 'suico');
83
            //$this->addElement( new \XoopsFormEditor(AM_SUICO_NOTES_NOTE_TEXT, 'note_text', $editorOptions), false  );
84
            if ($this->helper->isUserAdmin()) {
85
                $descEditor = new XoopsFormEditor(
86
                    \AM_SUICO_NOTES_NOTE_TEXT, $this->helper->getConfig(
87
                        'suicoEditorAdmin'
88
                ), $editorOptions, $nohtml = false, $onfailure = 'textarea'
89
                );
90
            } else {
91
                $descEditor = new XoopsFormEditor(
92
                    \AM_SUICO_NOTES_NOTE_TEXT, $this->helper->getConfig(
93
                        'suicoEditorUser'
94
                ), $editorOptions, $nohtml = false, $onfailure = 'textarea'
95
                );
96
            }
97
        } else {
98
            $descEditor = new XoopsFormDhtmlTextArea(
99
                \AM_SUICO_NOTES_NOTE_TEXT, 'description', $this->targetObject->getVar(
100
                    'description',
101
                    'e'
102
            ), 5, 50
103
            );
104
        }
105
        $this->addElement($descEditor);
106
        // Note_from
107
        $this->addElement(
108
            new XoopsFormSelectUser(
109
                \AM_SUICO_NOTES_NOTE_FROM, 'note_from', false, $this->targetObject->getVar(
110
                    'note_from'
111
            ), 1, false
112
            ),
113
            false
114
        );
115
        // Note_to
116
        $this->addElement(
117
            new XoopsFormSelectUser(
118
                \AM_SUICO_NOTES_NOTE_TO, 'note_to', false, $this->targetObject->getVar(
119
                    'note_to'
120
            ), 1, false
121
            ),
122
            false
123
        );
124
        // Private
125
        $private       = $this->targetObject->isNew() ? 0 : $this->targetObject->getVar('private');
126
        $check_private = new XoopsFormCheckBox(\AM_SUICO_NOTES_PRIVATE, 'private', $private);
127
        $check_private->addOption(1, ' ');
128
        $this->addElement($check_private);
129
        // Date
130
        //        $this->addElement(new XoopsFormTextDateSelect(AM_SUICO_NOTES_DATE, 'date',0, \strtotime($this->targetObject->getVar('date'))));
131
        $noteCreated = $this->targetObject->isNew() ? 0 : $this->targetObject->getVar('date_created');
132
        $this->addElement(new \XoopsFormTextDateSelect(\AM_SUICO_NOTES_DATE, 'date_created', '', $noteCreated), true);
0 ignored issues
show
Bug introduced by
'' of type string is incompatible with the type integer expected by parameter $size 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

132
        $this->addElement(new \XoopsFormTextDateSelect(\AM_SUICO_NOTES_DATE, 'date_created', /** @scrutinizer ignore-type */ '', $noteCreated), true);
Loading history...
133
        $this->addElement(new XoopsFormHidden('op', 'save'));
134
        $this->addElement(new XoopsFormButton('', 'submit', \_SUBMIT, 'submit'));
135
    }
136
}
137