Passed
Pull Request — master (#38)
by
unknown
02:06
created

Option::setUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
ccs 0
cts 3
cp 0
crap 2
rs 10
c 1
b 0
f 0
1
<?php
2
namespace Maknz\Slack\Object;
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
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...
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 17
    public function getText()
62
    {
63 17
        return $this->text;
64
    }
65
66
    /**
67
     * Set the option text.
68
     *
69
     * @param mixed $text
70
     *
71
     * @return Option
72
     *
73
     * @throws \InvalidArgumentException
74
     */
75 29
    public function setText($text)
76
    {
77 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...
78
79 29
        return $this;
80
    }
81
82
    /**
83
     * Get the option value.
84
     *
85
     * @return string
86
     */
87 15
    public function getValue()
88
    {
89 15
        return $this->value;
90
    }
91
92
    /**
93
     * Set the option value.
94
     *
95
     * @param string $value
96
     *
97
     * @return Option
98
     */
99 29
    public function setValue($value)
100
    {
101 29
        $this->value = $value;
102
103 29
        return $this;
104
    }
105
106
    /**
107
     * Get the option description.
108
     *
109
     * @return Maknz\Slack\BlockElement\Text
110
     */
111 8
    public function getDescription()
112
    {
113 8
        return $this->description;
114
    }
115
116
    /**
117
     * Set the option description.
118
     *
119
     * @param mixed $description
120
     *
121
     * @return Option
122
     *
123
     * @throws \InvalidArgumentException
124
     */
125
    public function setDescription($description)
126
    {
127
        $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...
128
129
        return $this;
130
    }
131
132
    /**
133
     * Get the option URL.
134
     *
135
     * @return string
136
     */
137 8
    public function getUrl()
138
    {
139 8
        return $this->url;
140
    }
141
142
    /**
143
     * Set the option URL.
144
     *
145
     * @param string $value
146
     *
147
     * @return Option
148
     */
149
    public function setUrl($url)
150
    {
151
        $this->url = $url;
152
153
        return $this;
154
    }
155
156
    /**
157
     * Get whether the option group has a selected option.
158
     *
159
     * @return bool
160
     */
161 14
    public function isInitiallySelected()
162
    {
163 14
        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 Option
172
     */
173 16
    public function setInitiallySelected($selected)
174
    {
175 16
        $this->initially_selected = (bool)$selected;
176
177 16
        return $this;
178
    }
179
180
    /**
181
     * Convert the block to its array representation.
182
     *
183
     * @return array
184
     */
185 8
    public function toArray()
186
    {
187
        $data = [
188 8
            'text'    => $this->getText()->toArray(),
189 8
            'value'   => $this->getValue(),
190
        ];
191
192 8
        if ($this->getDescription()) {
193
            $data['description'] = $this->getDescription()->toArray();
194
        }
195
196 8
        if ($this->getUrl()) {
197
            $data['url'] = $this->getUrl();
198
        }
199
200 8
        return $data;
201
    }
202
}
203