Completed
Push — master ( 8431a9...0bccd4 )
by Gabriel
04:28
created

Nip_Form_Element_Checkbox   A

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
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
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();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $inputValue is correct as $this->getValue() targeting Nip\Form\Elements\AbstractElement::getValue() 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...
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';
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->getAttrib('checked') targeting Nip\Form\Elements\AbstractElement::getAttrib() 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...
56
    }
57
}
58