Passed
Push — master ( 8ede22...b3e0ce )
by Alexander
02:27
created

TextInput::toArray()   A

Complexity

Conditions 6
Paths 32

Size

Total Lines 28
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
eloc 14
c 1
b 0
f 0
nc 32
nop 0
dl 0
loc 28
ccs 14
cts 14
cp 1
crap 6
rs 9.2222
1
<?php
2
namespace Maknz\Slack\BlockElement;
3
4
use Maknz\Slack\BlockElement;
5
6
class TextInput extends BlockElement
7
{
8
    /**
9
     * Block type.
10
     *
11
     * @var string
12
     */
13
    protected $type = 'plain_text_input';
14
15
    /**
16
     * Input action.
17
     *
18
     * @var string
19
     */
20
    protected $action_id;
21
22
    /**
23
     * Placeholder shown on the input.
24
     *
25
     * @var \Maknz\Slack\BlockElement\Text
26
     */
27
    protected $placeholder;
28
29
    /**
30
     * Input initial value.
31
     *
32
     * @var string
33
     */
34
    protected $initial_value;
35
36
    /**
37
     * Whether the input spans multiple lines.
38
     *
39
     * @var bool
40
     */
41
    protected $multiline = false;
42
43
    /**
44
     * Minimum length of the input.
45
     *
46
     * @var int
47
     */
48
    protected $min_length;
49
50
    /**
51
     * Maximum length of the input.
52
     *
53
     * @var int
54
     */
55
    protected $max_length;
56
57
    /**
58
     * Internal attribute to property map.
59
     *
60
     * @var array
61
     */
62
    protected static $availableAttributes = [
63
        'action_id'     => 'action_id',
64
        'placeholder'   => 'placeholder',
65
        'initial_value' => 'initial_value',
66
        'multiline'     => 'multiline',
67
        'min_length'    => 'min_length',
68
        'max_length'    => 'max_length',
69
    ];
70
71
    /**
72
     * Get the action.
73
     *
74
     * @return string
75
     */
76 6
    public function getActionId()
77
    {
78 6
        return $this->action_id;
79
    }
80
81
    /**
82
     * Set the action.
83
     *
84
     * @param string $actionId
85
     *
86
     * @return $this
87
     */
88 7
    public function setActionId($actionId)
89
    {
90 7
        $this->action_id = $actionId;
91
92 7
        return $this;
93
    }
94
95
    /**
96
     * Get the placeholder.
97
     *
98
     * @return \Maknz\Slack\BlockElement\Text
99
     */
100 6
    public function getPlaceholder()
101
    {
102 6
        return $this->placeholder;
103
    }
104
105
    /**
106
     * Set the placeholder.
107
     *
108
     * @param mixed $placeholder
109
     *
110
     * @return $this
111
     *
112
     * @throws \InvalidArgumentException
113
     */
114 3
    public function setPlaceholder($placeholder)
115
    {
116 3
        $this->placeholder = Text::create($placeholder, Text::TYPE_PLAIN);
117
118 3
        return $this;
119
    }
120
121
    /**
122
     * Get the initial value.
123
     *
124
     * @return string
125
     */
126 5
    public function getInitialValue()
127
    {
128 5
        return $this->initial_value;
129
    }
130
131
    /**
132
     * Set the initial value.
133
     *
134
     * @param string $initialValue
135
     *
136
     * @return $this
137
     */
138 2
    public function setInitialValue($initialValue)
139
    {
140 2
        $this->initial_value = $initialValue;
141
142 2
        return $this;
143
    }
144
145
    /**
146
     * Get whether the input spans multiple lines.
147
     *
148
     * @return bool
149
     */
150 5
    public function getMultiline()
151
    {
152 5
        return $this->multiline;
153
    }
154
155
    /**
156
     * Set whether the input spans multiple lines.
157
     *
158
     * @param bool $multiline
159
     *
160
     * @return $this
161
     */
162 1
    public function setMultiline($multiline)
163
    {
164 1
        $this->multiline = (bool)$multiline;
165
166 1
        return $this;
167
    }
168
169
    /**
170
     * Get the input minimum length.
171
     *
172
     * @return int
173
     */
174 5
    public function getMinLength()
175
    {
176 5
        return $this->min_length;
177
    }
178
179
    /**
180
     * Set the input minimum length.
181
     *
182
     * @param int $minLength
183
     *
184
     * @return $this
185
     */
186 2
    public function setMinLength($minLength)
187
    {
188 2
        $this->min_length = $minLength;
189
190 2
        return $this;
191
    }
192
193
    /**
194
     * Get the input maximum length.
195
     *
196
     * @return int
197
     */
198 5
    public function getMaxLength()
199
    {
200 5
        return $this->max_length;
201
    }
202
203
    /**
204
     * Set the input maximum length.
205
     *
206
     * @param int $maxLength
207
     *
208
     * @return $this
209
     */
210 2
    public function setMaxLength($maxLength)
211
    {
212 2
        $this->max_length = $maxLength;
213
214 2
        return $this;
215
    }
216
217
    /**
218
     * Convert the block to its array representation.
219
     *
220
     * @return array
221
     */
222 5
    public function toArray()
223
    {
224
        $data = [
225 5
            'type' => $this->getType(),
226 5
            'action_id' => $this->getActionId(),
227
        ];
228
229 5
        if ($this->getPlaceholder()) {
230 2
            $data['placeholder'] = $this->getPlaceholder()->toArray();
231
        }
232
233 5
        if ($this->getInitialValue()) {
234 2
            $data['initial_value'] = $this->getInitialValue();
235
        }
236
237 5
        if ($this->getMultiline() != null) {
238 1
            $data['multiline'] = $this->getMultiline();
239
        }
240
241 5
        if ($this->getMinLength()) {
242 2
            $data['min_length'] = $this->getMinLength();
243
        }
244
245 5
        if ($this->getMaxLength()) {
246 2
            $data['max_length'] = $this->getMaxLength();
247
        }
248
249 5
        return $data;
250
    }
251
}
252