Completed
Push — master ( c0ab41...a9fac5 )
by wen
13:45
created

Number::getDefaultMax()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Sco\Admin\Form\Elements;
4
5
class Number extends NamedElement
6
{
7
    protected $type = 'number';
8
9
    protected $max;
10
11
    protected $min = 0;
12
13
    protected $step = 1;
14
15
    /**
16
     * @return string|int
17
     */
18
    public function getMax()
19
    {
20
        if ($this->max) {
21
            return $this->max;
22
        }
23
24
        return $this->getDefaultMax();
25
    }
26
27
    protected function getDefaultMax()
28
    {
29
        return 'Infinity';
30
    }
31
32
    /**
33
     * @param int $value
34
     * @return $this
35
     */
36
    public function setMax(int $value)
37
    {
38
        $this->max = $value;
39
40
        $this->addValidationRule('max:' . $value);
41
42
        return $this;
43
    }
44
45
    /**
46
     * @return int
47
     */
48
    public function getMin()
49
    {
50
        return $this->min;
51
    }
52
53
    /**
54
     * @param int $value
55
     * @return $this
56
     */
57
    public function setMin(int $value)
58
    {
59
        $this->min = $value;
60
61
        $this->addValidationRule('min:' . $value);
62
63
        return $this;
64
    }
65
66
    /**
67
     * @return int
68
     */
69
    public function getStep()
70
    {
71
        return $this->step;
72
    }
73
74
    /**
75
     * @param int $value
76
     * @return $this
77
     */
78
    public function setStep(int $value)
79
    {
80
        $this->step = $value;
81
82
        return $this;
83
    }
84
85
    protected function getDefaultValidationRules()
86
    {
87
        return parent::getDefaultValidationRules() + [
88
                'numeric' => 'numeric'
89
            ];
90
    }
91
92
    public function toArray()
93
    {
94
        return parent::toArray() + [
95
                'min'  => $this->getMin(),
96
                'max'  => $this->getMax(),
97
                'step' => $this->getStep(),
98
            ];
99
    }
100
}
101