Passed
Pull Request — master (#82)
by
unknown
04:46
created

Option::setText()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Maknz\Slack\CompositionObject;
3
4
use Maknz\Slack\BlockElement\Text;
5
6
class Option extends CompositionObject
7
{
8
    /**
9
     * Option text.
10
     *
11
     * @var \Maknz\Slack\BlockElement\Text
12
     */
13
    protected $text;
14
15
    /**
16
     * Option value.
17
     *
18
     * @var string
19
     */
20
    protected $value;
21
22
    /**
23
     * Option group description.
24
     *
25
     * @var \Maknz\Slack\BlockElement\Text
26
     */
27
    protected $description;
28
29
    /**
30
     * URL to be loaded when the option is clicked.
31
     *
32
     * @var string
33
     */
34
    protected $url;
35
36
    /**
37
     * Whether this option is initially selected.
38
     *
39
     * @var bool
40
     */
41
    protected $initially_selected = false;
42
43
    /**
44
     * Internal attribute to property map.
45
     *
46
     * @var array
47
     */
48
    protected static $availableAttributes = [
49
        'text'        => 'text',
50
        'value'       => 'value',
51
        'description' => 'description',
52
        'url'         => 'url',
53
        'selected'    => 'initially_selected',
54
    ];
55
56
    /**
57
     * Get the option text.
58
     *
59
     * @return \Maknz\Slack\BlockElement\Text
60
     */
61 28
    public function getText()
62
    {
63 28
        return $this->text;
64
    }
65
66
    /**
67
     * Set the option text.
68
     *
69
     * @param mixed $text
70
     *
71
     * @return $this
72
     *
73
     * @throws \InvalidArgumentException
74
     */
75 43
    public function setText($text)
76
    {
77 43
        $this->text = Text::create($text, Text::TYPE_PLAIN);
78
79 43
        return $this;
80
    }
81
82
    /**
83
     * Get the option value.
84
     *
85
     * @return string
86
     */
87 27
    public function getValue()
88
    {
89 27
        return $this->value;
90
    }
91
92
    /**
93
     * Set the option value.
94
     *
95
     * @param string $value
96
     *
97
     * @return $this
98
     */
99 43
    public function setValue($value)
100
    {
101 43
        $this->value = $value;
102
103 43
        return $this;
104
    }
105
106
    /**
107
     * Get the option description.
108
     *
109
     * @return \Maknz\Slack\BlockElement\Text
110
     */
111 18
    public function getDescription()
112
    {
113 18
        return $this->description;
114
    }
115
116
    /**
117
     * Set the option description.
118
     *
119
     * @param mixed $description
120
     *
121
     * @return $this
122
     *
123
     * @throws \InvalidArgumentException
124
     */
125 1
    public function setDescription($description)
126
    {
127 1
        $this->description = Text::create($description, Text::TYPE_PLAIN);
128
129 1
        return $this;
130
    }
131
132
    /**
133
     * Get the option URL.
134
     *
135
     * @return string
136
     */
137 18
    public function getUrl()
138
    {
139 18
        return $this->url;
140
    }
141
142
    /**
143
     * Set the option URL.
144
     *
145
     * @param string $url
146
     *
147
     * @return $this
148
     */
149 1
    public function setUrl($url)
150
    {
151 1
        $this->url = $url;
152
153 1
        return $this;
154
    }
155
156
    /**
157
     * Get whether the option group has a selected option.
158
     *
159
     * @return bool
160
     */
161 18
    public function isInitiallySelected()
162
    {
163 18
        return $this->initially_selected;
164
    }
165
166
    /**
167
     * Set whether the option group has a selected option.
168
     *
169
     * @param bool $selected
170
     *
171
     * @return $this
172
     */
173 21
    public function setInitiallySelected($selected)
174
    {
175 21
        $this->initially_selected = (bool)$selected;
176
177 21
        return $this;
178
    }
179
180
    /**
181
     * Convert the block to its array representation.
182
     *
183
     * @return array
184
     */
185 18
    public function toArray()
186
    {
187 18
        $data = [
188 18
            'text'    => $this->getText()->toArray(),
189 18
            'value'   => $this->getValue(),
190
        ];
191
192 18
        if ($this->getDescription()) {
193 1
            $data['description'] = $this->getDescription()->toArray();
194
        }
195
196 18
        if ($this->getUrl()) {
197 1
            $data['url'] = $this->getUrl();
198
        }
199
200 18
        return $data;
201
    }
202
}
203