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

Input::getModelFieldLength()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 3
eloc 5
nc 2
nop 0
1
<?php
2
3
namespace Sco\Admin\Form\Elements;
4
5
/**
6
 * Class Input
7
 *
8
 * @see http://element.eleme.io/#/en-US/component/input
9
 * @package Sco\Admin\Form\Elements
10
 */
11
abstract class Input extends NamedElement
12
{
13
    /**
14
     * @var
15
     */
16
    protected $maxLength;
17
18
    /**
19
     * @var int
20
     */
21
    protected $minLength = 0;
22
23
    /**
24
     * @var string
25
     */
26
    protected $size = '';
27
28
    /**
29
     * @var bool
30
     */
31
    protected $readonly = false;
32
33
    /**
34
     * @return string
35
     */
36
    public function getSize()
37
    {
38
        return $this->size;
39
    }
40
41
    /**
42
     * @param string $value
43
     * @return $this
44
     */
45
    public function setSize(string $value)
46
    {
47
        $this->size = $value;
48
49
        return $this;
50
    }
51
52
    /**
53
     * @return $this
54
     */
55
    public function mediumSize()
56
    {
57
        return $this->setSize('medium');
58
    }
59
60
    /**
61
     * @return $this
62
     */
63
    public function smallSize()
64
    {
65
        return $this->setSize('small');
66
    }
67
68
    /**
69
     * @return $this
70
     */
71
    public function miniSize()
72
    {
73
        return $this->setSize('mini');
74
    }
75
76
    /**
77
     * @return mixed
78
     */
79
    public function getMaxLength()
80
    {
81
        return $this->maxLength;
82
    }
83
84
    /**
85
     * @param int $value
86
     * @return $this
87
     */
88
    public function setMaxLength(int $value)
89
    {
90
        $this->maxLength = $value;
91
        $this->addValidationRule('max:' . $value);
92
93
        return $this;
94
    }
95
96
    /**
97
     * @return int
98
     */
99
    public function getMinLength()
100
    {
101
        return $this->minLength;
102
    }
103
104
    /**
105
     * @param int $value
106
     * @return $this
107
     */
108
    public function setMinLength(int $value)
109
    {
110
        $this->minLength = $value;
111
112
        $this->addValidationRule('min:' . $value);
113
114
        return $this;
115
    }
116
117
    /**
118
     * @return bool
119
     */
120
    public function isReadonly()
121
    {
122
        return $this->readonly;
123
    }
124
125
    /**
126
     * @return $this
127
     */
128
    public function readonly()
129
    {
130
        $this->readonly = true;
131
132
        return $this;
133
    }
134
135
    public function toArray()
136
    {
137
        return parent::toArray() + [
138
                'minLength' => $this->getMinLength(),
139
                'maxLength' => $this->getMaxLength(),
140
                'size'      => $this->getSize(),
141
                'readonly'  => $this->isReadonly(),
142
            ];
143
    }
144
}
145