Test Failed
Pull Request — master (#13)
by
unknown
05:47
created

XoopsForm::assign()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 33
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 27
nc 4
nop 1
dl 0
loc 33
rs 9.1768
c 0
b 0
f 0
1
<?php
2
/**
3
 * XOOPS Form Class
4
 *
5
 * You may not change or alter any portion of this comment or credits
6
 * of supporting developers from this source code or any supporting source code
7
 * which is considered copyrighted (c) material of the original comment or credit authors.
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * @copyright       (c) 2000-2016 XOOPS Project (www.xoops.org)
13
 * @license             GNU GPL 2 (https://www.gnu.org/licenses/gpl-2.0.html)
14
 * @package             kernel
15
 * @subpackage          form
16
 * @since               2.0.0
17
 * @author              Kazumi Ono (AKA onokazu) http://www.myweb.ne.jp/, http://jp.xoops.org/
18
 * @author              Taiwen Jiang <[email protected]>
19
 */
20
defined('XOOPS_ROOT_PATH') || exit('Restricted access');
21
22
/**
23
 * Abstract base class for forms
24
 *
25
 * @author         Kazumi Ono <[email protected]>
26
 * @author         Taiwen Jiang <[email protected]>
27
 * @package        kernel
28
 * @subpackage     form
29
 * @access         public
30
 */
31
class XoopsForm
32
{
33
    /**
34
     * *#@+
35
     *
36
     * @access private
37
     */
38
    /**
39
     * "action" attribute for the html form
40
     *
41
     * @var string
42
     */
43
    public $_action;
44
45
    /**
46
     * "method" attribute for the form.
47
     *
48
     * @var string
49
     */
50
    public $_method;
51
52
    /**
53
     * "name" attribute of the form
54
     *
55
     * @var string
56
     */
57
    public $_name;
58
59
    /**
60
     * title for the form
61
     *
62
     * @var string
63
     */
64
    public $_title;
65
66
    /**
67
     * summary for the form (WGAC2 Requirement)
68
     *
69
     * @var string
70
     */
71
    public $_summary = '';
72
73
    /**
74
     * array of {@link XoopsFormElement} objects
75
     *
76
     * @var array
77
     */
78
    public $_elements = array();
79
80
    /**
81
     * HTML classes for the <form> tag
82
     *
83
     * @var array
84
     */
85
    public $_class = array();
86
    
87
    /**
88
     * extra information for the <form> tag
89
     *
90
     * @var array
91
     */
92
    public $_extra = array();
93
94
    /**
95
     * required elements
96
     *
97
     * @var array
98
     */
99
    public $_required = array();
100
101
    /**
102
     * additional serialised object checksum (ERM Analysis - Requirement)
103
     * @deprecated
104
     * @access private
105
     */
106
    public $_objid = 'da39a3ee5e6b4b0d3255bfef95601890afd80709';
107
108
    /**
109
     * *#@-
110
     */
111
112
    /**
113
     * constructor
114
     *
115
     * @param string $title    title of the form
116
     * @param string $name     "name" attribute for the <form> tag
117
     * @param string $action   "action" attribute for the <form> tag
118
     * @param string $method   "method" attribute for the <form> tag
119
     * @param bool   $addtoken whether to add a security token to the form
120
     * @param string $summary
121
     */
122
    public function __construct($title, $name, $action, $method = 'post', $addtoken = false, $summary = '')
123
    {
124
        $this->_title   = $title;
125
        $this->_name    = $name;
126
        $this->_action  = $action;
127
        $this->_method  = $method;
128
        $this->_summary = $summary;
129
        if ($addtoken != false) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison !== instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
130
            $this->addElement(new XoopsFormHiddenToken());
131
        }
132
    }
133
    /**
134
     * PHP 4 style constructor compatibility shim
135
     * @deprecated all callers should be using parent::__construct()
136
     */
137
    public function XoopsForm()
138
    {
139
        $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1);
140
        trigger_error("Should call parent::__construct in {$trace[0]['file']} line {$trace[0]['line']},");
141
        self::__construct();
0 ignored issues
show
Bug Best Practice introduced by
The method XoopsForm::__construct() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

141
        self::/** @scrutinizer ignore-call */ 
142
              __construct();
Loading history...
Bug introduced by
The call to XoopsForm::__construct() has too few arguments starting with title. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

141
        self::/** @scrutinizer ignore-call */ 
142
              __construct();

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
142
    }
