Passed
Pull Request — master (#53)
by
unknown
01:19
created

ButtonBlock::setValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Nexylan packages.
7
 *
8
 * (c) Nexylan SAS <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Nexy\Slack;
15
16
/**
17
 * @author Sullivan Senechal <[email protected]>
18
 * @author Mikey McLellan <[email protected]>
19
 */
20
final class ButtonBlock extends SectionBlock
21
{
22
    const STYLE_PRIMARY = 'primary';
23
    const STYLE_DANGER = 'danger';
24
25
    /** @var string */
26
    private $url;
27
28
    /** @var string */
29
    private $value;
30
31
    /** @var string */
32
    private $actionId;
33
34
    /** @var string */
35
    private $style;
36
37
    public function __construct()
38
    {
39
        parent::__construct('button');
40
    }
41
42
    /**
43
     * @return string
44
     */
45
    public function getUrl(): string
46
    {
47
        return $this->url;
48
    }
49
50
    /**
51
     * @param string $url
52
     */
53
    public function setUrl(string $url): self
54
    {
55
        $this->url = $url;
56
57
        return $this;
58
    }
59
60
    /**
61
     * @return string
62
     */
63
    public function getValue(): string
64
    {
65
        return $this->value;
66
    }
67
68
    /**
69
     * @param string $value
70
     */
71
    public function setValue(string $value): self
72
    {
73
        $this->value = $value;
74
75
        return $this;
76
    }
77
78
    /**
79
     * @param string $actionId
80
     */
81
    public function setActionId(string $actionId): self
82
    {
83
        $this->actionId = $actionId;
84
85
        return $this;
86
    }
87
88
    /**
89
     * @return string
90
     */
91
    public function getActionId(): string
92
    {
93
        return $this->actionId;
94
    }
95
96
    /**
97
     * @return string
98
     */
99
    public function getStyle(): string
100
    {
101
        return $this->style;
102
    }
103
104
    /**
105
     * @param string $style
106
     */
107
    public function setStyle(string $style): self
108
    {
109
        $this->style = $style;
110
111
        return $this;
112
    }
113
114
    public function setMarkdown(string $string): SectionBlock
115
    {
116
        throw new \InvalidArgumentException('ButtonBlock must use plain_text');
117
    }
118
119
    /**
120
     * Convert this block to its array representation.
121
     *
122
     * @return array
123
     */
124
    public function toArray(): array
125
    {
126
        $data = [
127
            'url' => $this->url,
128
            'value' => $this->value,
129
            'action_id' => $this->actionId,
130
            'style' => $this->style
131
        ];
132
133
        return array_merge(parent::toArray(), $this->removeNulls($data));
134
    }
135
}
136