Completed
Push — master ( 48ff0c...a157cb )
by wen
03:02
created

Input   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getModelFieldLength() 0 8 2
A getModelColumn() 0 6 1
A getMaxLength() 0 8 2
A setMaxLength() 0 6 1
A getMinLength() 0 4 1
A setMinLength() 0 6 1
A toArray() 0 7 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 NamedElement
9
{
10
    protected $maxLength;
11
    protected $minLength = 0;
12
13
    protected function getModelFieldLength()
14
    {
15
        $column = $this->getModelColumn();
16
        if ($column->getType()->getName() == Type::STRING) {
17
            return $column->getLength();
18
        }
19
        return;
20
    }
21
22
    protected function getModelColumn()
23
    {
24
        $table  = DB::getTablePrefix() . $this->getModel()->getTable();
25
        $column = $this->getName();
26
        return DB::getDoctrineColumn($table, $column);
27
    }
28
29
    public function getMaxLength()
30
    {
31
        if ($this->maxLength) {
32
            return $this->maxLength;
33
        }
34
35
        return $this->getModelFieldLength();
36
    }
37
38
    public function setMaxLength($value)
39
    {
40
        $this->maxLength = (int)$value;
41
42
        return $this;
43
    }
44
45
    public function getMinLength()
46
    {
47
        return $this->minLength;
48
    }
49
50
    public function setMinLength($value)
51
    {
52
        $this->minLength = (int)$value;
53
54
        return $this;
55
    }
56
57
    public function toArray()
58
    {
59
        return parent::toArray() + [
60
                'minLength' => $this->getMinLength(),
61
                'maxLength' => $this->getMaxLength(),
62
            ];
63
    }
64
}
65