Passed
Push — master ( ef009a...7c77cf )
by Josh
02:14
created

ElementProperty::setOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace LCI\Blend\Helpers;
4
5
6
class ElementProperty
7
{
8
    /** @var string  */
9
    protected $area = '';
10
11
    /** @var string  */
12
    protected $description = ''; // description or desc??
13
14
    /** @var null|string */
15
    protected $lexicon = null;
16
17
    /** @var string */
18
    protected $name;
19
20
    /** @var array ~ only for color and list */
21
    protected $options = [];
22
23
    /** @var string ~ combo-boolean, textfield, textarea, datefield, list, , numberfield, file, color */
24
    protected $type = 'textfield'; // xtype, type
25
26
    /** @var mixed */
27
    protected $value;
28
29
    /**
30
     * ElementProperty constructor.
31
     * @param $name
32
     */
33
    public function __construct($name)
34
    {
35
        $this->name = $name;
36
    }
37
38
    /**
39
     * @return string
40
     */
41
    public function getName(): string
42
    {
43
        return $this->name;
44
    }
45
46
    /**
47
     * @return array
48
     */
49
    public function toArray()
50
    {
51
        return [
52
            'name' => $this->name,
53
            'desc' => $this->description,
54
            'type' => $this->type,
55
            'options' => $this->options,
56
            'value' => $this->value,
57
            'lexicon' => $this->lexicon,
58
            'area' => $this->area
59
        ];
60
    }
61
62
    /**
63
     * @param string $area
64
     * @return ElementProperty
65
     */
66
    public function setArea(string $area): ElementProperty
67
    {
68
        $this->area = $area;
69
        return $this;
70
    }
71
72
    /**
73
     * @param string $description
74
     * @return ElementProperty
75
     */
76
    public function setDescription(string $description): ElementProperty
77
    {
78
        $this->description = $description;
79
        return $this;
80
    }
81
82
    /**
83
     * @param null|string $lexicon
84
     * @return ElementProperty
85
     */
86
    public function setLexicon(string $lexicon): ElementProperty
87
    {
88
        $this->lexicon = $lexicon;
89
        return $this;
90
    }
91
92
    /**
93
     * @param string $text
94
     * @param $value
95
     * @return $this
96
     */
97
    public function addOption(string $text, $value)
98
    {
99
        $this->options[] = [
100
            'text' => $text,
101
            'value' => $value
102
        ];
103
104
        return $this;
105
    }
106
107
    /**
108
     * @param array $options
109
     * @return $this
110
     */
111
    public function addOptions(array $options)
112
    {
113
        foreach ($options as $option) {
114
            $this->options[] = $option;
115
        }
116
117
        return $this;
118
    }
119
120
    /**
121
     * @param array $options ~ [['text' => 'Option', 'value' => 'opt'], ... ]
122
     *  only valid for color and list
123
     * @return ElementProperty
124
     */
125
    public function setOptions(array $options): ElementProperty
126
    {
127
        $this->options = $options;
128
        return $this;
129
    }
130
131
    /**
132
     * @param string $type
133
     *  combo-boolean, textfield, textarea, datefield, list, , numberfield, file, color
134
     * @return ElementProperty
135
     */
136
    public function setType(string $type): ElementProperty
137
    {
138
        $this->type = $type;
139
        return $this;
140
    }
141
142
    /**
143
     * @param mixed $value
144
     * @return ElementProperty
145
     */
146
    public function setValue($value)
147
    {
148
        $this->value = $value;
149
        return $this;
150
    }
151
}