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

UserSelect   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 22
c 1
b 0
f 0
dl 0
loc 80
ccs 17
cts 17
cp 1
rs 10
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getInitialUser() 0 3 1
A toArray() 0 17 3
A setInitialUser() 0 9 2
1
<?php
2
namespace Maknz\Slack\BlockElement;
3
4
use InvalidArgumentException;
5
use Maknz\Slack\Object\Option;
6
7
class UserSelect extends AbstractDynamicSelect
8
{
9
    /**
10
     * Block type.
11
     *
12
     * @var string
13
     */
14
    protected $type = 'users_select';
15
16
    /**
17
     * The initially selected user.
18
     *
19
     * @var string
20
     */
21
    protected $initial_user;
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_user' => 'initial_user',
32
        'confirm'      => 'confirm',
33
    ];
34
35
    /**
36
     * Get the initially selected user.
37
     *
38
     * @return string
39
     */
40 3
    public function getInitialUser()
41
    {
42 3
        return $this->initial_user;
43
    }
44
45
    /**
46
     * Set the initially selected user.
47
     *
48
     * @param string $initialUser
49
     *
50
     * @return $this
51
     *
52
     * @throws InvalidArgumentException
53
     */
54 3
    public function setInitialUser($initialUser)
55
    {
56 3
        if (is_string($initialUser)) {
0 ignored issues
show
introduced by
The condition is_string($initialUser) is always true.
Loading history...
57 2
            $this->initial_user = $initialUser;
58
59 2
            return $this;
60
        }
61
62 1
        throw new InvalidArgumentException('The initial user ID must be a string');
63
    }
64
65
    /**
66
     * Convert the block to its array representation.
67
     *
68
     * @return array
69
     */
70 1
    public function toArray()
71
    {
72 1
        $data = [
73 1
            'type'        => $this->getType(),
74 1
            'placeholder' => $this->getPlaceholder()->toArray(),
75 1
            'action_id'   => $this->getActionId(),
76
        ];
77
78 1
        if ($this->getInitialUser()) {
79 1
            $data['initial_user'] = $this->getInitialUser();
80
        }
81
82 1
        if ($this->getConfirm()) {
83 1
            $data['confirm'] = $this->getConfirm()->toArray();
84
        }
85
86 1
        return $data;
87
    }
88
}
89