Completed
Push — master ( c4ab64...474227 )
by wen
02:28
created

Input::setMin()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Sco\Admin\Form\Elements;
4
5
use DB;
6
use Doctrine\DBAL\Types\Type;
7
8
class Input extends Element
9
{
10
    protected $defaultValue = '';
11
12
    protected $max;
13
    protected $min;
14
15
    public function getMax()
16
    {
17
        if ($this->max) {
18
            return $this->max;
19
        }
20
21
        return $this->getModelFieldLength();
22
    }
23
24
    protected function getModelFieldLength()
25
    {
26
        $column = $this->getModelColumn();
27
        if ($column->getType()->getName() == Type::STRING) {
28
            return $column->getLength();
29
        }
30
        return;
31
    }
32
33
    protected function getModelColumn()
34
    {
35
        $table = DB::getTablePrefix() . $this->getModel()->getTable();
36
        $column = $this->getName();
37
        return DB::getDoctrineColumn($table, $column);
38
    }
39
40
    public function setMax($value)
41
    {
42
        $this->max = intval($value);
43
44
        return $this;
45
    }
46
47
    public function getMin()
48
    {
49
        return $this->min;
50
    }
51
52
    public function setMin($value)
53
    {
54
        $this->min = intval($value);
55
56
        return $this;
57
    }
58
59
    public function toArray()
60
    {
61
        $data = [];
62
            $data['minlength'] = $this->getMin();
63
64
            $data['maxlength'] = $this->getMax();
65
66
        return parent::toArray() + $data;
67
    }
68
}
69