GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#54)
by
unknown
06:42
created

AttachmentAction::setType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Maknz\Slack;
4
5
use InvalidArgumentException;
6
7
class AttachmentAction
8
{
9
    const TYPE_BUTTON = 'button';
10
11
    const STYLE_DEFAULT = 'default';
12
    const STYLE_PRIMARY = 'primary';
13
    const STYLE_DANGER = 'danger';
14
15
    /**
16
     * The required name field of the action. The name will be returned to your Action URL.
17
     *
18
     * @var string
19
     */
20
    protected $name;
21
22
    /**
23
     * The required label for the action.
24
     *
25
     * @var string
26
     */
27
    protected $text;
28
29
    /**
30
     * Button style.
31
     *
32
     * @var string
33
     */
34
    protected $style;
35
36
    /**
37
     * The required type of the action.
38
     *
39
     * @var string
40
     */
41
    protected $type = self::TYPE_BUTTON;
42
43
    /**
44
     * Optional value. It will be sent to your Action URL.
45
     *
46
     * @var string
47
     */
48
    protected $value;
49
50
    /**
51
     * Confirmation field.
52
     *
53
     * @var ActionConfirmation
54
     */
55
    protected $confirm;
56
57
58
    /**
59
     * Instantiate a new AttachmentAction.
60
     *
61
     * @param array $attributes
62
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
63
     */
64
    public function __construct(array $attributes)
65
    {
66
        if (isset($attributes['name'])) {
67
            $this->setName($attributes['name']);
68
        }
69
70
        if (isset($attributes['text'])) {
71
            $this->setText($attributes['text']);
72
        }
73
74
        if (isset($attributes['style'])) {
75
            $this->setStyle($attributes['style']);
76
        }
77
78
        if (isset($attributes['type'])) {
79
            $this->setType($attributes['type']);
80
        }
81
82
        if (isset($attributes['value'])) {
83
            $this->setValue($attributes['value']);
84
        }
85
86
        if (isset($attributes['confirm'])) {
87
            $this->setConfirm($attributes['confirm']);
88
        }
89
    }
90
91
    /**
92
     * @return string
93
     */
94
    public function getName()
95
    {
96
        return $this->name;
97
    }
98
99
    /**
100
     * @param string $name
101
     * @return AttachmentAction
102
     */
103
    public function setName($name)
104
    {
105
        $this->name = $name;
106
107
        return $this;
108
    }
109
110
    /**
111
     * @return string
112
     */
113
    public function getText()
114
    {
115
        return $this->text;
116
    }
117
118
    /**
119
     * @param string $text
120
     * @return AttachmentAction
121
     */
122
    public function setText($text)
123
    {
124
        $this->text = $text;
125
126
        return $this;
127
    }
128
129
    /**
130
     * @return string
131
     */
132
    public function getStyle()
133
    {
134
        return $this->style;
135
    }
136
137
    /**
138
     * @param string $style
139
     * @return AttachmentAction
140
     */
141
    public function setStyle($style)
142
    {
143
        $this->style = $style;
144
145
        return $this;
146
    }
147
148
    /**
149
     * @return string
150
     */
151
    public function getType()
152
    {
153
        return $this->type;
154
    }
155
156
    /**
157
     * @param string $type
158
     * @return AttachmentAction
159
     */
160
    public function setType($type)
161
    {
162
        $this->type = $type;
163
164
        return $this;
165
    }
166
167
    /**
168
     * @return string
169
     */
170
    public function getValue()
171
    {
172
        return $this->value;
173
    }
174
175
    /**
176
     * @param string $value
177
     * @return AttachmentAction
178
     */
179
    public function setValue($value)
180
    {
181
        $this->value = $value;
182
183
        return $this;
184
    }
185
186
    /**
187
     * @return ActionConfirmation
188
     */
189
    public function getConfirm()
190
    {
191
        return $this->confirm;
192
    }
193
194
    /**
195
     * @param ActionConfirmation|array $confirm
196
     * @return AttachmentAction
197
     */
198
    public function setConfirm($confirm)
199
    {
200
        if ($confirm instanceof ActionConfirmation) {
201
            $this->confirm = $confirm;
202
203
            return $this;
204
        } elseif (is_array($confirm)) {
205
            $this->confirm = new ActionConfirmation($confirm);
206
207
            return $this;
208
        }
209
210
        throw new InvalidArgumentException('The action confirmation must be an instance of Maknz\Slack\ActionConfirmation or a keyed array');
211
    }
212
213
    /**
214
     * Get the array representation of this attachment action.
215
     *
216
     * @return array
217
     */
218
    public function toArray()
219
    {
220
        return [
221
            'name' => $this->getName(),
222
            'text' => $this->getText(),
223
            'style' => $this->getStyle(),
224
            'type' => $this->getType(),
225
            'value' => $this->getValue(),
226
            'confirm' => $this->getConfirm()->toArray(),
227
        ];
228
    }
229
}
230