Completed
Push — master ( 31307f...55a138 )
by Michael
03:27
created

FormRRuleCheckBox::render()   C

Complexity

Conditions 7
Paths 10

Size

Total Lines 22
Code Lines 15

Duplication

Lines 4
Ratio 18.18 %

Importance

Changes 0
Metric Value
cc 7
eloc 15
nc 10
nop 0
dl 4
loc 22
rs 6.9811
c 0
b 0
f 0
1
<?php namespace XoopsModules\Extcal\Form;
2
/*
3
 * You may not change or alter any portion of this comment or credits
4
 * of supporting developers from this source code or any supporting source code
5
 * which is considered copyrighted (c) material of the original comment or credit authors.
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
 */
11
12
/**
13
 * @copyright    {@link https://xoops.org/ XOOPS Project}
14
 * @license      {@link http://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later}
15
 * @package      extcal
16
 * @since
17
 * @author       XOOPS Development Team,
18
 */
19
20
21
/**
22
 * Class FormRRuleCheckBox.
23
 */
24
class FormRRuleCheckBox extends \XoopsFormCheckBox
25
{
26
    /**
27
     * @param      $caption
28
     * @param      $name
29
     * @param null $value
30
     */
31
    public function __construct($caption, $name, $value = null)
32
    {
33
        parent::__construct($caption, $name, $value);
34
    }
35
36
    /**
37
     * prepare HTML for output.
38
     *
39
     * @return string
40
     */
41
    public function render()
42
    {
43
        $ret = '<table><tr>';
44
        $i   = 0;
45 View Code Duplication
        if (count($this->getOptions()) > 1 && '[]' !== substr($this->getName(), -2, 2)) {
0 ignored issues
show
Bug introduced by
Consider using $this->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
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...
46
            $newname = $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...
47
            $this->setName($newname);
48
        }
49
        foreach ($this->getOptions() as $value => $name) {
50
            if (0 == (++$i) % 6) {
51
                $ret .= '</tr><tr>';
52
            }
53
            $ret .= "<td><input type='checkbox' name='" . $this->getName() . "' value='" . $value . "'";
0 ignored issues
show
Bug introduced by
Consider using $this->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
54
            if (count($this->getValue()) > 0 && in_array($value, $this->getValue())) {
55
                $ret .= ' checked';
56
            }
57
            $ret .= $this->getExtra() . '>' . $name . "</td>\n";
58
        }
59
        $ret .= '</tr></table>';
60
61
        return $ret;
62
    }
63
}
64