Completed
Push — master ( 442119...4a1793 )
by wen
02:50
created

Input::getMinLength()   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
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Sco\Admin\Form\Elements;
4
5
use DB;
6
7
class Input extends Element
8
{
9
    protected $defaultValue = '';
10
11
    protected $maxLength;
12
    protected $minLength = 0;
13
14
    public function getMaxLength()
15
    {
16
        if ($this->maxLength) {
17
            return $this->maxLength;
18
        }
19
20
        return $this->getModelFieldLength();
21
    }
22
23
    protected function getModelFieldLength()
24
    {
25
        return $this->getModelColumn()->getLength();
26
    }
27
28
    protected function getModelColumn()
29
    {
30
        $table = DB::getTablePrefix() . $this->getModel()->getTable();
31
        $column = $this->getName();
32
        return DB::getDoctrineColumn($table, $column);
33
    }
34
35
    public function setMaxLength($value)
36
    {
37
        $this->maxLength = intval($value);
38
39
        return $this;
40
    }
41
42
    public function getMinLength()
43
    {
44
        return $this->minLength;
45
    }
46
47
    public function setMinLength($value)
48
    {
49
        $this->minLength = intval($value);
50
51
        return $this;
52
    }
53
54
    public function toArray()
55
    {
56
        $data = [];
57
            $data['minlength'] = $this->getMinLength();
58
59
            $data['maxlength'] = $this->getMaxLength();
60
61
        return parent::toArray() + $data;
62
    }
63
}
64