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

UsersSelect::setInitialUser()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 2
rs 10
c 1
b 0
f 0
1
<?php
2
namespace Maknz\Slack\BlockElement;
3
4
use InvalidArgumentException;
5
6
class UsersSelect extends AbstractDynamicSelect
7
{
8
    /**
9
     * Block type.
10
     *
11
     * @var string
12
     */
13
    protected $type = 'users_select';
14
15
    /**
16
     * The initially selected user.
17
     *
18
     * @var string
19
     */
20
    protected $initial_user;
21
22
    /**
23
     * Internal attribute to property map.
24
     *
25
     * @var array
26
     */
27
    protected static $availableAttributes = [
28
        'placeholder'  => 'placeholder',
29
        'action_id'    => 'action_id',
30
        'initial_user' => 'initial_user',
31
        'confirm'      => 'confirm',
32
    ];
33
34
    /**
35
     * Get the initially selected user.
36
     *
37
     * @return string
38
     */
39 3
    public function getInitialUser()
40
    {
41 3
        return $this->initial_user;
42
    }
43
44
    /**
45
     * Set the initially selected user.
46
     *
47
     * @param string $initialUser
48
     *
49
     * @return $this
50
     *
51
     * @throws InvalidArgumentException
52
     */
53 3
    public function setInitialUser($initialUser)
54
    {
55 3
        if (is_string($initialUser)) {
0 ignored issues
show
introduced by
The condition is_string($initialUser) is always true.
Loading history...
56 2
            $this->initial_user = $initialUser;
57
58 2
            return $this;
59
        }
60
61 1
        throw new InvalidArgumentException('The initial user ID must be a string');
62
    }
63
64
    /**
65
     * Convert the block to its array representation.
66
     *
67
     * @return array
68
     */
69 1
    public function toArray()
70
    {
71 1
        $data = [
72 1
            'type'        => $this->getType(),
73 1
            'placeholder' => $this->getPlaceholder()->toArray(),
74 1
            'action_id'   => $this->getActionId(),
75
        ];
76
77 1
        if ($this->getInitialUser()) {
78 1
            $data['initial_user'] = $this->getInitialUser();
79
        }
80
81 1
        if ($this->getConfirm()) {
82 1
            $data['confirm'] = $this->getConfirm()->toArray();
83
        }
84
85 1
        return $data;
86
    }
87
}
88