Completed
Push — master ( 89fe2f...2bde54 )
by wen
05:41
created

Number::setMin()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
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
    protected $min  = 0;
11
    protected $step = 1;
12
13
    public function getMax()
14
    {
15
        return $this->max;
16
    }
17
18
    public function setMax($value)
19
    {
20
        $this->max = (int)$value;
21
22
        $this->addValidationRule('max:' . $value);
23
24
        return $this;
25
    }
26
27
    public function getMin()
28
    {
29
        return $this->min;
30
    }
31
32
    public function setMin($value)
33
    {
34
        $this->min = (int)$value;
35
36
        $this->addValidationRule('min:' . $value);
37
38
        return $this;
39
    }
40
41
    public function setStep($value)
42
    {
43
        $this->step = (int)$value;
44
45
        return $this;
46
    }
47
48
    protected function getDefaultValidationRules()
49
    {
50
        return parent::getDefaultValidationRules() + [
51
            'numeric' => 'numeric'
52
            ];
53
    }
54
55
    public function toArray()
56
    {
57
        return parent::toArray() + [
58
                'min'      => $this->getMin(),
59
                'max'      => $this->getMax(),
60
                'step'     => $this->step,
61
            ];
62
    }
63
}
64