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

Input   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 9
c 0
b 0
f 0
lcom 1
cbo 2
dl 0
loc 61
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getMax() 0 8 2
A getModelFieldLength() 0 8 2
A getModelColumn() 0 6 1
A setMax() 0 6 1
A getMin() 0 4 1
A setMin() 0 6 1
A toArray() 0 9 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