Passed
Branch master (38ab27)
by Michael
03:06
created

TDMCreateFormRadio::render()   D

Complexity

Conditions 12
Paths 228

Size

Total Lines 43
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 12
eloc 31
nc 228
nop 0
dl 0
loc 43
rs 4.1907
c 0
b 0
f 0

How to fix   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
2
3
/**
4
 * XOOPS form radio compo.
5
 *
6
 * You may not change or alter any portion of this comment or credits
7
 * of supporting developers from this source code or any supporting source code
8
 * which is considered copyrighted (c) material of the original comment or credit authors.
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
 *
13
 * @copyright   The XOOPS project https://xoops.org/
14
 * @license     GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
15
 *
16
 * @since       1.91
17
 *
18
 * @author      Kazumi Ono (AKA onokazu) http://www.myweb.ne.jp/, http://jp.xoops.org/
19
 * @author      Taiwen Jiang <[email protected]>
20
 *
21
 * @version     $Id: TDMCreateFormRadio.php 12360 2014-12-06 13:18:22Z timgno $
22
 */
23
class TDMCreateFormRadio extends XoopsFormRadio
0 ignored issues
show
Bug introduced by
The type XoopsFormRadio was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
24
{
25
    /**
26
     * Prepare HTML for output.
27
     *
28
     * @return string HTML
29
     */
30
    public function render()
31
    {
32
        $ret = '';
33
        $ele_name = $this->getName();
34
        $ele_title = $this->getTitle();
35
        $ele_value = $this->getValue();
36
        $ele_options = $this->getOptions();
37
        $ele_extra = $this->getExtra();
38
        $ele_delimeter = empty($this->columns) ? $this->getDelimeter() : '';
39
        if (!empty($this->columns)) {
40
            $ret .= '<table class="table table-bordered"><tr>';
41
        }
42
        $i = 0;
43
        $id_ele = 0;
44
        foreach ($ele_options as $value => $name) {
45
            ++$id_ele;
46
            if (!empty($this->columns)) {
47
                if (0 == $i % $this->columns) {
48
                    $ret .= '<tr>';
49
                }
50
                $ret .= '<td class="radio">';
51
            }
52
            $ret .= '<input type="radio" name="'.$ele_name.'" id="'.$ele_name.'['.$value.']'.$id_ele.'" title = "'.htmlspecialchars($ele_title, ENT_QUOTES).'" value="'.htmlspecialchars($value, ENT_QUOTES).'"';
53
            if (isset($ele_value) && $value == $ele_value) {
54
                $ret .= ' checked';
55
            }
56
            $ret .= $ele_extra.' />'."<label name='xolb_{$ele_name}' for='".$ele_name.'['.$value.']'.$id_ele."'><span><span></span></span>".$name.'</label>'.$ele_delimeter;
57
            if (!empty($this->columns)) {
58
                $ret .= '</td>';
59
                if (0 == ++$i % $this->columns) {
60
                    $ret .= '</tr>';
61
                }
62
            }
63
        }
64
        if (!empty($this->columns)) {
65
            if ($span = $i % $this->columns) {
66
                $ret .= '<td colspan="'.($this->columns - $span).'"></td></tr>';
67
            }
68
            $ret .= '</table>';
69
        }
70
71
        return $ret;
72
    }
73
}
74