Passed
Pull Request — master (#75)
by Chris
12:05
created

ChannelSelect   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 25
c 1
b 0
f 0
dl 0
loc 85
ccs 19
cts 19
cp 1
rs 10
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 21 4
A setInitialChannel() 0 9 2
A getInitialChannel() 0 3 1
1
<?php
2
namespace Maknz\Slack\BlockElement;
3
4
use InvalidArgumentException;
5
use Maknz\Slack\Object\Option;
6
7
class ChannelSelect extends RespondableSelect
8
{
9
    /**
10
     * Block type.
11
     *
12
     * @var string
13
     */
14
    protected $type = 'channels_select';
15
16
    /**
17
     * The initially selected channel.
18
     *
19
     * @var string
20
     */
21
    protected $initial_channel;
22
23
    /**
24
     * Internal attribute to property map.
25
     *
26
     * @var array
27
     */
28
    protected static $availableAttributes = [
29
        'placeholder'          => 'placeholder',
30
        'action_id'            => 'action_id',
31
        'initial_channel'      => 'initial_channel',
32
        'confirm'              => 'confirm',
33
        'response_url_enabled' => 'response_url_enabled',
34
    ];
35
36
    /**
37
     * Get the initially selected channel.
38
     *
39
     * @return string
40
     */
41 3
    public function getInitialChannel()
42
    {
43 3
        return $this->initial_channel;
44
    }
45
46
    /**
47
     * Set the initially selected channel.
48
     *
49
     * @param string $initialChannel
50
     *
51
     * @return $this
52
     *
53
     * @throws InvalidArgumentException
54
     */
55 3
    public function setInitialChannel($initialChannel)
56
    {
57 3
        if (is_string($initialChannel)) {
0 ignored issues
show
introduced by
The condition is_string($initialChannel) is always true.
Loading history...
58 2
            $this->initial_channel = $initialChannel;
59
60 2
            return $this;
61
        }
62
63 1
        throw new InvalidArgumentException('The initial channel ID must be a string');
64
    }
65
66
    /**
67
     * Convert the block to its array representation.
68
     *
69
     * @return array
70
     */
71 1
    public function toArray()
72
    {
73 1
        $data = [
74 1
            'type'        => $this->getType(),
75 1
            'placeholder' => $this->getPlaceholder()->toArray(),
76 1
            'action_id'   => $this->getActionId(),
77
        ];
78
79 1
        if ($this->getInitialChannel()) {
80 1
            $data['initial_channel'] = $this->getInitialChannel();
81
        }
82
83 1
        if ($this->getConfirm()) {
84 1
            $data['confirm'] = $this->getConfirm()->toArray();
85
        }
86
87 1
        if ($this->isResponseUrlEnabled()) {
88 1
            $data['response_url_enabled'] = true;
89
        }
90
91 1
        return $data;
92
    }
93
}
94