Completed
Push — master ( bf34f3...88111b )
by Michael
03:08
created

SmartObjectForm::getTextArea()   F

Complexity

Conditions 20
Paths 1632

Size

Total Lines 159
Code Lines 73

Duplication

Lines 4
Ratio 2.52 %

Importance

Changes 0
Metric Value
cc 20
eloc 73
nc 1632
nop 1
dl 4
loc 159
rs 2
c 0
b 0
f 0

How to fix   Long Method    Complexity   

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 namespace XoopsModules\Smartobject\Form;
2
3
/**
4
 * Contains the class responsible for providing forms related to a SmartObject
5
 *
6
 * @license    GNU
7
 * @author     marcan <[email protected]>
8
 * @link       http://smartfactory.ca The SmartFactory
9
 * @package    SmartObject
10
 * @subpackage SmartObjectForm
11
 */
12
13
// defined('XOOPS_ROOT_PATH') || die('Restricted access');
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
14
15
/**
16
 * Including the XoopsFormLoader classes
17
 */
18
use XoopsFormDhtmlTextArea;
19
use XoopsFormEditor;
20
use XoopsFormElement;
21
use XoopsFormTextArea;
22
use XoopsModules\Smartobject\Form\Elements\SmartFormCheckElement;
23
use XoopsModules\Smartobject\Form\Elements\SmartFormRichFileElement;
24
use XoopsModules\Smartobject\Form\Elements\SmartFormSection;
25
use XoopsModules\Smartobject\Form\Elements\SmartFormSectionClose;
26
use XoopsModules\Smartobject\Form\Elements\SmartFormUrlLinkElement;
27
28
require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
29
//require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformsection.php';
0 ignored issues
show
Unused Code Comprehensibility introduced by
36% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
30
//require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformsectionclose.php';
31
32
/**
33
 * SmartForm base class
34
 *
35
 * Base class representing a single form for a specific SmartObject
36
 *
37
 * @package SmartObject
38
 * @author  marcan <[email protected]>
39
 * @link    http://smartfactory.ca The SmartFactory
40
 */