143
    /**
144
     * *#@+
145
     * retrieves object serialisation/identification id (sha1 used)
146
     *
147
     * each object has serialisation<br>
148
     * - legal requirement of enterprise relational management (ERM)
149
     *
150
     * @deprecated
151
     * @access public
152
     * @param         $object
153
     * @param  string $hashinfo
154
     * @return string
155
     */
156
    public function getObjectID($object, $hashinfo = 'sha1')
157
    {
158
        if (!is_object($object)) {
159
            $object = $this;
160
        }
161
162
        switch ($hashinfo) {
163
            case 'md5':
164
165
                @$var['name'] = md5(get_class($object));
166
167
                foreach (get_object_vars($object) as $key => $value) {
168
                    if ($key !== '_objid') {
169
                        @$var['value'] = $this->getArrayID($value, $key, $var['value'], $hashinfo);
170
                    }
171
                }
172
173
                foreach (get_class_methods($object) as $key => $value) {
174
                    @$var['func'] = $this->getArrayID($value, $key, $var['func'], $hashinfo);
175
                }
176
177
                @$this->_objid = md5($var['name'] . ':' . $var['func'] . ':' . $var['value']);
0 ignored issues
show
Deprecated Code introduced by
The property XoopsForm::$_objid has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

177
                @/** @scrutinizer ignore-deprecated */ $this->_objid = md5($var['name'] . ':' . $var['func'] . ':' . $var['value']);
Loading history...
178
179
                return $this->_objid;
0 ignored issues
show
Deprecated Code introduced by
The property XoopsForm::$_objid has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

179
                return /** @scrutinizer ignore-deprecated */ $this->_objid;
Loading history...
180
                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...
181
182
            default:
183
184
                @$var['name'] = sha1(get_class($object));
185
186
                foreach (get_object_vars($object) as $key => $value) {
187
                    if ($key !== '_objid') {
188
                        @$var['value'] = $this->getArrayID($value, $key, $var['value'], $hashinfo);
189
                    }
190
                }
191
192
                foreach (get_class_methods($object) as $key => $value) {
193
                    @$var['func'] = $this->getArrayID($value, $key, $var['func'], $hashinfo);
194
                }
195
196
                @$this->_objid = sha1($var['name'] . ':' . $var['func'] . ':' . $var['value']);
0 ignored issues
show
Deprecated Code introduced by
The property XoopsForm::$_objid has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

196
                @/** @scrutinizer ignore-deprecated */ $this->_objid = sha1($var['name'] . ':' . $var['func'] . ':' . $var['value']);
Loading history...
197
198
                return $this->_objid;
0 ignored issues
show
Deprecated Code introduced by
The property XoopsForm::$_objid has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

198
                return /** @scrutinizer ignore-deprecated */ $this->_objid;
Loading history...
199
200
        }
201
    }
202
203
    /**
204
     * @param        $value
205
     * @param        $key
206
     * @param        $ret
207
     * @param string $hashinfo
208
     *
209
     * @return string
210
     */
211
    public function getArrayID($value, $key, $ret, $hashinfo = 'sha1')
