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
Push — master ( 8dfb79...7e3c2d )
by Cas
08:12 queued 04:57
created

ChatPostMessagePayload::setAsUser()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
/*
4
 * This file is part of the Slack API library.
5
 *
6
 * (c) Cas Leentfaar <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace CL\Slack\Payload;
13
14
use CL\Slack\Model\Attachment;
15
use Doctrine\Common\Collections\ArrayCollection;
16
use JMS\Serializer\Serializer;
17
18
/**
19
 * @author Cas Leentfaar <[email protected]>
20
 *
21
 * @link Official documentation at https://api.slack.com/methods/chat.postMessage
22
 */
23
class ChatPostMessagePayload extends AbstractPayload implements AdvancedSerializeInterface
24
{
25
    /**
26
     * @var string
27
     */
28
    private $channel;
29
30
    /**
31
     * @var string
32
     */
33
    private $text;
34
35
    /**
36
     * @var string
37
     */
38
    private $username;
39
40
    /**
41
     * @var bool
42
     */
43
    private $asUser;
44
45
    /**
46
     * @var string
47
     */
48
    private $iconEmoji;
49
50
    /**
51
     * @var string
52
     */
53
    private $iconUrl;
54
55
    /**
56
     * @var bool
57
     */
58
    private $unfurlLinks;
59
60
    /**
61
     * @var bool
62
     */
63
    private $unfurlMedia;
64
65
    /**
66
     * @var bool
67
     */
68
    private $linkNames;
69
70
    /**
71
     * @var string
72
     */
73
    private $parse;
74
75
    /**
76
     * @var Attachment[]|ArrayCollection
77
     */
78
    private $attachments;
79
80
    /**
81
     * @var string
82
     */
83
    private $attachmentsJson;
84
85 1
    public function __construct()
86
    {
87 1
        $this->attachments = new ArrayCollection();
88 1
    }
89
90
    /**
91
     * Sets the channel to send the message to.
92
     * Can be a public channel, private group, IM channel, encoded ID, or a name.
93
     *
94
     * @param string $channel
95
     */
96 1
    public function setChannel($channel)
97
    {
98 1
        $this->channel = $channel;
99 1
    }
100
101
    /**
102
     * @return string The channel to send the message to.
103
     */
104 1
    public function getChannel()
105
    {
106 1
        return $this->channel;
107
    }
108
109
    /**
110
     * @param string $text Actual message to send.
111
     *
112
     * @see https://api.slack.com/docs/formatting for an explanation of formatting.
113
     */
114 1
    public function setText($text)
115
    {
116 1
        $this->text = $text;
117 1
    }
118
119
    /**
120
     * @return string Actual message to send.
121
     */
122 1
    public function getText()
123
    {
124 1
        return $this->text;
125
    }
126
127
    /**
128
     * @param string $message
129
     *
130
     * @deprecated Will be removed soon, use `setText()` instead
131
     */
132
    public function setMessage($message)
133
    {
134
        $this->setText($message);
135
    }
136
137
    /**
138
     * @return string
139
     *
140
     * @deprecated Will be removed soon, use `getText()` instead
141
     */
142
    public function getMessage()
143
    {
144
        return $this->getText();
145
    }
146
147
    /**
148
     * @param string $username Name of bot that will send the message (can be any name you want).
149
     */
150 1
    public function setUsername($username)
151
    {
152 1
        $this->username = $username;
153 1
    }
154
155
    /**
156
     * @return string Name of the bot that will send the message.
157
     */
158 1
    public function getUsername()
159
    {
160 1
        return $this->username;
161
    }
162
163
    /**
164
     * @param bool $asUser Pass message as authorized user
165
     */
166 1
    public function setAsUser($asUser)
167
    {
168 1
        $this->asUser = $asUser;
169 1
    }
170
171
    /**
172
     * @return bool Returns true if message will be sent as authorized user
173
     */
174 1
    public function getAsUser()
175
    {
176 1
        return $this->asUser;
177
    }
178
179
    /**
180
     * @param string $parse Change how messages are treated.
181
     *
182
     * @see https://api.slack.com/docs/formatting
183
     */
184 1
    public function setParse($parse)
185
    {
186 1
        $this->parse = $parse;
187 1
    }
188
189
    /**
190
     * @return string Change how messages are treated.
191
     */
192 1
    public function getParse()
193
    {
194 1
        return $this->parse;
195
    }
196
197
    /**
198
     * Sets the emoji to use as the icon for this message (overrides icon URL).
199
     *
200
     * You can use one of Slack's emoji's or upload your own.
201
     *
202
     * @see https://{YOURSLACKTEAMHERE}.slack.com/customize/emoji
203
     *
204
     * @param string|null $iconEmoji Emoji to use as the icon for this message (overrides icon URL).
205
     */
206 1
    public function setIconEmoji($iconEmoji)
207
    {
208 1
        if (substr($iconEmoji, 0, 1) !== ':') {
209
            $iconEmoji = sprintf(':%s:', $iconEmoji);
210
        }
211
212 1
        $this->iconEmoji = $iconEmoji;
213 1
    }
214
215
    /**
216
     * @return string|null Emoji to use as the icon for this message.
217
     */
218 1
    public function getIconEmoji()
219
    {
220 1
        return $this->iconEmoji;
221
    }
222
223
    /**
224
     * @param string|null $iconUrl URL to an image to use as the icon for this message.
225
     */
226 1
    public function setIconUrl($iconUrl)
227
    {
228 1
        $this->iconUrl = $iconUrl;
229 1
    }
230
231
    /**
232
     * @return string|null URL to an image to use as the icon for this message.
233
     */
234 1
    public function getIconUrl()
235
    {
236 1
        return $this->iconUrl;
237
    }
238
239
    /**
240
     * By default links to media are unfurled, but links to text content are not.
241
     * For more information on the differences and how to control this, see the the unfurling documentation.
242
     *
243
     * @see https://api.slack.com/docs/unfurling
244
     *
245
     * @param bool $unfurlLinks Pass true to enable unfurling of primarily text-based content.
246
     */
247 1
    public function setUnfurlLinks($unfurlLinks)
248
    {
249 1
        $this->unfurlLinks = $unfurlLinks;
250 1
    }
251
252
    /**
253
     * @return bool|null
254
     */
255 1
    public function getUnfurlLinks()
256
    {
257 1
        return $this->unfurlLinks;
258
    }
259
260
    /**
261
     * @see https://api.slack.com/docs/unfurling
262
     *
263
     * @param bool $unfurlMedia Pass false to disable unfurling of media content.
264
     */
265 1
    public function setUnfurlMedia($unfurlMedia)
266
    {
267 1
        $this->unfurlMedia = $unfurlMedia;
268 1
    }
269
270
    /**
271
     * @return bool|null
272
     */
273 1
    public function getUnfurlMedia()
274
    {
275 1
        return $this->unfurlMedia;
276
    }
277
278
    /**
279
     * @param bool $linkNames Set to true to automatically find and link channel names and usernames in the message.
280
     */
281 1
    public function setLinkNames($linkNames)
282
    {
283 1
        $this->linkNames = $linkNames;
284 1
    }
285
286
    /**
287
     * @see https://api.slack.com/docs/unfurling
288
     *
289
     * @return bool|null Whether channel names and usernames in the message should be linked automatically.
290
     */
291 1
    public function getLinkNames()
292
    {
293 1
        return $this->linkNames;
294
    }
295
296
    /**
297
     * @return Attachment[]|ArrayCollection
298
     */
299 1
    public function getAttachments()
300
    {
301 1
        return $this->attachments;
302
    }
303
304
    /**
305
     * @param Attachment $attachment
306
     */
307 1
    public function addAttachment(Attachment $attachment)
308
    {
309 1
        $this->attachments->add($attachment);
310 1
    }
311
312
    /**
313
     * Use for serialization.
314
     *
315
     * @return string
316
     */
317 1
    public function getAttachmentsJson()
318
    {
319 1
        return $this->attachmentsJson;
320
    }
321
322
    /**
323
     * {@inheritdoc}
324
     */
325 1
    public function getMethod()
326
    {
327 1
        return 'chat.postMessage';
328
    }
329
330
    /**
331
     * {@inheritdoc}
332
     */
333 1
    public function beforeSerialize(Serializer $serializer)
334
    {
335 1
        $this->attachmentsJson = $serializer->serialize($this->attachments, 'json');
336 1
    }
337
}
338