Checkbox::getButtonName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
ccs 2
cts 2
cp 1
cc 1
eloc 1
nc 1
nop 0
crap 1
1
<?php 
2
3
namespace Helmut\Forms\Fields\Checkbox;
4
5
use Helmut\Forms\Field;
6
7
class Checkbox extends Field {
8
9
    protected $value = false;
10
11 7
    public function getValue() 
12
    {
13 7
        return $this->value;
14
    }
15
16 9
    public function getButtonName()
17
    {
18 9
        //
19
    }    
20
21 5
    public function renderWith() 
22
    {
23 5
        return ['checked' => $this->value];
24
    }       
25
26 5
    public function setChecked()
27
    {
28 5
        $this->default = true;
29 5
        return $this;
30
    }
31
32 2
    public function setUnchecked()
33
    {
34 2
        $this->default = false;
35 2
        return $this;
36
    }   
37
38 9
    public function setValueFromDefault()
39
    {
40 9
        $this->value = $this->default;
41 9
    }
42
43 1
    public function setValueFromModel($model)
44
    {
45 1
        if (isset($model->{$this->name})) {
46 1
            $this->value = $model->{$this->name} ? true : false;
47
        }
48
    }   
49
50
    public function setValueFromRequest($request)
51
    {
52
        $this->value = $request->get($this->name) ? true : false;
53 1
    }
54
55 1
    public function fillModelWithValue($model)
56 1
    {
57
        $model->{$this->name} = $this->value ? 1 : 0;
58 1
    }
59
60 1
    public function validateRequired()
61
    {
62
        return $this->value === true;
63
    }
64
65
}
66