Checkbox   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 108
Duplicated Lines 7.41 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
dl 8
loc 108
c 2
b 0
f 1
wmc 7
lcom 1
cbo 1
ccs 0
cts 37
cp 0
rs 10

7 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 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
/**
6
 * Class Checkbox
7
 *
8
 * @package Sco\Admin\Form\Elements
9
 * @see http://element.eleme.io/#/en-US/component/checkbox
10
 */
11
class Checkbox extends MultiSelect
12
{
13
    protected $type = 'checkbox';
14
15
    /**
16
     * maximum number of checkbox checked
17
     *
18
     * @var int|null
19
     */
20
    protected $max;
21
22
    /**
23
     * minimum number of checkbox checked
24
     *
25
     * @var int
26
     */
27
    protected $min = 0;
28
29
    /**
30
     * If show check all button.
31
     *
32
     * @var bool
33
     */
34
    protected $showCheckAll = false;
35
36
    /**
37
     * Get maximum number.
38
     *
39
     * @return int|null
40
     */
41
    public function getMax()
42
    {
43
        return $this->max;
44
    }
45
46
    /**
47
     * Set maximum number.
48
     *
49
     * @param int $value
50
     *
51
     * @return $this
52
     */
53
    public function setMax(int $value)
54
    {
55
        $this->max = $value;
56
57
        $this->addValidationRule('max:' . $value);
58
59
        return $this;
60
    }
61
62
    /**
63
     * Get minimum number.
64
     *
65
     * @return int
66
     */
67
    public function getMin()
68
    {
69
        return $this->min;
70
    }
71
72
    /**
73
     * Set minimum number.
74
     *
75
     * @param int $value
76
     *
77
     * @return $this
78
     */
79
    public function setMin(int $value)
80
    {
81
        $this->min = $value;
82
83
        $this->addValidationRule('min:' . $value);
84
85
        return $this;
86
    }
87
88
    /**
89
     * Determine if show check all button.
90
     *
91
     * @return bool
92
     */
93
    public function isShowCheckAll()
94
    {
95
        return $this->showCheckAll;
96
    }
97
98
    /**
99
     * Show check all button.
100
     *
101
     * @return $this
102
     */
103
    public function enableShowCheckAll()
104
    {
105
        $this->showCheckAll = true;
106
107
        return $this;
108
    }
109
110 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...
111
    {
112
        return parent::toArray() + [
113
                'min'          => $this->getMin(),
114
                'max'          => $this->getMax(),
115
                'showCheckAll' => $this->isShowCheckAll(),
116
            ];
117
    }
118
}
119