Completed
Push — master ( ab5ce3...f55930 )
by Helmut
02:51
created

Checkbox::getValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
nc 1
cc 1
eloc 2
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
    public $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;
0 ignored issues
show
Documentation Bug introduced by
It seems like true of type boolean is incompatible with the declared type array of property $default.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
29 5
         return $this;
30
    }
31
32 2
    public function setUnchecked()
33
    {
34 2
         $this->default = false;
0 ignored issues
show
Documentation Bug introduced by
It seems like false of type false is incompatible with the declared type array of property $default.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
35 2
         return $this;
36
    }   
37
38 9
    public function setValueFromDefault()
39
    {
40 9
        $this->value = $this->default;
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->default of type array is incompatible with the declared type boolean of property $value.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
41 9
    }
42
43 1
    public function setValueFromModel($model)
44
    {
45 1
        if (property_exists($model, $this->name)) $this->value = $model->{$this->name} ? true : false;
46 1
    }   
47
48
    public function setValueFromRequest($request)
49
    {
50
        $this->value = $request->get($this->name) ? true : false;
51
    }
52
53 1
    public function fillModelWithValue($model)
54
    {
55 1
        if (property_exists($model, $this->name)) $model->{$this->name} = $this->value ? 1 : 0;
56 1
    }
57
58 1
    public function validateRequired()
59
    {
60 1
        return $this->value === true;
61
    }
62
63
}
64