212
    {
213
        switch ($hashinfo) {
214
            case 'md5':
215
                if (is_array($value)) {
216
                    foreach ($value as $keyb => $valueb) {
217
                        @$ret = md5($ret . ':' . $this->getArrayID($valueb, $keyb, $ret, $hashinfo));
218
                    }
219
                } else {
220
                    @$ret = md5($ret . ':' . $key . ':' . $value);
221
                }
222
223
                return $ret;
224
                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...
225
            default:
226
                if (is_array($value)) {
227
                    foreach ($value as $keyb => $valueb) {
228
                        @$ret = sha1($ret . ':' . $this->getArrayID($valueb, $keyb, $ret, $hashinfo));
229
                    }
230
                } else {
231
                    @$ret = sha1($ret . ':' . $key . ':' . $value);
232
                }
233
234
                return $ret;
235
                break;
236
        }
237
    }
238
239
    /**
240
     * return the summary of the form
241
     *
242
     * @param  bool $encode To sanitizer the text?
243
     * @return string
244
     */
245
    public function getSummary($encode = false)
246
    {
247
        return $encode ? htmlspecialchars($this->_summary, ENT_QUOTES) : $this->_summary;
248
    }
249
250
    /**
251
     * return the title of the form
252
     *
253
     * @param  bool $encode To sanitizer the text?
254
     * @return string
255
     */
256
    public function getTitle($encode = false)
257
    {
258
        return $encode ? htmlspecialchars($this->_title, ENT_QUOTES) : $this->_title;
259
    }
260
261
    /**
262
     * get the "name" attribute for the <form> tag
263
     *
264
     * Deprecated, to be refactored
265
     *
266
     * @param  bool $encode To sanitizer the text?
267
     * @return string
268
     */
269
    public function getName($encode = true)
270
    {
271
        return $encode ? htmlspecialchars($this->_name, ENT_QUOTES) : $this->_name;
272
    }
273
274
    /**
275
     * get the "action" attribute for the <form> tag
276
     *
277
     * @param  bool $encode To sanitizer the text?
278
     * @return string
279
     */
280
    public function getAction($encode = true)
281
    {
282
        // Convert &amp; to & for backward compatibility
283
        return $encode ? htmlspecialchars(str_replace('&amp;', '&', $this->_action), ENT_QUOTES) : $this->_action;
284
    }
285
286
    /**
287
     * get the "method" attribute for the <form> tag
288
     *
289
     * @return string
290
     */
291
    public function getMethod()
292
    {
293
        return (strtolower($this->_method) === 'get') ? 'get' : 'post';
294
    }
295
296
    /**
297
     * Add an element to the form
298
     *
299
     * @param string|XoopsFormElement $formElement reference to a {@link XoopsFormElement}
300
     * @param bool             $required    is this a "required" element?
301
     *
302
     */
303
    public function addElement($formElement, $required = false)
304
    {
305
        if (is_string($formElement)) {
306
            $this->_elements[] = $formElement;
307
        } elseif (is_subclass_of($formElement, 'XoopsFormElement')) {
308
            $this->_elements[] = &$formElement;
309
            if (!$formElement->isContainer()) {
310
                if ($required) {
311
                    $formElement->_required = true;
312
                    $this->_required[]      = &$formElement;
313
                }
314
            } else {
315
                $required_elements = &$formElement->getRequired();
0 ignored issues
show
Bug introduced by
The method getRequired() does not exist on XoopsFormElement. It seems like you code against a sub-type of XoopsFormElement such as XoopsFormElementTray. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

315
                $required_elements = &$formElement->/** @scrutinizer ignore-call */ getRequired();
Loading history...
316
                $count             = count($required_elements);
317
                for ($i = 0; $i < $count; ++$i) {
318
                    $this->_required[] = &$required_elements[$i];
319
                }
320
            }
321
        }
322
    }
323
324
    /**
325
     * get an array of forms elements
326
     *
327
     * @param bool $recurse get elements recursively?
328
     *
329
     * @return XoopsFormElement[] array of {@link XoopsFormElement}s
330
     */
331
    public function &getElements($recurse = false)
