Completed
Push — master ( f05a87...6b2b65 )
by wen
14:04
created

Checkbox::getDefaultValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Sco\Admin\Form\Elements;
4
5
class Checkbox extends Select
6
{
7
    protected $type = 'checkbox';
8
9
    protected $defaultValue = [];
10
11
    protected $max;
12
    protected $min          = 0;
13
    protected $showCheckAll = false;
14
15
    public function getMax()
16
    {
17
        return $this->max;
18
    }
19
20
    public function setMax($value)
21
    {
22
        $this->max = (int)$value;
23
24
        $this->addValidationRule('max:' . $value);
25
26
        return $this;
27
    }
28
29
    public function getMin()
30
    {
31
        return $this->min;
32
    }
33
34
    public function setMin($value)
35
    {
36
        $this->min = (int)$value;
37
38
        $this->addValidationRule('min:' . $value);
39
40
        return $this;
41
    }
42
43
    public function isShowCheckAll()
44
    {
45
        return $this->showCheckAll;
46
    }
47
48
    public function enableShowCheckAll()
49
    {
50
        $this->showCheckAll = true;
51
52
        return $this;
53
    }
54
55
    public function getValue()
56
    {
57
        $value = parent::getValue();
58
        if (empty($value)) {
59
            return [];
60
        }
61
        return explode(',', $value);
62
    }
63
64
    protected function prepareValue($value)
65
    {
66
        if (empty($value)) {
67
            return '';
68
        }
69
70
        return implode(',', $value);
71
    }
72
73 View Code Duplication
    public function toArray()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
74
    {
75
        return parent::toArray() + [
76
                'min'          => $this->getMin(),
77
                'max'          => $this->getMax(),
78
                'showCheckAll' => $this->isShowCheckAll(),
79
            ];
80
    }
81
}
82