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

Button::getValue()   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\BlockElement;
3
4
class Button extends Confirmable
5
{
6
    const STYLE_DEFAULT = 'default';
7
    const STYLE_PRIMARY = 'primary';
8
    const STYLE_DANGER = 'danger';
9
10
    /**
11
     * Block type.
12
     *
13
     * @var string
14
     */
15
    protected $type = 'button';
16
17
    /**
18
     * Button text.
19
     *
20
     * @var Maknz\Slack\BlockElement\Text
0 ignored issues
show
Bug introduced by
The type Maknz\Slack\BlockElement...Slack\BlockElement\Text was not found. Did you mean Maknz\Slack\BlockElement\Text? If so, make sure to prefix the type with \.
Loading history...
21
     */
22
    protected $text;
23
24
    /**
25
     * Button action.
26
     *
27
     * @var string
28
     */
29
    protected $action_id;
30
31
    /**
32
     * Button URL.
33
     *
34
     * @var string
35
     */
36
    protected $url;
37
38
    /**
39
     * Button value.
40
     *
41
     * @var string
42
     */
43
    protected $value;
44
45
    /**
46
     * Button style.
47
     *
48
     * @var string
49
     */
50
    protected $style;
51
52
    /**
53
     * Internal attribute to property map.
54
     *
55
     * @var array
56
     */
57
    protected static $availableAttributes = [
58
        'text'      => 'text',
59
        'action_id' => 'action_id',
60
        'url'       => 'url',
61
        'value'     => 'value',
62
        'style'     => 'style',
63
        'confirm'   => 'confirm',
64
    ];
65
66
    /**
67
     * Get the button text.
68
     *
69
     * @return Maknz\Slack\BlockElement\Text
70
     */
71 6
    public function getText()
72
    {
73 6
        return $this->text;
74
    }
75
76
    /**
77
     * Set the button text.
78
     *
79
     * @param mixed $text
80
     *
81
     * @return Button
82
     *
83
     * @throws \InvalidArgumentException
84
     */
85 6
    public function setText($text)
86
    {
87 6
        $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\BlockElement...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...
88
89 6
        return $this;
90
    }
91
92
    /**
93
     * Get the button action.
94
     *
95
     * @return string
96
     */
97 4
    public function getActionId()
98
    {
99 4
        return $this->action_id;
100
    }
101
102
    /**
103
     * Set the button action.
104
     *
105
     * @param string $actionId
106
     *
107
     * @return Button
108
     */
109 5
    public function setActionId($actionId)
110
    {
111 5
        $this->action_id = $actionId;
112
113 5
        return $this;
114
    }
115
116
    /**
117
     * Get the button URL.
118
     *
119
     * @return string
120
     */
121 4
    public function getUrl()
122
    {
123 4
        return $this->url;
124
    }
125
126
    /**
127
     * Set the button URL.
128
     *
129
     * @param string $url
130
     *
131
     * @return Button
132
     */
133 1
    public function setUrl($url)
134
    {
135 1
        $this->url = $url;
136
137 1
        return $this;
138
    }
139
140
    /**
141
     * Get the button value.
142
     *
143
     * @return string
144
     */
145 5
    public function getValue()
146
    {
147 5
        return $this->value;
148
    }
149
150
    /**
151
     * Set the button value.
152
     *
153
     * @param string $value
154
     *
155
     * @return Button
156
     */
157 3
    public function setValue($value)
158
    {
159 3
        $this->value = $value;
160
161 3
        return $this;
162
    }
163
164
    /**
165
     * Get the button style.
166
     *
167
     * @return string
168
     */
169 4
    public function getStyle()
170
    {
171 4
        return $this->style;
172
    }
173
174
    /**
175
     * Set the button style.
176
     *
177
     * @param string $style
178
     *
179
     * @return Button
180
     */
181 2
    public function setStyle($style)
182
    {
183 2
        $this->style = $style;
184
185 2
        return $this;
186
    }
187
188
    /**
189
     * Convert the block to its array representation.
190
     *
191
     * @return array
192
     */
193 4
    public function toArray()
194
    {
195
        $data = [
196 4
            'type'      => $this->getType(),
197 4
            'text'      => $this->getText()->toArray(),
198 4
            'action_id' => $this->getActionId(),
199
        ];
200
201 4
        if ($this->getUrl()) {
202 1
            $data['url'] = $this->getUrl();
203
        }
204
205 4
        if ($this->getValue()) {
206 2
            $data['value'] = $this->getValue();
207
        }
208
209 4
        if ($this->getStyle()) {
210 2
            $data['style'] = $this->getStyle();
211
        }
212
213 4
        if ($this->getConfirm()) {
214 1
            $data['confirm'] = $this->getConfirm()->toArray();
215
        }
216
217 4
        return $data;
218
    }
219
}
220