Completed
Push — master ( efa9b4...b05f68 )
by wen
05:55
created

Number::getDefaultMin()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
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
    public function toArray()
129
    {
130
        return parent::toArray() + [
131
                'min'  => $this->getMin(),
132
                'max'  => $this->getMax(),
133
                'step' => $this->getStep(),
134
            ];
135
    }
136
}
137