SlackMessage::success()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
ccs 0
cts 3
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Illuminate\Notifications\Messages;
4
5
use Closure;
6
7
class SlackMessage
8
{
9
    /**
10
     * The "level" of the notification (info, success, error).
11
     *
12
     * @var string
13
     */
14
    public $level = 'info';
15
16
    /**
17
     * The text content of the message.
18
     *
19
     * @var string
20
     */
21
    public $content;
22
23
    /**
24
     * The message's attachments.
25
     *
26
     * @var array
27
     */
28
    public $attachments = [];
29
30
    /**
31
     * Indicate that the notification gives information about a successful operation.
32
     *
33
     * @return $this
34
     */
35
    public function success()
36
    {
37
        $this->level = 'success';
38
39
        return $this;
40
    }
41
42
    /**
43
     * Indicate that the notification gives information about an error.
44
     *
45
     * @return $this
46
     */
47
    public function error()
48
    {
49
        $this->level = 'error';
50
51
        return $this;
52
    }
53
54
    /**
55
     * Set the content of the Slack message.
56
     *
57
     * @param  string  $content
58
     * @return $this
59
     */
60 1
    public function content($content)
61
    {
62 1
        $this->content = $content;
63
64 1
        return $this;
65
    }
66
67
    /**
68
     * Define an attachment for the message.
69
     *
70
     * @param  \Closure  $callback
71
     * @return $this
72
     */
73 1
    public function attachment(Closure $callback)
74
    {
75 1
        $this->attachments[] = $attachment = new SlackAttachment;
76
77 1
        $callback($attachment);
78
79 1
        return $this;
80
    }
81
82
    /**
83
     * Get the color for the message.
84
     *
85
     * @return string
86
     */
87 1
    public function color()
88
    {
89 1
        switch ($this->level) {
90 1
            case 'success':
91
                return '#7CD197';
92 1
            case 'error':
93
                return '#F35A00';
94
        }
95 1
    }
96
}
97