Completed
Push — master ( 2b7730...10405b )
by wen
11:53
created

Input   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getMaxLength() 0 4 1
A setMaxLength() 0 7 1
A getMinLength() 0 4 1
A setMinLength() 0 8 1
A isReadonly() 0 4 1
A readonly() 0 6 1
A toArray() 0 8 1
1
<?php
2
3
namespace Sco\Admin\Form\Elements;
4
5
/**
6
 * Class Input
7
 *
8
 * @package Sco\Admin\Form\Elements
9
 * @see http://element.eleme.io/#/en-US/component/input
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 bool
25
     */
26
    protected $readonly = false;
27
28
    /**
29
     * @return mixed
30
     */
31
    public function getMaxLength()
32
    {
33
        return $this->maxLength;
34
    }
35
36
    /**
37
     * @param int $value
38
     * @return $this
39
     */
40
    public function setMaxLength(int $value)
41
    {
42
        $this->maxLength = $value;
43
        $this->addValidationRule('max:' . $value);
44
45
        return $this;
46
    }
47
48
    /**
49
     * @return int
50
     */
51
    public function getMinLength()
52
    {
53
        return $this->minLength;
54
    }
55
56
    /**
57
     * @param int $value
58
     * @return $this
59
     */
60
    public function setMinLength(int $value)
61
    {
62
        $this->minLength = $value;
63
64
        $this->addValidationRule('min:' . $value);
65
66
        return $this;
67
    }
68
69
    /**
70
     * @return bool
71
     */
72
    public function isReadonly()
73
    {
74
        return $this->readonly;
75
    }
76
77
    /**
78
     * @return $this
79
     */
80
    public function readonly()
81
    {
82
        $this->readonly = true;
83
84
        return $this;
85
    }
86
87
    public function toArray()
88
    {
89
        return parent::toArray() + [
90
                'minLength' => $this->getMinLength(),
91
                'maxLength' => $this->getMaxLength(),
92
                'readonly'  => $this->isReadonly(),
93
            ];
94
    }
95
}
96