41
class SmartObjectForm extends \XoopsThemeForm
42
{
43
    public $targetObject           = null;
44
    public $form_fields            = null;
45
    public $_cancel_js_action      = false;
46
    public $_custom_button         = false;
47
    public $_captcha               = false;
48
    public $_form_name             = false;
49
    public $_form_caption          = false;
50
    public $_submit_button_caption = false;
51
52
    /**
53
     * SmartobjectForm constructor.
54
     * @param string $target
55
     * @param string $form_name
56
     * @param string $form_caption
57
     * @param string $form_action
58
     * @param null   $form_fields
59
     * @param bool   $submit_button_caption
60
     * @param bool   $cancel_js_action
61
     * @param bool   $captcha
62
     */
63
    public function __construct(
64
        &$target,
65
        $form_name,
66
        $form_caption,
67
        $form_action,
68
        $form_fields = null,
69
        $submit_button_caption = false,
70
        $cancel_js_action = false,
71
        $captcha = false
72
    ) {
73
        $this->targetObject           =& $target;
74
        $this->form_fields            = $form_fields;
75
        $this->_cancel_js_action      = $cancel_js_action;
76
        $this->_captcha               = $captcha;
77
        $this->_form_name             = $form_name;
0 ignored issues
show
Documentation Bug introduced by
The property $_form_name was declared of type boolean, but $form_name is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
78
        $this->_form_caption          = $form_caption;
0 ignored issues
show
Documentation Bug introduced by
The property $_form_caption was declared of type boolean, but $form_caption is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
79
        $this->_submit_button_caption = $submit_button_caption;
80
81
        if (!isset($form_action)) {
82
            $form_action = xoops_getenv('PHP_SELF');
83
        }
84
85
        parent::__construct($form_caption, $form_name, $form_action, 'post', true);
86
        $this->setExtra('enctype="multipart/form-data"');
87
88
        $this->createElements();
89
90
        if ($captcha) {
91
            $this->addCaptcha();
92
        }
93
94
        $this->createPermissionControls();
95
96
        $this->createButtons($form_name, $form_caption, $submit_button_caption);
97
    }
98
99
    public function addCaptcha()
100
    {
101
        require_once SMARTOBJECT_ROOT_PATH . 'include/captcha/formcaptcha.php';
102
        $this->addElement(new \XoopsFormCaptcha(), true);
103
    }
104
105
    /**
106
     * @param      $name
107
     * @param      $caption
108
     * @param bool $onclick
109
     */
110
    public function addCustomButton($name, $caption, $onclick = false)
111
    {
112
        $custom_button_array    = [
113
            'name'    => $name,
114
            'caption' => $caption,
115
            'onclick' => $onclick
116
        ];
117
        $this->_custom_button[] = $custom_button_array;
118
    }
119
120
    /**
121
     * Add an element to the form
122
     *
123
     * @param string|XoopsFormElement &$formElement reference to a {@link XoopsFormElement}
124
     * @param bool                    $key
125
     * @param bool                    $var
126
     * @param bool|string             $required     is this a "required" element?
127
     */
128
    public function addElement($formElement, $key = false, $var = false, $required = 'notset')
129
    {
130
        if ($key) {
131
            if ($this->targetObject->vars[$key]['readonly']) {
132
                $formElement->setExtra('disabled="disabled"');
133
                $formElement->setName($key . '-readonly');
134
                // Since this element is disable, we still want to pass it's value in the form
135
                $hidden = new \XoopsFormHidden($key, $this->targetObject->vars[$key]['value']);
136
                $this->addElement($hidden);
137
            }
138
            $formElement->setDescription($var['form_dsc']);
139
            if (isset($this->targetObject->controls[$key]['onSelect'])) {
140
                $hidden = new \XoopsFormHidden('changedField', false);
141
                $this->addElement($hidden);
142
                $otherExtra      = isset($var['form_extra']) ? $var['form_extra'] : '';
143
                $onchangedString = "this.form.elements.changedField.value='$key'; this.form.elements.op.value='changedField'; submit()";
144
                $formElement->setExtra('onchange="' . $onchangedString . '"' . ' ' . $otherExtra);
145
            } else {
146
                if (isset($var['form_extra'])) {
147
                    $formElement->setExtra($var['form_extra']);
148
                }
149
            }
150
            $controls = $this->targetObject->controls;
151
            if (isset($controls[$key]['js'])) {
152
                $formElement->customValidationCode[] = $controls[$key]['js'];
153
            }
154
            parent::addElement($formElement, 'notset' === $required ? $var['required'] : $required);
155
        } else {
156
            parent::addElement($formElement, 'notset' === $required ? false : true);
157
        }
158
        unset($formElement);
159
    }
160
161
    public function createElements()
162
    {
163
        $controls = $this->targetObject->controls;
164
        $vars     = $this->targetObject->vars;
165
        foreach ($vars as $key => $var) {
166
167
            // If $displayOnForm is false OR this is the primary key, it doesn't
168
            // need to be displayed, then we only create an hidden field
169
            if ($key == $this->targetObject->handler->keyName || !$var['displayOnForm']) {
170
                $elementToAdd = new \XoopsFormHidden($key, $var['value']);
171
                $this->addElement($elementToAdd, $key, $var, false);
172
                unset($elementToAdd);
173
            // If not, the we need to create the proper form control for this fields
174
            } else {
175
                // If this field has a specific control, we will use it
176
177
                if ('parentid' === $key) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
178
                    /**
179
                     * Why this ?
180
                     */
181
                }
182
                if (isset($controls[$key])) {
183
                    /* If the control has name, it's because it's an object already present in the script
184
                     * for example, "user"
185
                     * If the field does not have a name, than we will use a "select" (ie XoopsFormSelect)
186
                     */
187
                    if (!isset($controls[$key]['name']) || !$controls[$key]['name']) {
188
                        $controls[$key]['name'] = 'select';
189
                    }
190
191
                    $form_select = $this->getControl($controls[$key]['name'], $key);
192
193
                    // Adding on the form, the control for this field
194
                    $this->addElement($form_select, $key, $var);
195
                    unset($form_select);
196
197
                // If this field don't have a specific control, we will use the standard one, depending on its data type
198
                } else {
199
                    switch ($var['data_type']) {
200
201
                        case XOBJ_DTYPE_TXTBOX:
202
203
                            $form_text = $this->getControl('text', $key);
204
                            $this->addElement($form_text, $key, $var);
205
                            unset($form_text);
206
                            break;
207
208 View Code Duplication
                        case XOBJ_DTYPE_INT:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
209
                            $this->targetObject->setControl($key, [
0 ignored issues
show
Bug introduced by
The method setControl cannot be called on $this->targetObject (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
210
                                'name' => 'text',
211
                                'size' => '5'
212
                            ]);
213
                            $form_text = $this->getControl('text', $key);
214
                            $this->addElement($form_text, $key, $var);
215
                            unset($form_text);
216
                            break;
217
218 View Code Duplication
                        case XOBJ_DTYPE_FLOAT:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
219
                            $this->targetObject->setControl($key, [
0 ignored issues
show
Bug introduced by
The method setControl cannot be called on $this->targetObject (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
220
                                'name' => 'text',
221
                                'size' => '5'
222
                            ]);
223
                            $form_text = $this->getControl('text', $key);
224
                            $this->addElement($form_text, $key, $var);
225
                            unset($form_text);
226
                            break;
227
228
                        case XOBJ_DTYPE_LTIME:
229
                            $form_date_time = $this->getControl('date_time', $key);
230
                            $this->addElement($form_date_time, $key, $var);
231
                            unset($form_date_time);
232
                            break;
233
234
                        case XOBJ_DTYPE_STIME:
235
                            $form_date_time = $this->getControl('date', $key);
236
                            $this->addElement($form_date_time, $key, $var);
237
                            unset($form_date_time);
238
                            break;
239
240
                        case XOBJ_DTYPE_TIME_ONLY:
241
                            $form_time = $this->getControl('time', $key);
242
                            $this->addElement($form_time, $key, $var);
243
                            unset($form_time);
244
                            break;
245
246 View Code Duplication
                        case XOBJ_DTYPE_CURRENCY:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
247
                            $this->targetObject->setControl($key, [
0 ignored issues
show
Bug introduced by
The method setControl cannot be called on $this->targetObject (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
248
                                'name' => 'text',
249
                                'size' => '15'
250
                            ]);
251
                            $form_currency = $this->getControl('text', $key);
252
                            $this->addElement($form_currency, $key, $var);
253
                            unset($form_currency);
254
                            break;
255
256
                        case XOBJ_DTYPE_URLLINK:
257
                            $form_urllink = $this->getControl('urllink', $key);
258
                            $this->addElement($form_urllink, $key, $var);
259
                            unset($form_urllink);
260
                            break;
261
262
                        case XOBJ_DTYPE_FILE:
263
                            $form_file = $this->getControl('richfile', $key);
264
                            $this->addElement($form_file, $key, $var);
265
                            unset($form_file);
266
                            break;
267
268
                        case XOBJ_DTYPE_TXTAREA:
269
270
                            $form_text_area = $this->getTextArea($key, $var);
271
                            $this->addElement($form_text_area, $key, $var);
272
                            unset($form_text_area);
273
                            break;
274
275
                        case XOBJ_DTYPE_ARRAY:
276
                            // TODO: To come...
277
                            break;
278
                        case XOBJ_DTYPE_SOURCE:
279
                            // TODO: To come...
280
                            break;
281
                        case XOBJ_DTYPE_FORM_SECTION:
282
                            $section_control = new SmartFormSection($key, $var['value']);
283
                            $this->addElement($section_control, $key, $var);
284
                            unset($section_control);
285
                            break;
286
                        case XOBJ_DTYPE_FORM_SECTION_CLOSE:
287
                            $section_control = new SmartFormSectionClose($key, $var['value']);
288
                            $this->addElement($section_control, $key, $var);
289
                            unset($section_control);
290
                            break;
291
                    }
292
                }
293
            }
294
        }
295
        // Add an hidden field to store the URL of the page before this form
296
        $this->addElement(new \XoopsFormHidden('smart_page_before_form', smart_get_page_before_form()));
297
    }
298
299
    public function createPermissionControls()
300
    {
301
        $smartModuleConfig = $this->targetObject->handler->getModuleConfig();
302
303
        $permissions = $this->targetObject->handler->getPermissions();
304
305
        if ($permissions) {
306
            $memberHandler = xoops_getHandler('member');
307
            $group_list    = $memberHandler->getGroupList();
308
            asort($group_list);
309
            foreach ($permissions as $permission) {
310
                if ($this->targetObject->isNew()) {
0 ignored issues
show
Bug introduced by
The method isNew cannot be called on $this->targetObject (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
311
                    if (isset($smartModuleConfig['def_perm_' . $permission['perm_name']])) {
312
                        $groups_value = $smartModuleConfig['def_perm_' . $permission['perm_name']];
313
                    }
314
                } else {
315
                    $groups_value = $this->targetObject->getGroupPerm($permission['perm_name']);
0 ignored issues
show
Bug introduced by
The method getGroupPerm cannot be called on $this->targetObject (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
316
                }
317
                $groups_select = new \XoopsFormSelect($permission['caption'], $permission['perm_name'], $groups_value, 4, true);
0 ignored issues
show
Bug introduced by
The variable $groups_value does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
318
                $groups_select->setDescription($permission['description']);
319
                $groups_select->addOptionArray($group_list);
320
                $this->addElement($groups_select);
321
                unset($groups_select);
322
            }
323
        }
324
    }
325
326
    /**
327
     * @param      $form_name
328
     * @param      $form_caption
329
     * @param bool $submit_button_caption
330
     */
331
    public function createButtons($form_name, $form_caption, $submit_button_caption = false)
332
    {
333
        $button_tray = new \XoopsFormElementTray('', '');
334
        $button_tray->addElement(new \XoopsFormHidden('op', $form_name));
335
        if (!$submit_button_caption) {
336
            if ($this->targetObject->isNew()) {
0 ignored issues
show
Bug introduced by
The method isNew cannot be called on $this->targetObject (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
337
                $butt_create = new \XoopsFormButton('', 'create_button', _CO_SOBJECT_CREATE, 'submit');
338
            } else {
339
                $butt_create = new \XoopsFormButton('', 'modify_button', _CO_SOBJECT_MODIFY, 'submit');
340
            }
341
        } else {
342
            $butt_create = new \XoopsFormButton('', 'modify_button', $submit_button_caption, 'submit');
343
        }
344
        $butt_create->setExtra('onclick="this.form.elements.op.value=\'' . $form_name . '\'"');
345
        $button_tray->addElement($butt_create);
346
347
        //creating custom buttons
348
        if ($this->_custom_button) {
349
            foreach ($this->_custom_button as $custom_button) {
0 ignored issues
show
Bug introduced by
The expression $this->_custom_button of type boolean is not traversable.
Loading history...
350
                $butt_custom = new \XoopsFormButton('', $custom_button['name'], $custom_button['caption'], 'submit');
351
                if ($custom_button['onclick']) {
352
                    $butt_custom->setExtra('onclick="' . $custom_button['onclick'] . '"');
353
                }
354
                $button_tray->addElement($butt_custom);
355
                unset($butt_custom);
356
            }
357
        }
358
359
        // creating the "cancel" button
360
        $butt_cancel = new \XoopsFormButton('', 'cancel_button', _CO_SOBJECT_CANCEL, 'button');
361
        if ($this->_cancel_js_action) {
362
            $butt_cancel->setExtra('onclick="' . $this->_cancel_js_action . '"');
363
        } else {
364
            $butt_cancel->setExtra('onclick="history.go(-1)"');
365
        }
366
        $button_tray->addElement($butt_cancel);
367
368
        $this->addElement($button_tray);
369
    }
370
371
    /**
372
     * @param $controlName
373
     * @param $key
374
     * @return \XoopsFormLabel
375
     */
376
    public function getControl($controlName, $key)
377
    {
378
        switch ($controlName) {
379 View Code Duplication
            case 'check':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
380
//                require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformcheckelement.php';
381
                $control    = $this->targetObject->getControl($key);
0 ignored issues
show
Bug introduced by
The method getControl cannot be called on $this->targetObject (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
382
                $controlObj = new SmartFormCheckElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key));
0 ignored issues
show
Bug introduced by
The method getVar cannot be called on $this->targetObject (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
383
                $controlObj->addOptionArray($control['options']);
384
385
                return $controlObj;
386
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
387
388
            case 'color':
389
                $control    = $this->targetObject->getControl($key);
0 ignored issues
show
Bug introduced by
The method getControl cannot be called on $this->targetObject (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
Unused Code introduced by
$control is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
390
                $controlObj = new \XoopsFormColorPicker($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key));
0 ignored issues
show
Bug introduced by
The method getVar cannot be called on $this->targetObject (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
391
392
                return $controlObj;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $controlObj; (XoopsFormColorPicker) is incompatible with the return type documented by XoopsModules\Smartobject...tObjectForm::getControl of type XoopsFormLabel|null.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
393
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
394
395 View Code Duplication
            case 'radio':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
396
                $control = $this->targetObject->getControl($key);
0 ignored issues
show
Bug introduced by
The method getControl cannot be called on $this->targetObject (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
397
398
                $controlObj = new \XoopsFormRadio($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key));
0 ignored issues
show
Bug introduced by
The method getVar cannot be called on $this->targetObject (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
399
                $controlObj->addOptionArray($control['options']);
400
401
                return $controlObj;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $controlObj; (XoopsFormRadio) is incompatible with the return type documented by XoopsModules\Smartobject...tObjectForm::getControl of type XoopsFormLabel|null.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
402
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
403
404
            case 'label':
405
                return new \XoopsFormLabel($this->targetObject->vars[$key]['form_caption'], $this->targetObject->getVar($key));
0 ignored issues
show
Bug introduced by
The method getVar cannot be called on $this->targetObject (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
406
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
407
408
            case 'textarea':
409
                return $this->getTextArea($key);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->getTextArea($key); (XoopsFormTinymce|XoopsFo...extArea|XoopsFormEditor) is incompatible with the return type documented by XoopsModules\Smartobject...tObjectForm::getControl of type XoopsFormLabel|null.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
410
411
            case 'theme':
412
                return $this->getThemeSelect($key, $this->targetObject->vars[$key]);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->getThemeSe...getObject->vars[$key]); (XoopsFormSelect) is incompatible with the return type documented by XoopsModules\Smartobject...tObjectForm::getControl of type XoopsFormLabel|null.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
413
414
            case 'theme_multi':
415
                return $this->getThemeSelect($key, $this->targetObject->vars[$key], true);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->getThemeSe...ect->vars[$key], true); (XoopsFormSelect) is incompatible with the return type documented by XoopsModules\Smartobject...tObjectForm::getControl of type XoopsFormLabel|null.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
416
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
417
418
            case 'timezone':
419
                return new \XoopsFormSelectTimezone($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key));
0 ignored issues
show
Bug introduced by
The method getVar cannot be called on $this->targetObject (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
Bug Best Practice introduced by
The return type of return new \XoopsFormSel...tObject->getVar($key)); (XoopsFormSelectTimezone) is incompatible with the return type documented by XoopsModules\Smartobject...tObjectForm::getControl of type XoopsFormLabel|null.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
420
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
421
422 View Code Duplication
            case 'group':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
423
                return new \XoopsFormSelectGroup($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 1, false);
0 ignored issues
show
Bug introduced by
The method getVar cannot be called on $this->targetObject (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
Bug Best Practice introduced by
The return type of return new \XoopsFormSel...($key, 'e'), 1, false); (XoopsFormSelectGroup) is incompatible with the return type documented by XoopsModules\Smartobject...tObjectForm::getControl of type XoopsFormLabel|null.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
424
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
425
426 View Code Duplication
            case 'group_multi':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
427
                return new \XoopsFormSelectGroup($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 5, true);
0 ignored issues
show
Bug introduced by
The method getVar cannot be called on $this->targetObject (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
Bug Best Practice introduced by
The return type of return new \XoopsFormSel...r($key, 'e'), 5, true); (XoopsFormSelectGroup) is incompatible with the return type documented by XoopsModules\Smartobject...tObjectForm::getControl of type XoopsFormLabel|null.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
428
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
429
430
            /*case 'user':
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
431
             return new \XoopsFormSelectUser($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 1, false);
432
             break;*/
433
434 View Code Duplication
            case 'user_multi':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
435
                return new \XoopsFormSelectUser($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 5, true);
0 ignored issues
show
Bug introduced by
The method getVar cannot be called on $this->targetObject (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
Bug Best Practice introduced by
The return type of return new \XoopsFormSel...r($key, 'e'), 5, true); (XoopsFormSelectUser) is incompatible with the return type documented by XoopsModules\Smartobject...tObjectForm::getControl of type XoopsFormLabel|null.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
436
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
437
438 View Code Duplication
            case 'password':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
439
                return new \XoopsFormPassword($this->targetObject->vars[$key]['form_caption'], $key, 50, 255, $this->targetObject->getVar($key, 'e'));
0 ignored issues
show
Bug introduced by
The method getVar cannot be called on $this->targetObject (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
Bug Best Practice introduced by
The return type of return new \XoopsFormPas...ct->getVar($key, 'e')); (XoopsFormPassword) is incompatible with the return type documented by XoopsModules\Smartobject...tObjectForm::getControl of type XoopsFormLabel|null.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
440
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
441
442
            case 'country':
443
                return new \XoopsFormSelectCountry($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key, 'e'));
0 ignored issues
show
Bug introduced by
The method getVar cannot be called on $this->targetObject (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
Bug Best Practice introduced by
The return type of return new \XoopsFormSel...ct->getVar($key, 'e')); (XoopsFormSelectCountry) is incompatible with the return type documented by XoopsModules\Smartobject...tObjectForm::getControl of type XoopsFormLabel|null.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
444
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
445
446
            case 'urllink':
447
//                require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformurllinkelement.php';
448
449
                return new SmartFormUrlLinkElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getUrlLinkObj($key));
0 ignored issues
show
Bug introduced by
The method getUrlLinkObj cannot be called on $this->targetObject (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
450
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
451
452
            case 'richfile':
453
//                require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformrichfileelement.php';
454
455
                return new SmartFormRichFileElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getFileObj($key));
0 ignored issues
show
Bug introduced by
The method getFileObj cannot be called on $this->targetObject (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
456
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
457
            case 'section':
458
//                require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformsection.php';
459
460
                return new SmartFormSection($key, $this->targetObject->vars[$key]['form_caption']);
461
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
462
463
            default:
464
                $classname = 'SmartForm' . ucfirst($controlName) . 'Element';
465
                if (!class_exists($classname)) {
466
                    if (file_exists(SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php')) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
467
//                        require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php';
468
                    } else {
469
                        // perhaps this is a control created by the module
470
                        $moduleName             = $this->targetObject->handler->_moduleName;
471
                        $moduleFormElementsPath = $this->targetObject->handler->_modulePath . 'class/form/elements/';
472
                        $classname              = ucfirst($moduleName) . ucfirst($controlName) . 'Element';
473
                        $classFileName          = strtolower($classname) . '.php';
474
475
                        if (file_exists($moduleFormElementsPath . $classFileName)) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
476
//                            require_once $moduleFormElementsPath . $classFileName;
0 ignored issues
show
Unused Code Comprehensibility introduced by
45% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
477
                        } else {
478
                            trigger_error($classname . ' Not found', E_USER_WARNING);
479
480
                            return new \XoopsFormLabel(); //Empty object
481
                        }
482
                    }
483
                }
484
485
                return new $classname($this->targetObject, $key);
486
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
487
        }
488
    }
489
490
    /**
491
     * @param $key
492
     * @return \XoopsFormDhtmlTextArea|\XoopsFormEditor|\XoopsFormTextArea|\XoopsFormTinymce|\XoopsFormTinymce4
493
     */
494
    public function getTextArea($key)
495
    {
496
        $var = $this->targetObject->vars[$key];
497
498
        // if no control has been created, let's create a default one
499
        if (!isset($this->targetObject->controls[$key])) {
500
            $control = [
501
                'name'        => 'textarea',
502
                'itemHandler' => false,
503
                'method'      => false,
504
                'module'      => false,
505
                'form_editor' => 'default'
506
            ];
507
        } else {
508
            $control = $this->targetObject->controls[$key];
509
        }
510
        $xoops22 = smart_isXoops22();
511
512
        $form_editor = isset($control['form_editor']) ? $control['form_editor'] : 'textarea';
513
        /**
514
         * If the editor is 'default', retreive the default editor of this module
515
         */
516 View Code Duplication
        if ('default' === $form_editor) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
517
            global $xoopsModuleConfig;
518
            $form_editor = isset($xoopsModuleConfig['default_editor']) ? $xoopsModuleConfig['default_editor'] : 'textarea';
519
        }
520
521
        $caption = $var['form_caption'];
522
        $name    = $key;
523
524
        $value = $this->targetObject->getVar($key);
0 ignored issues
show
Bug introduced by
The method getVar cannot be called on $this->targetObject (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
Unused Code introduced by
$value is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
525
526
        $value = $this->targetObject->getValueFor($key, true);
0 ignored issues
show
Bug introduced by
The method getValueFor cannot be called on $this->targetObject (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
527
528
        $editor_configs          = [];
529
        $editor_configs['name']  = $name;
530
        $editor_configs['value'] = $value;
531
        if ('textarea' !== $form_editor) {
532
            $editor_configs['rows'] = 35;
533
            $editor_configs['cols'] = 60;
534
        }
535
536
        if (isset($control['rows'])) {
537
            $editor_configs['rows'] = $control['rows'];
538
        }
539
        if (isset($control['cols'])) {
540
            $editor_configs['cols'] = $control['cols'];
541
        }
542
543
        $editor_configs['width']  = '100%';
544
        $editor_configs['height'] = '400px';
545
546
        $dhtml            = true;
547
        $xoopseditorclass = XOOPS_ROOT_PATH . '/class/xoopsform/formeditor.php';
548
549
        if (file_exists($xoopseditorclass)) {
550
            require_once $xoopseditorclass;
551
            $editor = new \XoopsFormEditor($caption, $form_editor, $editor_configs, $nohtml = false, $onfailure = 'textarea');
552
        } else {
553
            switch ($form_editor) {
554
555
                case 'tiny':
556
                    if (!$xoops22) {
557
                        if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php')) {
558
                            require_once XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php';
559
                            $editor = new \XoopsFormTinymce([
560
                                                                    'caption' => $caption,
561
                                                                    'name'    => $name,
562
                                                                    'value'   => $value,
563
                                                                    'width'   => '100%',
564
                                                                    'height'  => '300px'
565
                                                                ], true);
566
                        } else {
567
                            if ($dhtml) {
568
                                $editor = new \XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60);
569
                            } else {
570
                                $editor = new \XoopsFormTextArea($caption, $name, $value, 7, 60);
571
                            }
572
                        }
573
                    } else {
574
                        $editor = new \XoopsFormEditor($caption, 'tinyeditor', $editor_configs);
575
                    }
576
                    break;
577
578
                case 'dhtmltextarea':
579
                case 'dhtmltext':
580
                    $editor = new \XoopsFormDhtmlTextArea($var['form_caption'], $key, $this->targetObject->getVar($key, 'e'), 20, 60);
0 ignored issues
show
Bug introduced by
The method getVar cannot be called on $this->targetObject (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
581
                    if ($var['form_dsc']) {
582
                        $editor->setDescription($var['form_dsc']);
583
                    }
584
                    break;
585
586
//                case 'inbetween':
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
587
//                    if (!$xoops22) {
588
//                        if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/inbetween/forminbetweentextarea.php')) {
589
//                            require_once XOOPS_ROOT_PATH . '/class/xoopseditor/inbetween/forminbetweentextarea.php';
590
//                            $editor = new \XoopsFormInbetweenTextArea([
591
//                                                                         'caption' => $caption,
592
//                                                                         'name'    => $name,
593
//                                                                         'value'   => $value,
594
//                                                                         'width'   => '100%',
595
//                                                                         'height'  => '300px'
596
//                                                                     ], true);
597
//                        } else {
598
//                            if ($dhtml) {
599
//                                $editor = new \XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60);
600
//                            } else {
601
//                                $editor = new \XoopsFormTextArea($caption, $name, $value, 7, 60);
602
//                            }
603
//                        }
604
//                    } else {
605
//                        $editor = new \XoopsFormEditor($caption, 'inbetween', $editor_configs);
606
//                    }
607
//                    break;
608
609
//                case 'koivi':
0 ignored issues
show
Unused Code Comprehensibility introduced by
51% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
610
//                    if (!$xoops22) {
611
//                        if (is_readable(XOOPS_ROOT_PATH . '/class/wysiwyg/formwysiwygtextarea.php')) {
612
//                            require_once XOOPS_ROOT_PATH . '/class/wysiwyg/formwysiwygtextarea.php';
613
//                            $editor = new \XoopsFormWysiwygTextArea($caption, $name, $value, '100%', '400px');
614
//                        } else {
615
//                            if ($dhtml) {
616
//                                $editor = new \XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60);
617
//                            } else {
618
//                                $editor = new \XoopsFormTextArea($caption, $name, $value, 7, 60);
619
//                            }
620
//                        }
621
//                    } else {
622
//                        $editor = new \XoopsFormEditor($caption, 'koivi', $editor_configs);
623
//                    }
624
//                    break;
625
626
//                case 'htmlarea':
0 ignored issues
show
Unused Code Comprehensibility introduced by
48% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
627
//                    if (!$xoops22) {
628
//                        if (is_readable(XOOPS_ROOT_PATH . '/class/htmlarea/formhtmlarea.php')) {
629
//                            require_once XOOPS_ROOT_PATH . '/class/htmlarea/formhtmlarea.php';
630
//                            $editor = new \XoopsFormHtmlarea($caption, $name, $value);
631
//                        }
632
//                    } else {
633
//                        $editor = new \XoopsFormEditor($caption, 'htmlarea', $editor_configs);
634
//                    }
635
//                    break;
636
637
                default:
638
                case 'textarea':
0 ignored issues
show
Unused Code introduced by
case 'textarea': $fo...sc']); } break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
639
                    $form_rows = isset($control['rows']) ? $control['rows'] : 5;
640
                    $form_cols = isset($control['cols']) ? $control['cols'] : 60;
641
642
                    $editor = new \XoopsFormTextArea($var['form_caption'], $key, $this->targetObject->getVar($key, 'e'), $form_rows, $form_cols);
0 ignored issues
show
Bug introduced by
The method getVar cannot be called on $this->targetObject (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
643
                    if ($var['form_dsc']) {
644
                        $editor->setDescription($var['form_dsc']);
645
                    }
646
                    break;
647
648
            }
649
        }
650
651
        return $editor;
652
    }
653
654
    /**
655
     * @param                  $key
656
     * @param                  $var
657
     * @param  bool            $multiple
658
     * @return \XoopsFormSelect
659
     */
660
    public function getThemeSelect($key, $var, $multiple = false)
661
    {
662
        $size         = $multiple ? 5 : 1;
663
        $theme_select = new \XoopsFormSelect($var['form_caption'], $key, $this->targetObject->getVar($key), $size, $multiple);
0 ignored issues
show
Bug introduced by
The method getVar cannot be called on $this->targetObject (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
664
665
        $handle  = opendir(XOOPS_THEME_PATH . '/');
666
        $dirlist = [];
667
        while (false !== ($file = readdir($handle))) {
668
            if (is_dir(XOOPS_THEME_PATH . '/' . $file) && !preg_match('/^[.]{1,2}$/', $file)
669
                && 'cvs' !== strtolower($file)) {
670
                $dirlist[$file] = $file;
671
            }
672
        }
673
        closedir($handle);
674
        if (!empty($dirlist)) {
675
            asort($dirlist);
676
            $theme_select->addOptionArray($dirlist);
677
        }
678
679
        return $theme_select;
680
    }
681
682
    /**
683
     * @param $keyname
684
     * @return bool
685
     */
686
    public function &getElementById($keyname)
687
    {
688
        foreach ($this->_elements as $eleObj) {
689
            if ($eleObj->getName() == $keyname) {
690
                $ret =& $eleObj;
691
                break;
692
            }
693
        }
694
695
        return isset($ret) ? $ret : false;
696
    }
697
698
    /**
699
     * create HTML to output the form as a theme-enabled table with validation.
700
     *
701
     * @return string
702
     */
703
    public function render()
704
    {
705
        $required = $this->getRequired();
0 ignored issues
show
Unused Code introduced by
$required is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
706
        $ret      = "
707
            <form name='" . $this->getName() . "' id='" . $this->getName() . "' action='" . $this->getAction() . "' method='" . $this->getMethod() . "' onsubmit='return xoopsFormValidate_" . $this->getName() . "(this);'" . $this->getExtra() . ">
0 ignored issues
show
Bug introduced by
Consider using $this->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
708
            <table width='100%' class='outer' cellspacing='1'>
709
            <tr><th colspan='2'>" . $this->getTitle() . '</th></tr>
710
        ';
711
        $hidden   = '';
712
        $class    = 'even';
713
        foreach ($this->getElements() as $ele) {
714
            if (!is_object($ele)) {
715
                $ret .= $ele;
716
            } elseif (!$ele->isHidden()) {
717
                //$class = ( $class == 'even' ) ? 'odd': 'even';
0 ignored issues
show
Unused Code Comprehensibility introduced by
48% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
718
                $ret .= "<tr id='" . $ele->getName() . "' valign='top' align='left'><td class='head'>" . $ele->getCaption();
719
                if ('' !== $ele->getDescription()) {
720
                    $ret .= '<br><br><span style="font-weight: normal;">' . $ele->getDescription() . '</span>';
721
                }
722
                $ret .= "</td><td class='$class'>" . $ele->render() . "</td></tr>\n";
723
            } else {
724
                $hidden .= $ele->render();
725
            }
726
        }
727
        $ret .= "</table>\n$hidden\n</form>\n";
728
        $ret .= $this->renderValidationJS(true);
729
730
        return $ret;
731
    }
732
733
    /**
734
     * assign to smarty form template instead of displaying directly
735
     *
736
     * @param \XoopsTpl $tpl
737
     *
738
     * object
739
     * @param bool      $smartyName
740
     * @see     Smarty
741
     */
742
    public function assign(\XoopsTpl $tpl, $smartyName = false)
743
    {
744
        $i        = 0;
745
        $elements = [];
746
        foreach ($this->getElements() as $ele) {
747
            $n                             = ('' !== $ele->getName()) ? $ele->getName() : $i;
748
            $elements[$n]['name']          = $ele->getName();
749
            $elements[$n]['caption']       = $ele->getCaption();
750
            $elements[$n]['body']          = $ele->render();
751
            $elements[$n]['hidden']        = $ele->isHidden();
752
            $elements[$n]['section']       = strtolower(get_class($ele)) == strtolower('SmartFormSection');
753
            $elements[$n]['section_close'] = $ele instanceof \XoopsModules\Smartobject\Form\Elements\SmartFormSectionClose;
754
            $elements[$n]['hide']          = isset($this->targetObject->vars[$n]['hide']) ? $this->targetObject->vars[$n]['hide'] : false;
755
            if ('' !== $ele->getDescription()) {
756
                $elements[$n]['description'] = $ele->getDescription();
757
            }
758
            ++$i;
759
        }
760
        $js = $this->renderValidationJS();
761
        if (!$smartyName) {
762
            $smartyName = $this->getName();
0 ignored issues
show
Bug introduced by
Consider using $this->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
763
        }
764
765
        $tpl->assign($smartyName, [
766
            'title'      => $this->getTitle(),
767
            'name'       => $this->getName(),
0 ignored issues
show
Bug introduced by
Consider using $this->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
768
            'action'     => $this->getAction(),
769
            'method'     => $this->getMethod(),
770
            'extra'      => 'onsubmit="return xoopsFormValidate_' . $this->getName() . '(this);"' . $this->getExtra(),
0 ignored issues
show
Bug introduced by
Consider using $this->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
771
            'javascript' => $js,
772
            'elements'   => $elements
773
        ]);
774
    }
775
776
    /**
777
     * @param  bool $withtags
778
     * @return string
779
     */
780
    public function renderValidationJS($withtags = true)
781
    {
782
        $js = '';
783
        if ($withtags) {
784
            $js .= "\n<!-- Start Form Validation JavaScript //-->\n<script type='text/javascript'>\n<!--//\n";
785
        }
786
        $myts     = \MyTextSanitizer::getInstance();
0 ignored issues
show
Unused Code introduced by
$myts is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
787
        $formname = $this->getName();
0 ignored issues
show
Bug introduced by
Consider using $this->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
788
        $js       .= "function xoopsFormValidate_{$formname}(myform) {";
789
        // First, output code to check required elements
790
        $elements = $this->getRequired();
791
        foreach ($elements as $elt) {
792
            $eltname    = $elt->getName();
793
            $eltcaption = trim($elt->getCaption());
794
            $eltmsg     = empty($eltcaption) ? sprintf(_FORM_ENTER, $eltname) : sprintf(_FORM_ENTER, $eltcaption);
795
            $eltmsg     = str_replace('"', '\"', stripslashes($eltmsg));
796
            if ('xoopsformradio' === strtolower(get_class($elt))) {
797
                $js .= 'var myOption = -1;';
798
                $js .= "for (i=myform.{$eltname}.length-1; i > -1; i--) {
799
                    if (myform.{$eltname}[i].checked) {
800
                        myOption = i; i = -1;
801
                    }
802
                }
803
                if (myOption == -1) {
804
                    window.alert(\"{$eltmsg}\"); myform.{$eltname}[0].focus(); return false; }\n";
805
            } elseif ('smartformselect_multielement' === strtolower(get_class($elt))) {
806
                $js .= 'var hasSelections = false;';
807
                $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) {
808
                    if (myform['{$eltname}[]'].options[i].selected) {
809
                        hasSelections = true;
810
                    }
811
812
                }
813
                if (hasSelections === false) {
814
                    window.alert(\"{$eltmsg}\"); myform['{$eltname}[]'].options[0].focus(); return false; }\n";
815
            } elseif ('xoopsformcheckbox' === strtolower(get_class($elt))
816
                      || 'smartformcheckelement' === strtolower(get_class($elt))) {
817
                $js .= 'var hasSelections = false;';
818
                //sometimes, there is an implicit '[]', sometimes not
819 View Code Duplication
                if (false === strpos($eltname, '[')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
820
                    $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) {
821
                        if (myform['{$eltname}[]'][i].checked) {
822
                            hasSelections = true;
823
                        }
824
825
                    }
826
                    if (hasSelections === false) {
827
                        window.alert(\"{$eltmsg}\"); myform['{$eltname}[]'][0].focus(); return false; }\n";
828
                } else {
829
                    $js .= "for (var i = 0; i < myform['{$eltname}'].length; i++) {
830
                        if (myform['{$eltname}'][i].checked) {
831
                            hasSelections = true;
832
                        }
833
834
                    }
835
                    if (hasSelections === false) {
836
                        window.alert(\"{$eltmsg}\"); myform['{$eltname}'][0].focus(); return false; }\n";
837
                }
838
            } else {
839
                $js .= "if ( myform.{$eltname}.value == \"\" ) " . "{ window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }\n";
840
            }
841
        }
842
        // Now, handle custom validation code
843
        $elements =& $this->getElements(true);
844
        foreach ($elements as $elt) {
845
            if (method_exists($elt, 'renderValidationJS') && 'xoopsformcheckbox' !== strtolower(get_class($elt))) {
846
                if ($eltjs = $elt->renderValidationJS()) {
847
                    $js .= $eltjs . "\n";
848
                }
849
            }
850
        }
851
        $js .= "return true;\n}\n";
852
        if ($withtags) {
853
            $js .= "//--></script>\n<!-- 'End Form Validation JavaScript' //-->\n";
854
        }
855
856
        return $js;
857
    }
858
}
859