Passed
Push — master ( eec14a...4028c5 )
by Alexander
02:26
created

ConversationsSelect   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 126
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 36
dl 0
loc 126
ccs 28
cts 28
cp 1
rs 10
c 1
b 0
f 0
wmc 11

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getDefaultToCurrentConversation() 0 3 1
A toArray() 0 27 6
A getInitialConversation() 0 3 1
A setInitialConversation() 0 9 2
A setDefaultToCurrentConversation() 0 5 1
1
<?php
2
namespace Maknz\Slack\BlockElement;
3
4
use InvalidArgumentException;
5
use Maknz\Slack\FilterTrait;
6
7
class ConversationsSelect extends RespondableSelect
8
{
9
    use FilterTrait;
10
11
    /**
12
     * Block type.
13
     *
14
     * @var string
15
     */
16
    protected $type = 'conversations_select';
17
18
    /**
19
     * The initially selected conversation.
20
     *
21
     * @var string
22
     */
23
    protected $initial_conversation;
24
25
    /**
26
     * Whether to initially select the current conversation.
27
     *
28
     * @var bool
29
     */
30
    protected $default_to_current_conversation = false;
31
32
    /**
33
     * Internal attribute to property map.
34
     *
35
     * @var array
36
     */
37
    protected static $availableAttributes = [
38
        'placeholder'                     => 'placeholder',
39
        'action_id'                       => 'action_id',
40
        'initial_conversation'            => 'initial_conversation',
41
        'default_to_current_conversation' => 'default_to_current_conversation',
42
        'confirm'                         => 'confirm',
43
        'response_url_enabled'            => 'response_url_enabled',
44
        'filter'                          => 'filter',
45
    ];
46
47
    /**
48
     * Get the initially selected conversation.
49
     *
50
     * @return string
51
     */
52 4
    public function getInitialConversation()
53
    {
54 4
        return $this->initial_conversation;
55
    }
56
57
    /**
58
     * Set the initially selected conversation.
59
     *
60
     * @param string $initialConversation
61
     *
62
     * @return $this
63
     *
64
     * @throws InvalidArgumentException
65
     */
66 4
    public function setInitialConversation($initialConversation)
67
    {
68 4
        if (is_string($initialConversation)) {
0 ignored issues
show
introduced by
The condition is_string($initialConversation) is always true.
Loading history...
69 3
            $this->initial_conversation = $initialConversation;
70
71 3
            return $this;
72
        }
73
74 1
        throw new InvalidArgumentException('The initial conversation ID must be a string');
75
    }
76
77
    /**
78
     * Get whether to default to the current conversation.
79
     *
80
     * @return bool
81
     */
82 1
    public function getDefaultToCurrentConversation()
83
    {
84 1
        return $this->default_to_current_conversation;
85
    }
86
87
    /**
88
     * Set whether to default to the current conversation.
89
     *
90
     * @param string $defaultToCurrentConversation
91
     *
92
     * @return $this
93
     */
94 1
    public function setDefaultToCurrentConversation($defaultToCurrentConversation)
95
    {
96 1
        $this->default_to_current_conversation = (bool)$defaultToCurrentConversation;
97
98 1
        return $this;
99
    }
100
101
    /**
102
     * Convert the block to its array representation.
103
     *
104
     * @return array
105
     */
106 2
    public function toArray()
107
    {
108 2
        $data = [
109 2
            'type'        => $this->getType(),
110 2
            'placeholder' => $this->getPlaceholder()->toArray(),
111 2
            'action_id'   => $this->getActionId(),
112
        ];
113
114 2
        if ($this->getInitialConversation()) {
115 2
            $data['initial_conversation'] = $this->getInitialConversation();
116 1
        } elseif ($this->getDefaultToCurrentConversation()) {
117 1
            $data['default_to_current_conversation'] = true;
118
        }
119
120 2
        if ($this->getConfirm()) {
121 1
            $data['confirm'] = $this->getConfirm()->toArray();
122
        }
123
124 2
        if ($this->isResponseUrlEnabled()) {
125 1
            $data['response_url_enabled'] = true;
126
        }
127
128 2
        if ($this->getFilter()) {
129 1
            $data['filter'] = $this->getFilter()->toArray();
130
        }
131
132 2
        return $data;
133
    }
134
}
135