332
    {
333
        if (!$recurse) {
334
            return $this->_elements;
335
        } else {
336
            $ret   = array();
337
            $count = count($this->_elements);
338
            for ($i = 0; $i < $count; ++$i) {
339
                if (is_object($this->_elements[$i])) {
340
                    if (!$this->_elements[$i]->isContainer()) {
341
                        $ret[] = &$this->_elements[$i];
342
                    } else {
343
                        $elements = &$this->_elements[$i]->getElements(true);
344
                        $count2   = count($elements);
345
                        for ($j = 0; $j < $count2; ++$j) {
346
                            $ret[] = &$elements[$j];
347
                        }
348
                        unset($elements);
349
                    }
350
                }
351
            }
352
353
            return $ret;
354
        }
355
    }
356
357
    /**
358
     * get an array of "name" attributes of form elements
359
     *
360
     * @return array array of form element names
361
     */
362
    public function getElementNames()
363
    {
364
        $ret      = array();
365
        $elements = &$this->getElements(true);
366
        $count    = count($elements);
367
        for ($i = 0; $i < $count; ++$i) {
368
            $ret[] = $elements[$i]->getName();
369
        }
370
371
        return $ret;
372
    }
373
374
    /**
375
     * get a reference to a {@link XoopsFormElement} object by its "name"
376
     *
377
     * @param  string $name "name" attribute assigned to a {@link XoopsFormElement}
378
     * @return object reference to a {@link XoopsFormElement}, false if not found
379
     */
380
    public function &getElementByName($name)
381
    {
382
        $elements =& $this->getElements(true);
383
        $count    = count($elements);
384
        for ($i = 0; $i < $count; ++$i) {
385
            if ($name == $elements[$i]->getName(false)) {
386
                return $elements[$i];
387
            }
388
        }
389
        $elt = null;
390
391
        return $elt;
392
    }
393
394
    /**
395
     * Sets the "value" attribute of a form element
396
     *
397
     * @param string $name  the "name" attribute of a form element
398
     * @param string $value the "value" attribute of a form element
399
     */
400
    public function setElementValue($name, $value)
401
    {
402
        $ele = &$this->getElementByName($name);
403
        if (is_object($ele) && method_exists($ele, 'setValue')) {
404
            $ele->setValue($value);
405
        }
406
    }
407
408
    /**
409
     * Sets the "value" attribute of form elements in a batch
410
     *
411
     * @param array $values array of name/value pairs to be assigned to form elements
412
     */
413
    public function setElementValues($values)
414
    {
415
        if (is_array($values) && !empty($values)) {
416
            // will not use getElementByName() for performance..
417
            $elements = &$this->getElements(true);
418
            $count    = count($elements);
419
            for ($i = 0; $i < $count; ++$i) {
420
                $name = $elements[$i]->getName(false);
421
                if ($name && isset($values[$name]) && method_exists($elements[$i], 'setValue')) {
422
                    $elements[$i]->setValue($values[$name]);
0 ignored issues
show
Bug introduced by
The method setValue() does not exist on XoopsFormElement. It seems like you code against a sub-type of said class. However, the method does not exist in XoopsFormFile or XoopsFormLabel or XoopsFormElementTray or XoopsFormCaptcha or XoopsFormSelectEditor or XoopsFormDateTime or XoopsFormSelectUser. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

422
                    $elements[$i]->/** @scrutinizer ignore-call */ 
423
                                   setValue($values[$name]);
Loading history...
423
                }
424
            }
425
        }
426
    }
427
428
    /**
429
     * Gets the "value" attribute of a form element
430
     *
431
     * @param  string $name   the "name" attribute of a form element
432
     * @param  bool   $encode To sanitizer the text?
433
     * @return string the "value" attribute assigned to a form element, null if not set
434
     */
435
    public function getElementValue($name, $encode = false)
436
    {
437
        $ele = &$this->getElementByName($name);
438
        if (is_object($ele) && method_exists($ele, 'getValue')) {
439
            return $ele->getValue($encode);
440
        }
441
442
        return null;
443
    }
