Completed
Pull Request — master (#38)
by
unknown
03:25
created

Option::getDescription()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
namespace Maknz\Slack\Object;
3
4
use InvalidArgumentException;
5
use Maknz\Slack\BlockElement\Text;
6
7
class Option extends CompositionObject
8
{
9
    /**
10
     * Option text.
11
     *
12
     * @var Maknz\Slack\BlockElement\Text
0 ignored issues
show
Bug introduced by
The type Maknz\Slack\Object\Maknz\Slack\BlockElement\Text was not found. Did you mean Maknz\Slack\BlockElement\Text? If so, make sure to prefix the type with \.
Loading history...
13
     */
14
    protected $text;
15
16
    /**
17
     * Option value.
18
     *
19
     * @var string
20
     */
21
    protected $value;
22
23
    /**
24
     * Option group description.
25
     *
26
     * @var Maknz\Slack\BlockElement\Text
27
     */
28
    protected $description;
29
30
    /**
31
     * URL to be loaded when the option is clicked.
32
     *
33
     * @var string
34
     */
35
    protected $url;
36
37
    /**
38
     * Whether this option is initially selected.
39
     *
40
     * @var bool
41
     */
42
    protected $initially_selected = false;
43
44
    /**
45
     * Internal attribute to property map.
46
     *
47
     * @var array
48
     */
49
    protected static $availableAttributes = [
50
        'text'        => 'text',
51
        'value'       => 'value',
52
        'description' => 'description',
53
        'url'         => 'url',
54
        'selected'    => 'initially_selected',
55
    ];
56
57
    /**
58
     * Get the option text.
59
     *
60
     * @return Maknz\Slack\BlockElement\Text
61
     */
62 17
    public function getText()
63
    {
64 17
        return $this->text;
65
    }
66
67
    /**
68
     * Set the option text.
69
     *
70
     * @param mixed $text
71
     *
72
     * @return Option
73
     *
74
     * @throws \InvalidArgumentException
75
     */
76 29
    public function setText($text)
77
    {
78 29
        $this->text = Text::create($text, Text::TYPE_PLAIN);
0 ignored issues
show
Documentation Bug introduced by
It seems like Maknz\Slack\BlockElement...ement\Text::TYPE_PLAIN) of type Maknz\Slack\BlockElement\Text is incompatible with the declared type Maknz\Slack\Object\Maknz\Slack\BlockElement\Text of property $text.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
79
80 29
        return $this;
81
    }
82
83
    /**
84
     * Get the option value.
85
     *
86
     * @return string
87
     */
88 15
    public function getValue()
89
    {
90 15
        return $this->value;
91
    }
92
93
    /**
94
     * Set the option value.
95
     *
96
     * @param string $value
97
     *
98
     * @return Option
99
     */
100 29
    public function setValue($value)
101
    {
102 29
        $this->value = $value;
103
104 29
        return $this;
105
    }
106
107
    /**
108
     * Get the option description.
109
     *
110
     * @return Maknz\Slack\BlockElement\Text
111
     */
112 8
    public function getDescription()
113
    {
114 8
        return $this->description;
115
    }
116
117
    /**
118
     * Set the option description.
119
     *
120
     * @param mixed $description
121
     *
122
     * @return Option
123
     *
124
     * @throws \InvalidArgumentException
125
     */
126
    public function setDescription($description)
127
    {
128
        $this->description = Text::create($description, Text::TYPE_PLAIN);
0 ignored issues
show
Documentation Bug introduced by
It seems like Maknz\Slack\BlockElement...ement\Text::TYPE_PLAIN) of type Maknz\Slack\BlockElement\Text is incompatible with the declared type Maknz\Slack\Object\Maknz\Slack\BlockElement\Text of property $description.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
129
130
        return $this;
131
    }
132
133
    /**
134
     * Get the option URL.
135
     *
136
     * @return string
137
     */
138 8
    public function getUrl()
139
    {
140 8
        return $this->url;
141
    }
142
143
    /**
144
     * Set the option URL.
145
     *
146
     * @param string $value
147
     *
148
     * @return Option
149
     */
150
    public function setUrl($url)
151
    {
152
        $this->url = $url;
153
154
        return $this;
155
    }
156
157
    /**
158
     * Get whether the option group has a selected option.
159
     *
160
     * @return bool
161
     */
162 14
    public function isInitiallySelected()
163
    {
164 14
        return $this->initially_selected;
165
    }
166
167
    /**
168
     * Set whether the option group has a selected option.
169
     *
170
     * @param bool $selected
171
     *
172
     * @return Option
173
     */
174 16
    public function setInitiallySelected($selected)
175
    {
176 16
        $this->initially_selected = (bool)$selected;
177
178 16
        return $this;
179
    }
180
181
    /**
182
     * Convert the block to its array representation.
183
     *
184
     * @return array
185
     */
186 8
    public function toArray()
187
    {
188
        $data = [
189 8
            'text'    => $this->getText()->toArray(),
190 8
            'value'   => $this->getValue(),
191
        ];
192
193 8
        if ($this->getDescription()) {
194
            $data['description'] = $this->getDescription()->toArray();
195
        }
196
197 8
        if ($this->getUrl()) {
198
            $data['url'] = $this->getUrl();
199
        }
200
201 8
        return $data;
202
    }
203
}
204