Message   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 94
ccs 25
cts 25
cp 1
rs 10
c 0
b 0
f 0
wmc 11
lcom 1
cbo 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 4
A getText() 0 4 1
A setText() 0 4 1
A getIconEmoji() 0 4 1
A setIconEmoji() 0 4 1
A getAttachments() 0 4 1
A setAttachments() 0 4 1
A addAttachment() 0 4 1
1
<?php
2
/**
3
 * T3Bot.
4
 *
5
 * @author Frank Nägler <[email protected]>
6
 *
7
 * @link http://www.t3bot.de
8
 * @link http://wiki.typo3.org/T3Bot
9
 */
10
namespace T3Bot\Slack;
11
12
use T3Bot\Slack\Message\Attachment;
13
14
/**
15
 * Class Message.
16
 */
17
class Message
18
{
19
    /**
20
     * The text so be send.
21
     *
22
     * @var string
23
     */
24
    protected $text;
25
26
    /**
27
     * The URL for the avatar image.
28
     *
29
     * @var string
30
     */
31
    protected $icon_emoji = '';
32
33
    /**
34
     * @var array<T3Bot\Slack\Message\Attachment>
35
     */
36
    protected $attachments = [];
37
38
    /**
39
     * Constructor for a message.
40
     *
41
     * @param array $data
42
     */
43 28
    public function __construct(array $data = [])
44
    {
45 28
        foreach ($data as $property => $value) {
46 1
            if (property_exists($this, $property)) {
47 1
                $this->$property = $value;
48
            }
49
        }
50 28
        if ($this->icon_emoji === '') {
51 27
            $this->icon_emoji = $GLOBALS['config']['slack']['botAvatar'];
52
        }
53 28
    }
54
55
    /**
56
     * @return string
57
     */
58 5
    public function getText() : string
59
    {
60 5
        return $this->text;
61
    }
62
63
    /**
64
     * @param string $text
65
     */
66 28
    public function setText($text)
67
    {
68 28
        $this->text = $text;
69 28
    }
70
71
    /**
72
     * @return string
73
     */
74 1
    public function getIconEmoji() : string
75
    {
76 1
        return $this->icon_emoji;
77
    }
78
79
    /**
80
     * @param string $icon_emoji
81
     */
82 1
    public function setIconEmoji($icon_emoji)
83
    {
84 1
        $this->icon_emoji = $icon_emoji;
85 1
    }
86
87
    /**
88
     * @return array
89
     */
90 15
    public function getAttachments() : array
91
    {
92 15
        return $this->attachments;
93
    }
94
95
    /**
96
     * @param array $attachments
97
     */
98 1
    public function setAttachments($attachments)
99
    {
100 1
        $this->attachments = $attachments;
101 1
    }
102
103
    /**
104
     * @param Attachment $attachment
105
     */
106 27
    public function addAttachment(Attachment $attachment)
107
    {
108 27
        $this->attachments[] = $attachment;
109 27
    }
110
}
111