SlackMessage   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 1

Test Coverage

Coverage 60%

Importance

Changes 0
Metric Value
dl 0
loc 90
c 0
b 0
f 0
wmc 7
lcom 3
cbo 1
ccs 12
cts 20
cp 0.6
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A success() 0 6 1
A error() 0 6 1
A content() 0 6 1
A attachment() 0 8 1
A color() 0 9 3
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