Passed
Pull Request — master (#40)
by
unknown
02:56
created

AttachmentAction::setUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 9.4285
c 0
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
 */
19
final class AttachmentAction
20
{
21
    const TYPE_BUTTON = 'button';
22
23
    const STYLE_DEFAULT = 'default';
24
    const STYLE_PRIMARY = 'primary';
25
    const STYLE_DANGER = 'danger';
26
27
    /**
28
     * The required name field of the action. The name will be returned to your Action URL.
29
     *
30
     * @var string
31
     */
32
    private $name;
33
34
    /**
35
     * The required label for the action.
36
     *
37
     * @var string
38
     */
39
    private $text;
40
41
    /**
42
     * Button style.
43
     *
44
     * @var string
45
     */
46
    private $style = self::STYLE_DEFAULT;
47
48
    /**
49
     * The required type of the action.
50
     *
51
     * @var string
52
     */
53
    private $type = self::TYPE_BUTTON;
54
55
    /**
56
     * Optional value. It will be sent to your Action URL.
57
     *
58
     * @var string|null
59
     */
60
    private $value;
61
 
62
    /**
63
     * Optional url. It will be sent to any external URL.
64
     * Not compatible with confirm action on button
65
     *
66
     * @var string|null
67
     */
68
    private $url;
69
70
    /**
71
     * Confirmation field.
72
     *
73
     * @var ActionConfirmation|null
74
     */
75
    private $confirm;
76
77
    /**
78
     * @param string $name
79
     * @param string $text
80
     */
81
    public function __construct(string $name, string $text)
82
    {
83
        $this->name = $name;
84
        $this->text = $text;
85
    }
86
87
    /**
88
     * @return string
89
     */
90
    public function getName(): string
91
    {
92
        return $this->name;
93
    }
94
95
    /**
96
     * @return string
97
     */
98
    public function getText(): string
99
    {
100
        return $this->text;
101
    }
102
103
    /**
104
     * @return string
105
     */
106
    public function getStyle(): string
107
    {
108
        return $this->style;
109
    }
110
111
    /**
112
     * @param string $style
113
     *
114
     * @return AttachmentAction
115
     */
116
    public function setStyle(string $style): self
117
    {
118
        $this->style = $style;
119
120
        return $this;
121
    }
122
123
    /**
124
     * @return string
125
     */
126
    public function getType(): string
127
    {
128
        return $this->type;
129
    }
130
131
    /**
132
     * @param string $type
133
     *
134
     * @return AttachmentAction
135
     */
136
    public function setType(string $type): self
137
    {
138
        $this->type = $type;
139
140
        return $this;
141
    }
142
143
    /**
144
     * @return string|null
145
     */
146
    public function getValue(): ?string
147
    {
148
        return $this->value;
149
    }
150
151
    /**
152
     * @param string $value
153
     *
154
     * @return AttachmentAction
155
     */
156
    public function setValue(?string $value): self
157
    {
158
        $this->value = $value;
159
160
        return $this;
161
    }
162
    
163
    /**
164
     * @param string $url
165
     *
166
     * @return AttachmentAction
167
     */    
168
    public function setUrl(string $url): self
169
    {
170
        $this->url = $url;
171
172
        return $this;
173
    }
174
175
    public function getUrl(): string
176
    {
177
        return $this->url;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->url could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
178
    }
179
180
    /**
181
     * @return ActionConfirmation|null
182
     */
183
    public function getConfirm(): ?ActionConfirmation
184
    {
185
        return $this->confirm;
186
    }
187
188
    /**
189
     * @param ActionConfirmation $confirm
190
     *
191
     * @return AttachmentAction
192
     */
193
    public function setConfirm(?ActionConfirmation $confirm): self
194
    {
195
        $this->confirm = $confirm;
196
197
        return $this;
198
    }
199
200
    /**
201
     * Get the array representation of this attachment action.
202
     *
203
     * @return array
204
     */
205
    public function toArray(): array
206
    {
207
        return [
208
            'name' => $this->name,
209
            'text' => $this->text,
210
            'style' => $this->style,
211
            'type' => $this->type,
212
            'value' => $this->value,
213
            'url' => $this->url,
214
            'confirm' => $this->confirm ? $this->confirm->toArray() : null,
215
        ];
216
    }
217
}
218