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

Input::getHint()   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\Block;
3
4
use InvalidArgumentException;
5
use Maknz\Slack\Block;
6
use Maknz\Slack\BlockElement;
7
use Maknz\Slack\BlockElement\Text;
8
9
class Input extends Block
10
{
11
    /**
12
     * Block type.
13
     *
14
     * @var string
15
     */
16
    protected $type = 'input';
17
18
    /**
19
     * Label that appears above the input.
20
     *
21
     * @var \Maknz\Slack\BlockElement\Text
22
     */
23
    protected $label;
24
25
    /**
26
     * Input element.
27
     *
28
     * @var \Maknz\Slack\BlockElement
29
     */
30
    protected $element;
31
32
    /**
33
     * A hint that appears below the input.
34
     *
35
     * @var \Maknz\Slack\BlockElement\Text
36
     */
37
    protected $hint;
38
39
    /**
40
     * Whether the input may be empty.
41
     *
42
     * @var bool
43
     */
44
    protected $optional = false;
45
46
    /**
47
     * Internal attribute to property map.
48
     *
49
     * @var array
50
     */
51
    protected static $availableAttributes = [
52
        'label'    => 'label',
53
        'element'  => 'element',
54
        'hint'     => 'hint',
55
        'optional' => 'optional',
56
    ];
57
58
    /**
59
     * Get the input label.
60
     *
61
     * @return \Maknz\Slack\BlockElement\Text
62
     */
63 1
    public function getLabel()
64
    {
65 1
        return $this->label;
66
    }
67
68
    /**
69
     * Set the input label.
70
     *
71
     * @param mixed
72
     *
73
     * @return Input
74
     */
75 1
    public function setLabel($label)
76
    {
77 1
        $this->label = Text::create($label);
78
79 1
        return $this;
80
    }
81
82
    /**
83
     * Get the input element.
84
     *
85
     * @return \Maknz\Slack\BlockElement
86
     */
87 2
    public function getElement()
88
    {
89 2
        return $this->element;
90
    }
91
92
    /**
93
     * Set the input element.
94
     *
95
     * @param mixed
96
     *
97
     * @return Input
98
     *
99
     * @throws \InvalidArgumentException
100
     */
101 3
    public function setElement($element)
102
    {
103 3
        $element = BlockElement::factory($element);
104
105 3
        if ( ! $element->isValidFor($this)) {
106 1
            throw new InvalidArgumentException('Block element '.get_class($element).' is not valid for '.static::class);
107
        }
108
109 2
        $this->element = $element;
110
111 2
        return $this;
112
    }
113
114
    /**
115
     * Get the input hint.
116
     *
117
     * @return \Maknz\Slack\BlockElement\Text
118
     */
119 2
    public function getHint()
120
    {
121 2
        return $this->hint;
122
    }
123
124
    /**
125
     * Set the input hint.
126
     *
127
     * @param mixed
128
     *
129
     * @return Input
130
     */
131 1
    public function setHint($hint)
132
    {
133 1
        $this->hint = Text::create($hint);
134
135 1
        return $this;
136
    }
137
138
    /**
139
     * Get whether the input is optional.
140
     *
141
     * @return bool
142
     */
143 1
    public function getOptional()
144
    {
145 1
        return $this->optional;
146
    }
147
148
    /**
149
     * Set whether the input is optional.
150
     *
151
     * @param bool
152
     *
153
     * @return Input
154
     */
155 1
    public function setOptional($optional)
156
    {
157 1
        $this->optional = (bool)$optional;
158
159 1
        return $this;
160
    }
161
162
    /**
163
     * Convert the block to its array representation.
164
     *
165
     * @return array
166
     */
167 1
    public function toArray()
168
    {
169
        $data = [
170 1
            'type'    => $this->getType(),
171 1
            'label'   => $this->getLabel()->toArray(),
172 1
            'element' => $this->getElement()->toArray(),
173
        ];
174
175 1
        if ($this->getBlockId()) {
176
            $data['block_id'] = $this->getBlockId();
177
        }
178
179 1
        if ($this->getHint()) {
180
            $data['hint'] = $this->getHint()->toArray();
181
        }
182
183 1
        if ($this->getOptional() != null) {
184 1
            $data['optional'] = $this->getOptional();
185
        }
186
187 1
        return $data;
188
    }
189
}
190