444
445
    /**
446
     * gets the "value" attribute of all form elements
447
     *
448
     * @param  bool $encode To sanitizer the text?
449
     * @return array array of name/value pairs assigned to form elements
450
     */
451
    public function getElementValues($encode = false)
452
    {
453
        // will not use getElementByName() for performance..
454
        $elements = &$this->getElements(true);
455
        $count    = count($elements);
456
        $values   = array();
457
        for ($i = 0; $i < $count; ++$i) {
458
            $name = $elements[$i]->getName(false);
459
            if ($name && method_exists($elements[$i], 'getValue')) {
460
                $values[$name] = &$elements[$i]->getValue($encode);
0 ignored issues
show
Bug introduced by
The method getValue() does not exist on XoopsFormElement. It seems like you code against a sub-type of said class. However, the method does not exist in XoopsFormFile or XoopsFormElementTray or XoopsFormCaptcha or XoopsGroupFormCheckBox or XoopsFormSelectEditor or XoopsFormDateTime or XoopsFormSelectUser. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

460
                $values[$name] = &$elements[$i]->/** @scrutinizer ignore-call */ getValue($encode);
Loading history...
461
            }
462
        }
463
464
        return $values;
465
    }
466
467
    /**
468
     * set the "class" attribute for the <form> tag
469
     *
470
     * @param string $class
471
     */
472
    public function setClass($class)
473
    {
474
        $class = trim($class);
475
        if (!empty($class)) {
476
            $this->_class[] = $class;
477
        }
478
    }
479
    
480
    /**
481
     * set the extra attributes for the <form> tag
482
     *
483
     * @param string $extra extra attributes for the <form> tag
484
     */
485
    public function setExtra($extra)
486
    {
487
        if (!empty($extra)) {
488
            $this->_extra[] = $extra;
489
        }
490
    }
491
492
    /**
493
     * set the summary tag for the <form> tag
494
     *
495
     * @param string $summary
496
     */
497
    public function setSummary($summary)
498
    {
499
        if (!empty($summary)) {
500
            $this->summary = strip_tags($summary);
0 ignored issues
show
Bug Best Practice introduced by
The property summary does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
501
        }
502
    }
503
504
    /**
505
     * get the "class" attribute for the <form> tag
506
     *
507
     * @return string "class" attribute value
508
     */
509
    public function &getClass()
510
    {
511
        if (empty($this->_class)) {
512
            return false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false returns the type false which is incompatible with the documented return type string.
Loading history...
513
        }
514
        $classes = array();
515
        foreach ($this->_class as $class) {
516
            $classes[] = htmlspecialchars($class, ENT_QUOTES);
517
        }
518
519
        return implode(' ', $classes);
520
    }
521
    
522
    /**
523
     * get the extra attributes for the <form> tag
524
     *
525
     * @return string
526
     */
527
    public function &getExtra()
528
    {
529
        $extra = empty($this->_extra) ? '' : ' ' . implode(' ', $this->_extra);
530
531
        return $extra;
532
    }
533
534
    /**
535
     * make an element "required"
536
     *
537
     * @param XoopsFormElement $formElement reference to a {@link XoopsFormElement}
538
     */
539
    public function setRequired(XoopsFormElement $formElement)
540
    {
541
        $this->_required[] = &$formElement;
542
    }
543
544
    /**
545
     * get an array of "required" form elements
546
     *
547
     * @return array array of {@link XoopsFormElement}s
548
     */
549
    public function &getRequired()
550
    {
551
        return $this->_required;
552
    }
553
554
    /**
555
     * insert a break in the form
556
     *
557
     * This method is abstract. It must be overwritten in the child classes.
558
     *
559
     * @param string $extra extra information for the break
560
     * @abstract
561
     */
562
    public function insertBreak($extra = null)
563
    {
564
    }
565
566
    /**
567
     * returns renderered form
568
     *
569
     * This method is abstract. It must be overwritten in the child classes.
570
     *
571
     * @abstract
572
     */
