MessageTrait::setUser()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 1
1
<?php
2
namespace PortlandLabs\Slackbot\Slack\Rtm\Event\Message;
3
4
trait MessageTrait
5
{
6
7
    /** @var string */
8
    private $subtype;
9
10
    /** @var string */
11
    private $timestamp;
12
13
    /** @var string */
14
    private $user;
15
16
    /** @var string */
17
    private $channel;
18
19
    /** @var string */
20
    private $message;
21
22
    /**
23
     * Get the subtype of the message
24
     *
25
     * @see https://api.slack.com/events/message for subtypes
26
     *
27
     * @return null|string
28
     */
29
    public function getSubtype(): ?string
30
    {
31
        return $this->subtype;
32
    }
33
34
    /**
35
     * Set the message subtype
36
     *
37
     * @param string $subtype
38
     * @return null|self
39
     */
40
    public function setSubtype(string $subtype): ?Message
41
    {
42
        $this->subtype = $subtype;
43
        return $this->forceInterface();
44
    }
45
46
    /**
47
     * Get the timestamp associated with the message
48
     *
49
     * @return string
50
     */
51
    public function getTimestamp(): string
52
    {
53
        return $this->timestamp;
54
    }
55
56
    /**
57
     * Set the message timestamp
58
     *
59
     * @param string $timestamp
60
     * @return null|self
61
     */
62
    public function setTimestamp(string $timestamp): ?Message
63
    {
64
        $this->timestamp = $timestamp;
65
        return $this->forceInterface();
66
    }
67
68
    /**
69
     * Get the user associated with the message
70
     *
71
     * @return null|string
72
     */
73
    public function getUser(): ?string
74
    {
75
        return $this->user;
76
    }
77
78
    public function setUser(string $user): ?Message
79
    {
80
        $this->user = $user;
81
        return $this->forceInterface();
82
    }
83
84
    /**
85
     * Get the channel associated with the message
86
     *
87
     * @return null|string
88
     */
89
    public function getChannel(): ?string
90
    {
91
        return $this->channel;
92
    }
93
94
    /**
95
     * Set the channel
96
     *
97
     * @param string $channel
98
     * @return null|self
99
     */
100
    public function setChannel(string $channel): ?Message
101
    {
102
        $this->channel = $channel;
103
        return $this->forceInterface();
104
    }
105
106
    /**
107
     * Get the message
108
     *
109
     * @return null|string
110
     */
111
    public function getText(): ?string
112
    {
113
        return $this->message;
114
    }
115
116
    /**
117
     * Set the message
118
     *
119
     * @param string $message
120
     * @return null|self
121
     */
122
    public function setText(string $message): ?Message
123
    {
124
        $this->message = $message;
125
        return $this->forceInterface();
126
    }
127
128
    /**
129
     * Ensure we return a Message interface implementation, otherwise return null
130
     *
131
     * @return null|self
132
     */
133
    private function forceInterface(): ?Message
134
    {
135
        return $this instanceof Message ? $this : null;
136
    }
137
}