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

Checkbox   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 77
Duplicated Lines 10.39 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
dl 8
loc 77
c 2
b 0
f 1
wmc 11
lcom 1
cbo 1
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A getMax() 0 4 1
A setMax() 0 8 1
A getMin() 0 4 1
A setMin() 0 8 1
A isShowCheckAll() 0 4 1
A enableShowCheckAll() 0 6 1
A getValue() 0 8 2
A prepareValue() 0 8 2
A toArray() 8 8 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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