Number   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 126
Duplicated Lines 6.35 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 8
loc 126
c 0
b 0
f 0
wmc 12
lcom 1
cbo 1
ccs 0
cts 57
cp 0
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A getMax() 0 8 2
A getDefaultMax() 0 4 1
A setMax() 0 8 1
A getMin() 0 8 2
A getDefaultMin() 0 4 1
A setMin() 0 8 1
A getStep() 0 4 1
A setStep() 0 6 1
A getDefaultValidationRules() 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 Number
7
 *
8
 * @package Sco\Admin\Form\Elements
9
 * @see http://element.eleme.io/#/en-US/component/input-number
10
 */
11
class Number extends NamedElement
12
{
13
    protected $type = 'number';
14
15
    /**
16
     * the maximum allowed value
17
     *
18
     * @var int
19
     */
20
    protected $max;
21
22
    /**
23
     * the minimum allowed value
24
     *
25
     * @var int
26
     */
27
    protected $min;
28
29
    /**
30
     * incremental step
31
     *
32
     * @var int
33
     */
34
    protected $step = 1;
35
36
    /**
37
     * @return string|int
38
     */
39
    public function getMax()
40
    {
41
        if ($this->max) {
42
            return $this->max;
43
        }
44
45
        return $this->getDefaultMax();
46
    }
47
48
    /**
49
     * @return string
50
     */
51
    protected function getDefaultMax()
52
    {
53
        return 'Infinity';
54
    }
55
56
    /**
57
     * @param int $value
58
     * @return $this
59
     */
60
    public function setMax(int $value)
61
    {
62
        $this->max = $value;
63
64
        $this->addValidationRule('max:' . $value);
65
66
        return $this;
67
    }
68
69
    /**
70
     * @return int
71
     */
72
    public function getMin()
73
    {
74
        if ($this->min) {
75
            return $this->min;
76
        }
77
78
        return $this->getDefaultMin();
79
    }
80
81
    /**
82
     * @return string
83
     */
84
    protected function getDefaultMin()
85
    {
86
        return '-Infinity';
87
    }
88
89
    /**
90
     * @param int $value
91
     * @return $this
92
     */
93
    public function setMin(int $value)
94
    {
95
        $this->min = $value;
96
97
        $this->addValidationRule('min:' . $value);
98
99
        return $this;
100
    }
101
102
    /**
103
     * @return int
104
     */
105
    public function getStep()
106
    {
107
        return $this->step;
108
    }
109
110
    /**
111
     * @param int $value
112
     * @return $this
113
     */
114
    public function setStep(int $value)
115
    {
116
        $this->step = $value;
117
118
        return $this;
119
    }
120
121
    protected function getDefaultValidationRules()
122
    {
123
        return parent::getDefaultValidationRules() + [
124
                'numeric' => 'numeric',
125
            ];
126
    }
127
128 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...
129
    {
130
        return parent::toArray() + [
131
                'min'  => $this->getMin(),
132
                'max'  => $this->getMax(),
133
                'step' => $this->getStep(),
134
            ];
135
    }
136
}
137