1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace NotificationChannels\Zendesk; |
4
|
|
|
|
5
|
|
|
use NotificationChannels\Exception\CouldNotCreateMessage; |
6
|
|
|
|
7
|
|
|
class ZendeskMessage |
8
|
|
|
{ |
9
|
|
|
/** @var string */ |
10
|
|
|
protected $subject; |
11
|
|
|
|
12
|
|
|
/** @var array */ |
13
|
|
|
protected $requester = []; |
14
|
|
|
|
15
|
|
|
/** @var string */ |
16
|
|
|
protected $description = ''; |
17
|
|
|
|
18
|
|
|
/** @var string */ |
19
|
|
|
protected $type; |
20
|
|
|
|
21
|
|
|
/** @var string */ |
22
|
|
|
protected $status = 'new'; |
23
|
|
|
|
24
|
|
|
/** @var array */ |
25
|
|
|
protected $tags = []; |
26
|
|
|
|
27
|
|
|
/** @var string */ |
28
|
|
|
protected $content = ''; |
29
|
|
|
|
30
|
|
|
/** @var string */ |
31
|
|
|
protected $htmlContent = ''; |
32
|
|
|
|
33
|
|
|
/** @var bool */ |
34
|
|
|
protected $isPublic = false; |
35
|
|
|
|
36
|
|
|
/** @var string */ |
37
|
|
|
protected $priority = 'normal'; |
38
|
|
|
|
39
|
|
|
/** @var array */ |
40
|
|
|
protected $customFields = []; |
41
|
|
|
|
42
|
|
|
/** @var int */ |
43
|
|
|
protected $groupId = ''; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param string $subject |
47
|
|
|
* |
48
|
|
|
* @return static |
49
|
|
|
*/ |
50
|
1 |
|
public static function create($subject = '', $description = '') |
51
|
|
|
{ |
52
|
1 |
|
return new static($subject, $description); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param string $subject |
57
|
|
|
*/ |
58
|
6 |
|
public function __construct($subject = '', $description = '') |
59
|
|
|
{ |
60
|
6 |
|
$this->subject = $subject; |
61
|
6 |
|
$this->description = $description; |
62
|
6 |
|
$this->content = $description; |
63
|
6 |
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Set the ticket subject. |
67
|
|
|
* |
68
|
|
|
* @param $subject |
69
|
|
|
* |
70
|
|
|
* @return $this |
71
|
|
|
*/ |
72
|
|
|
public function subject($subject) |
73
|
|
|
{ |
74
|
|
|
$this->subject = $subject; |
75
|
|
|
|
76
|
|
|
return $this; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Set the ticket customer name. |
81
|
|
|
* |
82
|
|
|
* @param string $name |
83
|
|
|
* @param string $email |
84
|
|
|
* |
85
|
|
|
* @return $this |
86
|
|
|
*/ |
87
|
2 |
|
public function from($name, $email) |
88
|
|
|
{ |
89
|
2 |
|
$this->requester = [ |
90
|
2 |
|
'name' => $name, |
91
|
2 |
|
'email' => $email, |
92
|
|
|
]; |
93
|
|
|
|
94
|
2 |
|
return $this; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Set the content message. |
99
|
|
|
* |
100
|
|
|
* @param $content |
101
|
|
|
* |
102
|
|
|
* @return $this |
103
|
|
|
*/ |
104
|
2 |
|
public function content($content) |
105
|
|
|
{ |
106
|
2 |
|
$this->content = $content; |
107
|
|
|
|
108
|
2 |
|
return $this; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Set the HTML content message. |
113
|
|
|
* |
114
|
|
|
* @param string $html |
115
|
|
|
* |
116
|
|
|
* @return $this |
117
|
|
|
*/ |
118
|
|
|
public function htmlContent($html) |
119
|
|
|
{ |
120
|
|
|
$this->htmlContent = $html; |
121
|
|
|
|
122
|
|
|
return $this; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Set the description. |
127
|
|
|
* |
128
|
|
|
* @param string $description |
129
|
|
|
* |
130
|
|
|
* @return $this |
131
|
|
|
*/ |
132
|
2 |
|
public function description($description) |
133
|
|
|
{ |
134
|
2 |
|
$this->description = $description; |
135
|
|
|
|
136
|
2 |
|
return $this; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Set the ticket type. |
141
|
|
|
* Allowed values are problem, incident, question, or task. |
142
|
|
|
* |
143
|
|
|
* @param string $type |
144
|
|
|
* |
145
|
|
|
* @return $this |
146
|
|
|
*/ |
147
|
|
|
public function type($type) |
148
|
|
|
{ |
149
|
|
|
if (! in_array($type, ['problem', 'incident', 'question', 'task'])) { |
150
|
|
|
throw CouldNotCreateMessage::invalidIndent($type); |
151
|
|
|
} |
152
|
|
|
$this->type = $type; |
153
|
|
|
|
154
|
|
|
return $this; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Set the ticket priority. |
159
|
|
|
* Allowed values are urgent, high, normal, or low. |
160
|
|
|
* |
161
|
|
|
* @param string $priority |
162
|
|
|
* |
163
|
|
|
* @return $this |
164
|
|
|
*/ |
165
|
|
|
public function priority($priority) |
166
|
|
|
{ |
167
|
|
|
if (! in_array($priority, ['urgent', 'high', 'normal', 'low'])) { |
168
|
|
|
throw CouldNotCreateMessage::invalidPriority($priority); |
169
|
|
|
} |
170
|
|
|
$this->priority = $priority; |
171
|
|
|
|
172
|
|
|
return $this; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* Set the ticket status. |
177
|
|
|
* Allowed values are new, open, pending, hold, solved or closed. |
178
|
|
|
* |
179
|
|
|
* @return $this |
180
|
|
|
*/ |
181
|
|
|
public function status($status) |
182
|
|
|
{ |
183
|
|
|
$this->status = $status; |
184
|
|
|
|
185
|
|
|
return $this; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* Set the message to be public. |
190
|
|
|
* |
191
|
|
|
* @return $this |
192
|
|
|
*/ |
193
|
1 |
|
public function visible() |
194
|
|
|
{ |
195
|
1 |
|
$this->isPublic = true; |
196
|
|
|
|
197
|
1 |
|
return $this; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* Add a tag to the ticket. |
202
|
|
|
* |
203
|
|
|
* @param string $tag |
204
|
|
|
* |
205
|
|
|
* @return $this |
206
|
|
|
*/ |
207
|
|
|
public function tag(array $tag) |
208
|
|
|
{ |
209
|
|
|
$this->tags[] = $tag; |
210
|
|
|
|
211
|
|
|
return $this; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* Set the value of custom field in the new ticket. |
216
|
|
|
* |
217
|
|
|
* @param int $id |
218
|
|
|
* @param string $value |
219
|
|
|
* |
220
|
|
|
* @return $this |
221
|
|
|
*/ |
222
|
|
|
public function customField($id, $value) |
223
|
|
|
{ |
224
|
|
|
$this->customFields[] = [ |
225
|
|
|
'id' => $id, |
226
|
|
|
'value' => $value, |
227
|
|
|
]; |
228
|
|
|
|
229
|
|
|
return $this; |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* Set the value of group id. |
234
|
|
|
* |
235
|
|
|
* @param int $id |
236
|
|
|
* @param string $value |
|
|
|
|
237
|
|
|
* |
238
|
|
|
* @return $this |
239
|
|
|
*/ |
240
|
|
|
public function group($id) |
241
|
|
|
{ |
242
|
|
|
$this->groupId = $id; |
243
|
|
|
|
244
|
|
|
return $this; |
245
|
|
|
} |
246
|
|
|
|
247
|
6 |
|
public function getComment() |
248
|
|
|
{ |
249
|
6 |
|
$comment = []; |
250
|
|
|
|
251
|
6 |
|
if ($this->htmlContent !== '') { |
252
|
|
|
$comment['html_body'] = $this->htmlContent; |
253
|
|
|
} |
254
|
|
|
|
255
|
6 |
|
if ($this->content !== '') { |
256
|
2 |
|
$comment['body'] = $this->content; |
257
|
|
|
} |
258
|
|
|
|
259
|
6 |
|
$comment['public'] = $this->isPublic; |
260
|
|
|
|
261
|
6 |
|
return $comment; |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
/** |
265
|
|
|
* @return array |
266
|
|
|
*/ |
267
|
6 |
|
public function toArray() |
268
|
|
|
{ |
269
|
|
|
return [ |
270
|
6 |
|
'subject' => $this->subject, |
271
|
6 |
|
'comment' => $this->getComment(), |
272
|
6 |
|
'requester' => $this->requester, |
273
|
6 |
|
'description' => $this->description, |
274
|
6 |
|
'type' => $this->type, |
275
|
6 |
|
'status' => $this->status, |
276
|
6 |
|
'tags' => $this->tags, |
277
|
6 |
|
'priority' => $this->priority, |
278
|
6 |
|
'custom_fields' => $this->customFields, |
279
|
6 |
|
'group_id' => $this->groupId, |
280
|
|
|
]; |
281
|
|
|
} |
282
|
|
|
} |
283
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.