Completed
Push — master ( 73de08...39d3cf )
by Gabor
03:53
created

CheckboxElement::setValue()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 0
cts 9
cp 0
rs 9.2
c 0
b 0
f 0
cc 4
eloc 6
nc 3
nop 1
crap 20
1
<?php
2
/**
3
 * WebHemi.
4
 *
5
 * PHP version 5.6
6
 *
7
 * @copyright 2012 - 2016 Gixx-web (http://www.gixx-web.com)
8
 * @license   https://opensource.org/licenses/MIT The MIT License (MIT)
9
 *
10
 * @link      http://www.gixx-web.com
11
 */
12
namespace WebHemi\Form\Element\Web;
13
14
/**
15
 * Class RadioElement.
16
 */
17
class CheckboxElement extends RadioElement
18
{
19
    /**
20
     * Returns the element type.
21
     *
22
     * @return string
23
     */
24
    public function getType()
25
    {
26
        return 'checkbox';
27
    }
28
29
    /**
30
     * Sets element value.
31
     *
32
     * @param mixed $value
33
     * @return RadioElement
34
     */
35
    public function setValue($value)
36
    {
37
        if (empty($this->options) && is_numeric($value)) {
38
            $this->value = $value ? 1 : 0;
39
        } else {
40
            parent::setValue($value);
41
        }
42
43
        return $this;
44
    }
45
46
    /**
47
     * Returns element value.
48
     *
49
     * @return mixed
50
     */
51
    public function getValue()
52
    {
53
        if (empty($this->options)) {
54
            return $this->value;
55
        }
56
57
        return parent::getValue();
58
    }
59
}
60