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 (#51)
by
unknown
03:37 queued 01:27
created

Attachment::setTs()   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 Attachment
8
{
9
    /**
10
     * The fallback text to use for clients that don't support attachments.
11
     *
12
     * @var string
13
     */
14
    protected $fallback;
15
16
    /**
17
     * Optional text that should appear within the attachment.
18
     *
19
     * @var string
20
     */
21
    protected $text;
22
23
    /**
24
     * Optional image that should appear within the attachment.
25
     *
26
     * @var string
27
     */
28
    protected $image_url;
29
30
    /**
31
     * Optional thumbnail that should appear within the attachment.
32
     *
33
     * @var string
34
     */
35
    protected $thumb_url;
36
37
    /**
38
     * Optional text that should appear above the formatted data.
39
     *
40
     * @var string
41
     */
42
    protected $pretext;
43
44
    /**
45
     * Optional title for the attachment.
46
     *
47
     * @var string
48
     */
49
    protected $title;
50
51
    /**
52
     * Optional title link for the attachment.
53
     *
54
     * @var string
55
     */
56
    protected $title_link;
57
58
    /**
59
     * Optional author name for the attachment.
60
     *
61
     * @var string
62
     */
63
    protected $author_name;
64
65
    /**
66
     * Optional author link for the attachment.
67
     *
68
     * @var string
69
     */
70
    protected $author_link;
71
72
    /**
73
     * Optional author icon for the attachment.
74
     *
75
     * @var string
76
     */
77
    protected $author_icon;
78
79
    /**
80
     * The color to use for the attachment.
81
     *
82
     * @var string
83
     */
84
    protected $color = 'good';
85
86
    /**
87
     * The fields of the attachment.
88
     *
89
     * @var array
90
     */
91
    protected $fields = [];
92
93
    /**
94
     * The fields of the attachment that Slack should interpret
95
     * with its Markdown-like language.
96
     *
97
     * @var array
98
     */
99
    protected $markdown_fields = [];
100
101
    /**
102
     * The text to use for the footer attachment.
103
     *
104
     * @var string
105
     */
106
    protected $footer;
107
108
    /**
109
     * The icon to use for the footer attachment.
110
     *
111
     * @var string
112
     */
113
    protected $footer_icon;
114
115
    /**
116
     * The timestamp to use for the footer attachment.
117
     *
118
     * @var int
119
     */
120
    protected $ts;
121
122
    /**
123
     * Instantiate a new Attachment.
124
     *
125
     * @param array $attributes
126
     * @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...
127
     */
128
    public function __construct(array $attributes)
129
    {
130
        if (isset($attributes['fallback'])) {
131
            $this->setFallback($attributes['fallback']);
132
        }
133
134
        if (isset($attributes['text'])) {
135
            $this->setText($attributes['text']);
136
        }
137
138
        if (isset($attributes['image_url'])) {
139
            $this->setImageUrl($attributes['image_url']);
140
        }
141
142
        if (isset($attributes['thumb_url'])) {
143
            $this->setThumbUrl($attributes['thumb_url']);
144
        }
145
146
        if (isset($attributes['pretext'])) {
147
            $this->setPretext($attributes['pretext']);
148
        }
149
150
        if (isset($attributes['color'])) {
151
            $this->setColor($attributes['color']);
152
        }
153
        
154
        if (isset($attributes['footer'])) {
155
            $this->setFooter($attributes['footer']);
156
        }
157
        
158
        if (isset($attributes['footer_icon'])) {
159
            $this->setFooterIcon($attributes['footer_icon']);
160
        }
161
        
162
        if (isset($attributes['ts'])) {
163
            $this->setTs($attributes['ts']);
164
        }
165
166
        if (isset($attributes['fields'])) {
167
            $this->setFields($attributes['fields']);
168
        }
169
170
        if (isset($attributes['mrkdwn_in'])) {
171
            $this->setMarkdownFields($attributes['mrkdwn_in']);
172
        }
173
174
        if (isset($attributes['title'])) {
175
            $this->setTitle($attributes['title']);
176
        }
177
178
        if (isset($attributes['title_link'])) {
179
            $this->setTitleLink($attributes['title_link']);
180
        }
181
182
        if (isset($attributes['author_name'])) {
183
            $this->setAuthorName($attributes['author_name']);
184
        }
185
186
        if (isset($attributes['author_link'])) {
187
            $this->setAuthorLink($attributes['author_link']);
188
        }
189
190
        if (isset($attributes['author_icon'])) {
191
            $this->setAuthorIcon($attributes['author_icon']);
192
        }
193
    }
194
195
    /**
196
     * Get the fallback text.
197
     *
198
     * @return string
199
     */
200
    public function getFallback()
201
    {
202
        return $this->fallback;
203
    }
204
205
    /**
206
     * Set the fallback text.
207
     *
208
     * @param string $fallback
209
     * @return $this
210
     */
211
    public function setFallback($fallback)
212
    {
213
        $this->fallback = $fallback;
214
215
        return $this;
216
    }
217
218
    /**
219
     * Get the optional text to appear within the attachment.
220
     *
221
     * @return string
222
     */
223
    public function getText()
224
    {
225
        return $this->text;
226
    }
227
228
    /**
229
     * Set the optional text to appear within the attachment.
230
     *
231
     * @param string $text
232
     * @return $this
233
     */
234
    public function setText($text)
235
    {
236
        $this->text = $text;
237
238
        return $this;
239
    }
240
241
    /**
242
     * Get the optional image to appear within the attachment.
243
     *
244
     * @return string
245
     */
246
    public function getImageUrl()
247
    {
248
        return $this->image_url;
249
    }
250
251
    /**
252
     * Set the optional image to appear within the attachment.
253
     *
254
     * @param string $image_url
255
     * @return $this
256
     */
257
    public function setImageUrl($image_url)
258
    {
259
        $this->image_url = $image_url;
260
261
        return $this;
262
    }
263
264
    /**
265
     * Get the optional thumbnail to appear within the attachment.
266
     *
267
     * @return string
268
     */
269
    public function getThumbUrl()
270
    {
271
        return $this->thumb_url;
272
    }
273
274
    /**
275
     * Set the optional thumbnail to appear within the attachment.
276
     *
277
     * @param string $thumb_url
278
     * @return $this
279
     */
280
    public function setThumbUrl($thumb_url)
281
    {
282
        $this->thumb_url = $thumb_url;
283
284
        return $this;
285
    }
286
287
    /**
288
     * Get the text that should appear above the formatted data.
289
     *
290
     * @return string
291
     */
292
    public function getPretext()
293
    {
294
        return $this->pretext;
295
    }
296
297
    /**
298
     * Set the text that should appear above the formatted data.
299
     *
300
     * @param string $pretext
301
     * @return $this
302
     */
303
    public function setPretext($pretext)
304
    {
305
        $this->pretext = $pretext;
306
307
        return $this;
308
    }
309
310
    /**
311
     * Get the color to use for the attachment.
312
     *
313
     * @return string
314
     */
315
    public function getColor()
316
    {
317
        return $this->color;
318
    }
319
320
    /**
321
     * Set the color to use for the attachment.
322
     *
323
     * @param string $colour
0 ignored issues
show
Documentation introduced by
There is no parameter named $colour. Did you maybe mean $color?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
324
     * @return void
325
     */
326
    public function setColor($color)
327
    {
328
        $this->color = $color;
329
330
        return $this;
331
    }
332
333
    /**
334
     * Get the footer to use for the attachment.
335
     *
336
     * @return string
337
     */
338
    public function getFooter()
339
    {
340
        return $this->footer;
341
    }
342
343
    /**
344
     * Set the footer text to use for the attachment.
345
     *
346
     * @param string $footer
347
     * @return void
348
     */
349
    public function setFooter($footer)
350
    {
351
        $this->footer = $footer;
352
353
        return $this;
354
    }
355
356
    /**
357
     * Get the footer icon to use for the attachment.
358
     *
359
     * @return string
360
     */
361
    public function getFooterIcon()
362
    {
363
        return $this->footer_icon;
364
    }
365
366
    /**
367
     * Set the footer icon to use for the attachment.
368
     *
369
     * @param string $footerIcon
370
     * @return void
371
     */
372
    public function setFooterIcon($footerIcon)
373
    {
374
        $this->footer_icon = $footerIcon;
375
376
        return $this;
377
    }
378
379
    /**
380
     * Get the timestamp to use for the attachment.
381
     *
382
     * @return integer
383
     */
384
    public function getTs()
385
    {
386
        return $this->ts;
387
    }
388
389
    /**
390
     * Set the timestamp to use for the attachment.
391
     *
392
     * @param int $ts
393
     * @return void
394
     */
395
    public function setTs($ts)
396
    {
397
        $this->ts = $ts;
398
399
        return $this;
400
    }
401
402
    /**
403
     * Get the title to use for the attachment.
404
     *
405
     * @return string
406
     */
407
    public function getTitle()
408
    {
409
        return $this->title;
410
    }
411
412
    /**
413
     * Set the title to use for the attachment.
414
     *
415
     * @param string $title
416
     * @return void
417
     */
418
    public function setTitle($title)
419
    {
420
        $this->title = $title;
421
422
        return $this;
423
    }
424
425
    /**
426
     * Get the title link to use for the attachment.
427
     *
428
     * @return string
429
     */
430
    public function getTitleLink()
431
    {
432
        return $this->title_link;
433
    }
434
435
    /**
436
     * Set the title link to use for the attachment.
437
     *
438
     * @param string $title_link
439
     * @return void
440
     */
441
    public function setTitleLink($title_link)
442
    {
443
        $this->title_link = $title_link;
444
445
        return $this;
446
    }
447
448
    /**
449
     * Get the author name to use for the attachment.
450
     *
451
     * @return string
452
     */
453
    public function getAuthorName()
454
    {
455
        return $this->author_name;
456
    }
457
458
    /**
459
     * Set the author name to use for the attachment.
460
     *
461
     * @param string $author_name
462
     * @return void
463
     */
464
    public function setAuthorName($author_name)
465
    {
466
        $this->author_name = $author_name;
467
468
        return $this;
469
    }
470
471
    /**
472
     * Get the author link to use for the attachment.
473
     *
474
     * @return string
475
     */
476
    public function getAuthorLink()
477
    {
478
        return $this->author_link;
479
    }
480
481
    /**
482
     * Set the auhtor link to use for the attachment.
483
     *
484
     * @param string $author_link
485
     * @return void
486
     */
487
    public function setAuthorLink($author_link)
488
    {
489
        $this->author_link = $author_link;
490
491
        return $this;
492
    }
493
494
    /**
495
     * Get the author icon to use for the attachment.
496
     *
497
     * @return string
498
     */
499
    public function getAuthorIcon()
500
    {
501
        return $this->author_icon;
502
    }
503
504
    /**
505
     * Set the author icon to use for the attachment.
506
     *
507
     * @param string $author_icon
508
     * @return void
509
     */
510
    public function setAuthorIcon($author_icon)
511
    {
512
        $this->author_icon = $author_icon;
513
514
        return $this;
515
    }
516
517
    /**
518
     * Get the fields for the attachment.
519
     *
520
     * @return array
521
     */
522
    public function getFields()
523
    {
524
        return $this->fields;
525
    }
526
527
    /**
528
     * Set the fields for the attachment.
529
     *
530
     * @param array $fields
531
     * @return void
532
     */
533
    public function setFields(array $fields)
534
    {
535
        $this->clearFields();
536
537
        foreach ($fields as $field) {
538
            $this->addField($field);
539
        }
540
541
        return $this;
542
    }
543
544
    /**
545
     * Add a field to the attachment.
546
     *
547
     * @param mixed $field
548
     * @return $this
549
     */
550
    public function addField($field)
551
    {
552
        if ($field instanceof AttachmentField) {
553
            $this->fields[] = $field;
554
555
            return $this;
556
        } elseif (is_array($field)) {
557
            $this->fields[] = new AttachmentField($field);
558
559
            return $this;
560
        }
561
562
        throw new InvalidArgumentException('The attachment field must be an instance of Maknz\Slack\AttachmentField or a keyed array');
563
    }
564
565
    /**
566
     * Clear the fields for the attachment.
567
     *
568
     * @return $this
569
     */
570
    public function clearFields()
571
    {
572
        $this->fields = [];
573
574
        return $this;
575
    }
576
577
    /**
578
     * Get the fields Slack should interpret in its
579
     * Markdown-like language.
580
     *
581
     * @return array
582
     */
583
    public function getMarkdownFields()
584
    {
585
        return $this->markdown_fields;
586
    }
587
588
    /**
589
     * Set the fields Slack should interpret in its
590
     * Markdown-like language.
591
     *
592
     * @param array $fields
593
     * @return $this
594
     */
595
    public function setMarkdownFields(array $fields)
596
    {
597
        $this->markdown_fields = $fields;
598
599
        return $this;
600
    }
601
602
    /**
603
     * Convert this attachment to its array representation.
604
     *
605
     * @return array
606
     */
607
    public function toArray()
608
    {
609
        $data = [
610
            'fallback' => $this->getFallback(),
611
            'text' => $this->getText(),
612
            'pretext' => $this->getPretext(),
613
            'color' => $this->getColor(),
614
            'mrkdwn_in' => $this->getMarkdownFields(),
615
            'image_url' => $this->getImageUrl(),
616
            'thumb_url' => $this->getThumbUrl(),
617
            'title' => $this->getTitle(),
618
            'title_link' => $this->getTitleLink(),
619
            'author_name' => $this->getAuthorName(),
620
            'author_link' => $this->getAuthorLink(),
621
            'author_icon' => $this->getAuthorIcon(),
622
        ];
623
624
        $data['fields'] = $this->getFieldsAsArrays();
625
626
        return $data;
627
    }
628
629
    /**
630
     * Iterates over all fields in this attachment and returns
631
     * them in their array form.
632
     *
633
     * @return array
634
     */
635
    protected function getFieldsAsArrays()
636
    {
637
        $fields = [];
638
639
        foreach ($this->getFields() as $field) {
640
            $fields[] = $field->toArray();
641
        }
642
643
        return $fields;
644
    }
645
}
646