Passed
Push — master ( ae08b1...91bc2f )
by Alexey
04:51
created

SlackMessage::setIconUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * This file is part of the WoW-Apps/Symfony-Slack-Bot bundle for Symfony 3
4
 * https://github.com/wow-apps/symfony-slack-bot
5
 *
6
 * (c) 2016 WoW-Apps
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WowApps\SlackBundle\DTO;
13
14
use WowApps\SlackBundle\Traits\SlackMessageTrait;
15
16
/**
17
 * @author Alexey Samara <[email protected]>
18
 * @package WowApps\SlackBundle
19
 * @see https://github.com/wow-apps/symfony-slack-bot/wiki/2.-Using-SlackBot#fill-dto
20
 */
21
class SlackMessage
22
{
23
    use SlackMessageTrait;
24
25
    /**
26
     * This property will be removed in version 3.3
27
     *
28
     * @deprecated
29
     * @var string
30
     */
31
    private $icon;
32
33
    /** @var string */
34
    private $iconUrl;
35
36
    /** @var string */
37
    private $iconEmoji;
38
39
    /** @var string */
40
    private $text;
41
42
    /** @var int */
43
    private $quoteType;
44
45
    /** @var string */
46
    private $quoteTitle;
47
48
    /** @var string */
49
    private $quoteTitleLink;
50
51
    /** @var string */
52
    private $quoteText;
53
54
    /** @var bool */
55
    private $showQuote;
56
57
    /** @var string */
58
    private $recipient;
59
60
    /** @var string */
61
    private $sender;
62
63
    /**
64
     * @param string $icon
65
     * @param string $text
66
     * @param int $quoteType
67
     * @param string $quoteTitle
68
     * @param string $quoteTitleLink
69
     * @param string $quoteText
70
     * @param bool $showQuote
71
     * @param string $recipient
72
     * @param string $sender
73
     */
74 24
    public function __construct(
75
        string  $icon = '',
76
        string  $text = '',
77
        int     $quoteType = 0,
78
        string  $quoteTitle = '',
79
        string  $quoteTitleLink = '',
80
        string  $quoteText = '',
81
        bool    $showQuote = false,
82
        string  $recipient = '',
83
        string  $sender = ''
84
    ) {
85
        $this
0 ignored issues
show
Deprecated Code introduced by
The method WowApps\SlackBundle\DTO\SlackMessage::setIcon() has been deprecated.

This method has been deprecated.

Loading history...
86 24
            ->setIcon($icon)
87 24
            ->setText($text)
88 24
            ->setQuoteType($quoteType)
89 24
            ->setQuoteTitle($quoteTitle)
90 24
            ->setQuoteTitleLink($quoteTitleLink)
91 24
            ->setQuoteText($quoteText)
92 24
            ->setShowQuote($showQuote)
93 24
            ->setRecipient($recipient)
94 24
            ->setSender($sender)
95
        ;
96 24
    }
97
98
    /**
99
     * This method will be removed in version 3.3
100
     *
101
     * @deprecated
102
     * @return string
103
     */
104 1
    public function getIcon(): string
105
    {
106
        // TODO: this dirty hack will be removed in version 3.3
107 1
        if (!empty($this->getIconUrl())) {
108 1
            return $this->getIconUrl();
109
        }
110
111
        if (!empty($this->getIconEmoji())) {
112
            return $this->getIconEmoji();
113
        }
114
115
        return '';
116
    }
117
118
    /**
119
     * This method will be removed in version 3.3
120
     *
121
     * @deprecated
122
     * @param string $icon
123
     * @return SlackMessage
124
     */
125 24
    public function setIcon(string $icon): SlackMessage
126
    {
127
        // TODO: this dirty hack will be removed in version 3.3
128 24
        if (preg_match('/^\:(.*?)\:$/i', $icon)) {
129
            $this->setIconEmoji($icon);
130
            return $this;
131
        }
132
133 24
        $this->setIconUrl($icon);
134 24
        return $this;
135
    }
136
137
    /**
138
     * @return string
139
     */
140 4
    public function getIconUrl(): string
141
    {
142 4
        return $this->iconUrl;
143
    }
144
145
    /**
146
     * @param string $iconUrl
147
     * @return SlackMessage
148
     */
149 24
    public function setIconUrl(string $iconUrl): SlackMessage
150
    {
151 24
        $this->iconUrl = $iconUrl;
152 24
        return $this;
153
    }
154
155
    /**
156
     * @return string
157
     */
158 3
    public function getIconEmoji(): string
159
    {
160 3
        return $this->iconEmoji;
161
    }
162
163
    /**
164
     * @param string $iconEmoji
165
     * @return SlackMessage
166
     */
167 23
    public function setIconEmoji(string $iconEmoji): SlackMessage
168
    {
169 23
        $this->iconEmoji = $iconEmoji;
170 23
        return $this;
171
    }
172
173
    /**
174
     * @return string
175
     */
176 3
    public function getText(): string
177
    {
178 3
        return $this->text;
179
    }
180
181
    /**
182
     * @param string $text
183
     * @return SlackMessage
184
     */
185 24
    public function setText(string $text): SlackMessage
186
    {
187 24
        $this->text = $this->escapeCharacters($text);
188 24
        return $this;
189
    }
190
191
    /**
192
     * @return int
193
     */
194 2
    public function getQuoteType(): int
195
    {
196 2
        return $this->quoteType;
197
    }
198
199
    /**
200
     * @param int $quoteType
201
     * @return SlackMessage
202
     */
203 24
    public function setQuoteType(int $quoteType): SlackMessage
204
    {
205 24
        $this->quoteType = $quoteType;
206 24
        return $this;
207
    }
208
209
    /**
210
     * @return string
211
     */
212 2
    public function getQuoteTitle(): string
213
    {
214 2
        return $this->quoteTitle;
215
    }
216
217
    /**
218
     * @param string $quoteTitle
219
     * @return SlackMessage
220
     */
221 24
    public function setQuoteTitle(string $quoteTitle): SlackMessage
222
    {
223 24
        $this->quoteTitle = $this->escapeCharacters($quoteTitle);
224 24
        return $this;
225
    }
226
227
    /**
228
     * @return string
229
     */
230 2
    public function getQuoteTitleLink(): string
231
    {
232 2
        return $this->quoteTitleLink;
233
    }
234
235
    /**
236
     * @param string $quoteTitleLink
237
     * @return SlackMessage
238
     */
239 24
    public function setQuoteTitleLink(string $quoteTitleLink): SlackMessage
240
    {
241 24
        $this->quoteTitleLink = $this->escapeCharacters($quoteTitleLink);
242 24
        return $this;
243
    }
244
245
    /**
246
     * @return string
247
     */
248 2
    public function getQuoteText(): string
249
    {
250 2
        return $this->quoteText;
251
    }
252
253
    /**
254
     * @param string $quoteText
255
     * @return SlackMessage
256
     */
257 24
    public function setQuoteText(string $quoteText): SlackMessage
258
    {
259 24
        $this->quoteText = $this->escapeCharacters($quoteText);
260 24
        return $this;
261
    }
262
263
    /**
264
     * @return bool
265
     */
266 2
    public function isShowQuote(): bool
267
    {
268 2
        return $this->showQuote;
269
    }
270
271
    /**
272
     * @param bool $showQuote
273
     * @return SlackMessage
274
     */
275 24
    public function setShowQuote(bool $showQuote): SlackMessage
276
    {
277 24
        $this->showQuote = $showQuote;
278 24
        return $this;
279
    }
280
281
    /**
282
     * @return string
283
     */
284 2
    public function getRecipient(): string
285
    {
286 2
        return $this->recipient;
287
    }
288
289
    /**
290
     * @param string $recipient
291
     * @return SlackMessage
292
     */
293 24
    public function setRecipient(string $recipient): SlackMessage
294
    {
295 24
        $this->recipient = $this->escapeCharacters($recipient);
296 24
        return $this;
297
    }
298
299
    /**
300
     * @return string
301
     */
302 2
    public function getSender(): string
303
    {
304 2
        return $this->sender;
305
    }
306
307
    /**
308
     * @param string $sender
309
     * @return SlackMessage
310
     */
311 24
    public function setSender(string $sender): SlackMessage
312
    {
313 24
        $this->sender = $this->escapeCharacters($sender);
314 24
        return $this;
315
    }
316
}
317