Completed
Push — feature/update_flight ( 5eb300...a7cb77 )
by Laurent
01:44
created

BaseInput::getOption()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 *
4
 */
5
6
namespace flightlog\form;
7
8
/**
9
 * @author Laurent De Coninck <[email protected]>
10
 */
11
abstract class BaseInput implements FormElementInterface
12
{
13
    /**
14
     * @var string
15
     */
16
    private $name;
17
18
    /**
19
     * @var array
20
     */
21
    private $options;
22
23
    /**
24
     * @var string|int
25
     */
26
    private $value;
27
28
    /**
29
     * @var string
30
     */
31
    private $type;
32
33
    /**
34
     * @param string $name
35
     * @param string $type
36
     * @param array  $options
37
     */
38
    public function __construct($name, $type, array $options = [])
39
    {
40
        if (empty($name)) {
41
            throw new \InvalidArgumentException('Name cannot be empty');
42
        }
43
44
        $this->name = $name;
45
        $this->options = $options;
46
        $this->type = $type;
47
    }
48
49
    /**
50
     * @inheritDoc
51
     */
52
    public function getType()
53
    {
54
        return $this->type;
55
    }
56
57
    /**
58
     * @inheritDoc
59
     */
60
    public function getOptions()
61
    {
62
        return $this->options;
63
    }
64
65
    /**
66
     * @inheritDoc
67
     */
68
    public function getName()
69
    {
70
        return $this->name;
71
    }
72
73
    /**
74
     * @inheritDoc
75
     */
76
    public function getValue()
77
    {
78
        return $this->value;
79
    }
80
81
    /**
82
     * @inheritDoc
83
     */
84
    public function setValue($value)
85
    {
86
        $this->value = $value;
87
    }
88
89
    /**
90
     * @param string     $name
91
     * @param int|string $value
92
     *
93
     * @return $this
94
     */
95
    public function setAttribute($name, $value)
96
    {
97
        $this->options['attr'][$name] = $value;
98
99
        return $this;
100
    }
101
102
    /**
103
     * @return $this
104
     */
105
    public function required(){
106
        $this->options['attr']['required'] = 'required';
107
108
        return $this;
109
    }
110
111
    /**
112
     * @return $this
113
     */
114
    public function disable(){
115
        $this->options['attr']['disabled'] = 'disabled';
116
        return $this;
117
    }
118
119
    /**
120
     * @param string $option
121
     *
122
     * @return string|int|boolean|null
123
     */
124
    public function getOption($option){
125
        if(!isset($this->options[$option])){
126
            return null;
127
        }
128
129
        return $this->options[$option];
130
    }
131
132
}