Completed
Push — master ( 30f23d...c3cbe9 )
by Derek Stephen
05:45
created

CheckBox::uncheckValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
c 0
b 0
f 0
ccs 8
cts 8
cp 1
rs 9.4285
cc 2
eloc 7
nc 2
nop 1
crap 2
1
<?php
2
/**
3
 * User: delboy1978uk
4
 * Date: 19/11/2016
5
 * Time: 21:37
6
 */
7
8
namespace Del\Form\Field;
9
10
use Del\Form\Renderer\Field\CheckboxRender;
11
use Del\Form\Traits\CanRenderInlineTrait;
12
use Del\Form\Traits\HasOptionsTrait;
13
14
class CheckBox extends FieldAbstract implements ArrayValueInterface
15
{
16
17
    use CanRenderInlineTrait;
18
    use HasOptionsTrait;
19
20
    /**
21
     * We end up ignoring this during rendering Checkboxes, see the renderer for info
22
     *
23
     * @return string
24
     */
25 6
    public function getTag()
26
    {
27 6
        return 'div';
28
    }
29
30 8
    public function init()
31
    {
32 8
        $this->setValue([]);
33 8
        $this->setRenderInline(false);
34 8
        $this->setRenderer(new CheckboxRender());
35 8
    }
36
37
    /**
38
     * @param $key
39
     * @return $this
40
     */
41 2
    public function checkValue($key)
42
    {
43 2
        $values = $this->getValue();
44 2
        $values[$key] = true;
45 2
        $this->setValue($values);
46 2
        return $this;
47
    }
48
49
    /**
50
     * @param $key
51
     * @return $this
52
     */
53 1
    public function uncheckValue($key)
54
    {
55 1
        $values = $this->getValue();
56 1
        if (in_array($key, $values)) {
57 1
            $index = array_search($key, $values);
58 1
            unset($values[$index]);
59 1
        }
60 1
        $this->setValue($values);
61 1
        return $this;
62
    }
63
}