Completed
Push — master ( 6b7dcc...b3fe52 )
by Alexey
11:45
created

SlackMessage::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 9.0856
c 0
b 0
f 0
cc 1
eloc 20
nc 1
nop 9

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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
 * Class SlackMessage
18
 *
19
 * @author Alexey Samara <[email protected]>
20
 * @package WowApps\SlackBundle
21
 */
22
class SlackMessage
23
{
24
    use SlackMessageTrait;
25
26
    /** @var string */
27
    private $icon;
28
29
    /** @var string */
30
    private $text;
31
32
    /** @var int */
33
    private $quoteType;
34
35
    /** @var string */
36
    private $quoteTitle;
37
38
    /** @var string */
39
    private $quoteTitleLink;
40
41
    /** @var string */
42
    private $quoteText;
43
44
    /** @var bool */
45
    private $showQuote;
46
47
    /** @var string */
48
    private $recipient;
49
50
    /** @var string */
51
    private $sender;
52
53
    /**
54
     * SlackMessage constructor.
55
     * @param string $icon
56
     * @param string $text
57
     * @param int $quoteType
58
     * @param string $quoteTitle
59
     * @param string $quoteTitleLink
60
     * @param string $quoteText
61
     * @param bool $showQuote
62
     * @param string $recipient
63
     * @param string $sender
64
     */
65
    public function __construct(
66
        string  $icon = '',
67
        string  $text = '',
68
        int     $quoteType = 0,
69
        string  $quoteTitle = '',
70
        string  $quoteTitleLink = '',
71
        string  $quoteText = '',
72
        bool    $showQuote = false,
73
        string  $recipient = '',
74
        string  $sender = ''
75
    ) {
76
        $this
77
            ->setIcon($icon)
78
            ->setText($text)
79
            ->setQuoteType($quoteType)
80
            ->setQuoteTitle($quoteTitle)
81
            ->setQuoteTitleLink($quoteTitleLink)
82
            ->setQuoteText($quoteText)
83
            ->setShowQuote($showQuote)
84
            ->setRecipient($recipient)
85
            ->setSender($sender)
86
        ;
87
    }
88
89
    /**
90
     * @return string
91
     */
92
    public function getIcon(): string
93
    {
94
        return $this->icon;
95
    }
96
97
    /**
98
     * @param string $icon
99
     * @return SlackMessage
100
     */
101
    public function setIcon(string $icon)
102
    {
103
        $this->icon = $icon;
104
        return $this;
105
    }
106
107
    /**
108
     * @return string
109
     */
110
    public function getText(): string
111
    {
112
        return $this->text;
113
    }
114
115
    /**
116
     * @param string $text
117
     * @return SlackMessage
118
     */
119
    public function setText(string $text)
120
    {
121
        $this->text = $this->escapeCharacters($text);
122
        return $this;
123
    }
124
125
    /**
126
     * @return int
127
     */
128
    public function getQuoteType(): int
129
    {
130
        return $this->quoteType;
131
    }
132
133
    /**
134
     * @param int $quoteType
135
     * @return SlackMessage
136
     */
137
    public function setQuoteType(int $quoteType)
138
    {
139
        $this->quoteType = $quoteType;
140
        return $this;
141
    }
142
143
    /**
144
     * @return string
145
     */
146
    public function getQuoteTitle(): string
147
    {
148
        return $this->quoteTitle;
149
    }
150
151
    /**
152
     * @param string $quoteTitle
153
     * @return SlackMessage
154
     */
155
    public function setQuoteTitle(string $quoteTitle)
156
    {
157
        $this->quoteTitle = $this->escapeCharacters($quoteTitle);
158
        return $this;
159
    }
160
161
    /**
162
     * @return string
163
     */
164
    public function getQuoteTitleLink(): string
165
    {
166
        return $this->quoteTitleLink;
167
    }
168
169
    /**
170
     * @param string $quoteTitleLink
171
     * @return SlackMessage
172
     */
173
    public function setQuoteTitleLink(string $quoteTitleLink)
174
    {
175
        $this->quoteTitleLink = $this->escapeCharacters($quoteTitleLink);
176
        return $this;
177
    }
178
179
    /**
180
     * @return string
181
     */
182
    public function getQuoteText(): string
183
    {
184
        return $this->quoteText;
185
    }
186
187
    /**
188
     * @param string $quoteText
189
     * @return SlackMessage
190
     */
191
    public function setQuoteText(string $quoteText)
192
    {
193
        $this->quoteText = $this->escapeCharacters($quoteText);
194
        return $this;
195
    }
196
197
    /**
198
     * @return bool
199
     */
200
    public function isShowQuote(): bool
201
    {
202
        return $this->showQuote;
203
    }
204
205
    /**
206
     * @param bool $showQuote
207
     * @return SlackMessage
208
     */
209
    public function setShowQuote(bool $showQuote)
210
    {
211
        $this->showQuote = $showQuote;
212
        return $this;
213
    }
214
215
    /**
216
     * @return string
217
     */
218
    public function getRecipient(): string
219
    {
220
        return $this->recipient;
221
    }
222
223
    /**
224
     * @param string $recipient
225
     * @return SlackMessage
226
     */
227
    public function setRecipient(string $recipient)
228
    {
229
        $this->recipient = $this->escapeCharacters($recipient);
230
        return $this;
231
    }
232
233
    /**
234
     * @return string
235
     */
236
    public function getSender(): string
237
    {
238
        return $this->sender;
239
    }
240
241
    /**
242
     * @param string $sender
243
     * @return SlackMessage
244
     */
245
    public function setSender(string $sender)
246
    {
247
        $this->sender = $this->escapeCharacters($sender);
248
        return $this;
249
    }
250
}
251