Nip_Form_Element_Checkbox   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 16
c 1
b 0
f 0
dl 0
loc 53
ccs 0
cts 19
cp 0
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getDataFromModel() 0 7 3
A setChecked() 0 8 2
A isChecked() 0 3 1
A init() 0 4 1
A getDataFromRequest() 0 4 1
1
<?php
2
3
class Nip_Form_Element_Checkbox extends Nip_Form_Element_Input_Abstract
4
{
5
    protected $_type = 'checkbox';
6
7
    public function init()
8
    {
9
        parent::init();
10
        $this->setAttrib('type', 'checkbox');
11
    }
12
13
    /**
14
     * @param $request
15
     * @return $this
16
     */
17
    public function getDataFromRequest($request)
18
    {
19
        $this->setChecked($request != null);
20
        return parent::getDataFromRequest($request);
21
    }
22
23
    /**
24
     * @param boolean $checked
25
     * @return $this
26
     */
27
    public function setChecked($checked)
28
    {
29
        if ($checked === true) {
30
            $this->setAttrib('checked', 'checked');
31
        } else {
32
            $this->delAttrib('checked');
33
        }
34
        return $this;
35
    }
36
37
    /**
38
     * @param $data
39
     * @return $this
40
     */
41
    public function getDataFromModel($value)
42
    {
43
        $inputValue = $this->getValue();
44
        if ($inputValue == null && $value) {
45
            $this->setChecked(true);
46
        }
47
        return parent::getDataFromModel($value);
48
    }
49
50
    /**
51
     * @return bool
52
     */
53
    public function isChecked()
54
    {
55
        return $this->getAttrib('checked') == 'checked';
56
    }
57
}
58