573
    public function render()
574
    {
575
    }
576
577
    /**
578
     * displays rendered form
579
     */
580
    public function display()
581
    {
582
        echo $this->render();
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->render() targeting XoopsForm::render() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
583
    }
584
585
    /**
586
     * Renders the Javascript function needed for client-side for validation
587
     *
588
     * Form elements that have been declared "required" and not set will prevent the form from being
589
     * submitted. Additionally, each element class may provide its own "renderValidationJS" method
590
     * that is supposed to return custom validation code for the element.
591
     *
592
     * The element validation code can assume that the JS "myform" variable points to the form, and must
593
     * execute <i>return false</i> if validation fails.
594
     *
595
     * A basic element validation method may contain something like this:
596
     * <code>
597
     * function renderValidationJS() {
598
     *            $name = $this->getName();
599
     *            return "if (myform.{$name}.value != 'valid') { " .
600
     *              "myform.{$name}.focus(); window.alert( '$name is invalid' ); return false;" .
601
     *              " }";
602
     * }
603
     * </code>
604
     *
605
     * @param boolean $withtags Include the < javascript > tags in the returned string
606
     *
607
     * @return string
608
     */
609
    public function renderValidationJS($withtags = true)
610
    {
611
        $js = '';
612
        if ($withtags) {
613
            $js .= "\n<!-- Start Form Validation JavaScript //-->\n<script type='text/javascript'>\n<!--//\n";
614
        }
615
        $formname = $this->getName();
616
        $js .= "function xoopsFormValidate_{$formname}() { var myform = window.document.{$formname}; ";
617
        $elements =& $this->getElements(true);
618
        foreach ($elements as $elt) {
619
            if (method_exists($elt, 'renderValidationJS')) {
620
                $js .= $elt->renderValidationJS();
621
            }
622
        }
623
        $js .= "return true;\n}\n";
624
        if ($withtags) {
625
            $js .= "//--></script>\n<!-- End Form Validation JavaScript //-->\n";
626
        }
627
628
        return $js;
629
    }
630
631
    /**
632
     * assign to smarty form template instead of displaying directly
633
     *
634
     * @param XoopsTpl $tpl reference to a {@link Smarty} object object
635
     * @see      Smarty
636
     */
637
    public function assign(XoopsTpl $tpl)
638
    {
639
        $i        = -1;
640
        $elements = array();
641
        //  Removed hard-coded legacy pseudo-element - XoopsFormRenderer is now responsible for the legend
642
        foreach ($this->getElements() as $ele) {
643
            ++$i;
644
            if (is_string($ele)) {
645
                $elements[$i]['body'] = $ele;
646
                continue;
647
            }
648
            $ele_name                 = $ele->getName();
649
            $ele_description          = $ele->getDescription();
650
            $n                        = $ele_name ?: $i;
651
            $elements[$n]['name']     = $ele_name;
652
            $elements[$n]['caption']  = $ele->getCaption();
653
            $elements[$n]['body']     = $ele->render();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $elements[$n]['body'] is correct as $ele->render() targeting XoopsFormElement::render() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
654
            $elements[$n]['hidden']   = $ele->isHidden();
655
            $elements[$n]['required'] = $ele->isRequired();
656
            if ($ele_description != '') {
657
                $elements[$n]['description'] = $ele_description;
658
            }
659
        }
660
        $js = $this->renderValidationJS();
661
        $tpl->assign($this->getName(), array(
662
            'title'      => $this->getTitle(),
663
            'name'       => $this->getName(),
664
            'action'     => $this->getAction(),
665
            'method'     => $this->getMethod(),
666
            'extra'      => 'onsubmit="return xoopsFormValidate_' . $this->getName() . '();"' . $this->getExtra(),
667
            'javascript' => $js,
668
            'elements'   => $elements,
669
            'rendered'   => $this->render(),
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->render() targeting XoopsForm::render() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
670
        ));
671
    }
672
}
673